1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.seasar.axis.client;
29
30 import java.lang.reflect.Method;
31 import java.net.URL;
32
33 import javax.xml.namespace.QName;
34 import javax.xml.rpc.Call;
35
36 import org.aopalliance.intercept.MethodInvocation;
37 import org.apache.axis.client.Service;
38 import org.apache.axis.encoding.TypeMappingRegistry;
39 import org.apache.axis.enum.Use;
40 import org.seasar.axis.S2AxisConstants;
41 import org.seasar.axis.encoding.AutoRegisterTypeMappingImpl;
42 import org.seasar.framework.aop.interceptors.AbstractInterceptor;
43 import org.seasar.framework.util.MethodUtil;
44
45 /***
46 * Javaインタフェースを通じてWebサービスを呼び出すためのインターセプタです。
47 *
48 * @author koichik
49 */
50 public class DynamicInvocationInterceptor extends AbstractInterceptor {
51
52 protected final Service service;
53 protected final String endPointAddress;
54
55 /***
56 * インスタンスを構築します。 <br>
57 * ビーンのタイプマッピングを自動化するようにサービスのタイプマッピングレジストリを設定します。
58 *
59 * @param service
60 * サービス
61 * @param endPointAddress
62 * エンドポイントアドレス
63 */
64 public DynamicInvocationInterceptor(final Service service, final String endPointAddress) {
65 this.service = service;
66 this.endPointAddress = endPointAddress;
67
68 final TypeMappingRegistry tmr = service.getEngine().getTypeMappingRegistry();
69 final AutoRegisterTypeMappingImpl autoTM = new AutoRegisterTypeMappingImpl(null);
70 tmr.register(Use.DEFAULT.getEncoding(), autoTM);
71 }
72
73 /***
74 * インスタンスを構築します。
75 *
76 * @param service
77 * サービス
78 * @param url
79 * エンドポイントアドレスのURL
80 */
81 public DynamicInvocationInterceptor(final Service service, final URL url) {
82 this(service, url.toString());
83 }
84
85 /***
86 * ターゲットまたはサービスのメソッドを起動します。 <br>
87 * 呼び出されたメソッドがターゲットで実装されている場合はターゲットのメソッドを呼び出します。
88 * ターゲットで実装されていなければサービスのメソッドを呼び出します。
89 *
90 * @param invocation
91 * メソッド起動情報
92 */
93 public Object invoke(final MethodInvocation invocation) throws Throwable {
94 final Method method = invocation.getMethod();
95 if (!MethodUtil.isAbstract(method)) {
96 return invocation.proceed();
97 }
98
99 final Call call = service.createCall();
100 call.setTargetEndpointAddress(endPointAddress);
101 call.setOperationName(new QName(S2AxisConstants.OPERATION_NAMESPACE_URI, method.getName()));
102 return call.invoke(invocation.getArguments());
103 }
104 }