Permalink
Browse files

strengthened soap fault handling

  • Loading branch information...
1 parent f8fa446 commit 23f2623ec72ab17f7c31dc24f4efdf6187663869 @ddossot committed Sep 26, 2011
View
@@ -12,13 +12,13 @@
<url>http://www.mulesoft.org/documentation/display/MAGENTO/Home</url>
<properties>
- <muleVersion>3.1.0</muleVersion>
+ <muleVersion>3.1.2</muleVersion>
<eclipsePluginVersion>2.8</eclipsePluginVersion>
<vmtype>org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType</vmtype>
<jdk.name>J2SE-1.5</jdk.name>
<jdk.version>1.5</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <cloudconnect.version>2.0.14</cloudconnect.version>
+ <cloudconnect.version>2.0.17-SNAPSHOT</cloudconnect.version>
</properties>
<build>
@@ -19,13 +19,13 @@
import org.apache.commons.lang.Validate;
import org.mule.module.magento.MagentoCloudConnector;
import org.mule.module.magento.api.util.MagentoMap;
+import org.mule.util.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * An utility class for creating proxies that handle {@link AxisFault}s by converting
- * them into {@link MagentoException}s, and return Maps of objects instead of magento
- * objects
+ * An utility class for creating proxies that handle {@link AxisFault}s by converting them into {@link MagentoException}
+ * s, and return Maps of objects instead of magento objects
*/
public final class MagentoClientAdaptor
{
@@ -36,28 +36,29 @@ private MagentoClientAdaptor()
}
@SuppressWarnings("unchecked")
- public static <T> T adapt(Class<T> receptorClass, final T receptor)
+ public static <T> T adapt(final Class<T> receptorClass, final T receptor)
{
Validate.isTrue(receptorClass.isInterface());
return (T) Proxy.newProxyInstance(MagentoClientAdaptor.class.getClassLoader(),
new Class[]{receptorClass}, new InvocationHandler()
{
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
+ throws Throwable
{
try
{
if (log.isDebugEnabled())
{
log.debug("Entering {} with args {}", method.getName(), args);
}
- Object ret = new MagentoMap(new Holder(method.invoke(receptor, args))).get("value");
+ final Object ret = new MagentoMap(new Holder(method.invoke(receptor, args))).get("value");
if (log.isDebugEnabled())
{
log.debug("Returning from {} with value {}", method.getName(), ret);
}
return ret;
}
- catch (InvocationTargetException e)
+ catch (final InvocationTargetException e)
{
if (e.getCause() instanceof AxisFault)
{
@@ -75,17 +76,25 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
});
}
- private static MagentoException toMagentoException(AxisFault fault)
+ private static MagentoException toMagentoException(final AxisFault fault)
{
- return new MagentoException( //
- Integer.parseInt(fault.getFaultCode().toString()), fault.getFaultString(), fault);
+ final String faultCode = fault.getFaultCode().toString();
+
+ if (NumberUtils.isNumber(faultCode))
+ {
+ return new MagentoException(Integer.parseInt(faultCode), fault.getFaultString(), fault);
+ }
+ else
+ {
+ return new MagentoException(MagentoException.UNKNOWN_ERROR, fault.getFaultString(), fault);
+ }
}
public static class Holder
{
- private Object value;
+ private final Object value;
- public Holder(Object value)
+ public Holder(final Object value)
{
this.value = value;
}
@@ -15,14 +15,15 @@
private static final long serialVersionUID = -5626573459450043144L;
private final int faultCode;
+ public static final int UNKNOWN_ERROR = -1;
public static final int SHIPMENT_DOES_NOT_EXIST = 100;
public static final int INVALID_FILTERS = 101;
public static final int INVALID_DATA = 102;
public static final int ORDER_DOES_NOT_EXIST = 103;
public static final int TRACKING_DOES_NOT_EXIST = 104;
public static final int TRACKING_NOT_DELETED = 105;
- MagentoException(int faultCode, String message, Throwable cause)
+ MagentoException(final int faultCode, final String message, final Throwable cause)
{
super(message, cause);
this.faultCode = faultCode;
@@ -33,4 +34,3 @@ public int getFaultCode()
return faultCode;
}
}
-

0 comments on commit 23f2623

Please sign in to comment.