10
10
11
11
package org .mule .module .netsuite .api ;
12
12
13
+ import org .mule .module .netsuite .NetSuiteCloudConnector ;
13
14
import org .mule .module .netsuite .api .annotation .NetSuiteOperation ;
14
15
15
- import com .netsuite .webservices .platform .core_2010_2 .Record ;
16
-
17
16
import java .lang .reflect .InvocationHandler ;
17
+ import java .lang .reflect .InvocationTargetException ;
18
18
import java .lang .reflect .Method ;
19
19
import java .lang .reflect .Proxy ;
20
20
import java .util .List ;
21
21
22
+ import org .slf4j .Logger ;
23
+ import org .slf4j .LoggerFactory ;
22
24
import org .springframework .core .annotation .AnnotationUtils ;
23
25
24
26
public final class NetSuiteClientAdaptor
25
27
{
26
28
private static final Object LOCK = new Object ();
29
+ private static final Logger log = LoggerFactory .getLogger (NetSuiteCloudConnector .class );
27
30
28
31
private NetSuiteClientAdaptor ()
29
32
{
@@ -37,28 +40,62 @@ public static NetSuiteClient<List<Object>, RuntimeException, Void> adapt(final N
37
40
new InvocationHandler ()
38
41
{
39
42
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
40
65
{
41
66
NetSuiteOperation operationMetadata = AnnotationUtils .findAnnotation (method ,
42
67
NetSuiteOperation .class );
43
68
if (operationMetadata == null )
44
69
{
45
- return method . invoke ( client , args );
70
+ return invokeMethod ( method , client , args );
46
71
}
47
72
try
48
73
{
49
74
synchronized (LOCK )
50
75
{
51
- return adaptReturnType (method . invoke ( client , args ), operationMetadata );
76
+ return adaptReturnType (invokeMethod ( method , client , args ), operationMetadata );
52
77
}
53
78
}
54
- catch (Exception e )
79
+ catch (Throwable e )
55
80
{
56
81
throw NetSuiteGenericException .soften (e );
57
82
}
58
83
}
59
84
});
60
85
}
61
86
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
+
62
99
private static Object adaptReturnType (Object returnValue , NetSuiteOperation operationMetadata )
63
100
throws Throwable
64
101
{
0 commit comments