Skip to content

Commit a0f16d9

Browse files
committed
Logging to all NetSuite operations
Also improved exception handling
1 parent 69c4cbc commit a0f16d9

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,18 @@
9595
<appendAssemblyId>false</appendAssemblyId>
9696
</configuration>
9797
</plugin>
98-
<!--
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-release-plugin</artifactId>
101+
<configuration>
102+
<autoVersionSubmodules>true</autoVersionSubmodules>
103+
<pushChanges>false</pushChanges>
104+
</configuration>
105+
<version>2.1</version>
106+
</plugin>
107+
108+
109+
<!--
99110
<plugin> <groupId>org.apache.cxf</groupId>
100111
<artifactId>cxf-codegen-plugin</artifactId>
101112
<version>${cxf.version}</version> <executions> <execution>

src/main/java/org/mule/module/netsuite/api/NetSuiteClientAdaptor.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010

1111
package org.mule.module.netsuite.api;
1212

13+
import org.mule.module.netsuite.NetSuiteCloudConnector;
1314
import org.mule.module.netsuite.api.annotation.NetSuiteOperation;
1415

15-
import com.netsuite.webservices.platform.core_2010_2.Record;
16-
1716
import java.lang.reflect.InvocationHandler;
17+
import java.lang.reflect.InvocationTargetException;
1818
import java.lang.reflect.Method;
1919
import java.lang.reflect.Proxy;
2020
import java.util.List;
2121

22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2224
import org.springframework.core.annotation.AnnotationUtils;
2325

2426
public final class NetSuiteClientAdaptor
2527
{
2628
private static final Object LOCK = new Object();
29+
private static final Logger log = LoggerFactory.getLogger(NetSuiteCloudConnector.class);
2730

2831
private NetSuiteClientAdaptor()
2932
{
@@ -37,28 +40,62 @@ public static NetSuiteClient<List<Object>, RuntimeException, Void> adapt(final N
3740
new InvocationHandler()
3841
{
3942
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
43+
{
44+
if (log.isDebugEnabled())
45+
{
46+
log.debug("Entering into {} with args {}", method.getName(), args);
47+
}
48+
try
49+
{
50+
Object ret = handle(method, args);
51+
if (log.isDebugEnabled())
52+
{
53+
log.debug("Returning from {} with value {}", method.getName(), ret);
54+
}
55+
return ret;
56+
}
57+
catch (Throwable e)
58+
{
59+
log.warn("Throwing {} at {}", e, method.getName());
60+
throw e;
61+
}
62+
}
63+
64+
private Object handle(Method method, Object[] args) throws Throwable
4065
{
4166
NetSuiteOperation operationMetadata = AnnotationUtils.findAnnotation(method,
4267
NetSuiteOperation.class);
4368
if (operationMetadata == null)
4469
{
45-
return method.invoke(client, args);
70+
return invokeMethod(method, client, args);
4671
}
4772
try
4873
{
4974
synchronized (LOCK)
5075
{
51-
return adaptReturnType(method.invoke(client, args), operationMetadata);
76+
return adaptReturnType(invokeMethod(method, client, args), operationMetadata);
5277
}
5378
}
54-
catch (Exception e)
79+
catch (Throwable e)
5580
{
5681
throw NetSuiteGenericException.soften(e);
5782
}
5883
}
5984
});
6085
}
6186

87+
private static Object invokeMethod(Method m, Object obj, Object... args) throws Throwable
88+
{
89+
try
90+
{
91+
return m.invoke(obj, args);
92+
}
93+
catch (InvocationTargetException e)
94+
{
95+
throw e.getCause();
96+
}
97+
}
98+
6299
private static Object adaptReturnType(Object returnValue, NetSuiteOperation operationMetadata)
63100
throws Throwable
64101
{

src/main/java/org/mule/module/netsuite/api/NetSuiteGenericException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public NetSuiteGenericException(String message)
2424
super(message);
2525
}
2626

27-
public static RuntimeException soften(Exception e)
27+
public static RuntimeException soften(Throwable e)
2828
{
2929
if (!(e instanceof RuntimeException))
3030
{

0 commit comments

Comments
 (0)