View Javadoc

1   package org.seasar.remoting.axis.connector;
2   
3   import java.lang.reflect.Method;
4   import java.net.URL;
5   
6   import javax.xml.namespace.QName;
7   import javax.xml.rpc.Call;
8   import javax.xml.rpc.Service;
9   
10  import org.apache.axis.encoding.TypeMappingRegistry;
11  import org.apache.axis.enum.Use;
12  import org.seasar.remoting.axis.S2AxisConstants;
13  import org.seasar.remoting.axis.encoding.AutoRegisterTypeMappingImpl;
14  import org.seasar.remoting.common.connector.impl.TargetSpecificURLBasedConnector;
15  
16  /***
17   * Webサービスを呼び出すコネクタの実装クラスです。
18   * 
19   * @author koichik
20   */
21  public class AxisConnector extends TargetSpecificURLBasedConnector {
22      protected Service service;
23  
24      /***
25       * Axisサービスを設定します。
26       * 
27       * @param service
28       *            Axisサービス
29       */
30      public void setService(final Service service) {
31          this.service = service;
32  
33          final TypeMappingRegistry tmr = (TypeMappingRegistry) service.getTypeMappingRegistry();
34          if (!(tmr.getTypeMapping(Use.DEFAULT.getEncoding()) instanceof AutoRegisterTypeMappingImpl)) {
35              final AutoRegisterTypeMappingImpl autoTM = new AutoRegisterTypeMappingImpl(null);
36              tmr.register(Use.DEFAULT.getEncoding(), autoTM);
37          }
38      }
39  
40      /***
41       * Axisサービスを使用してリモートメソッドの呼び出しを実行し、その結果を返します。
42       * 
43       * @param targetURL
44       *            リモートオブジェクトのURL
45       * @param method
46       *            呼び出すメソッド
47       * @param args
48       *            リモートオブジェクトのメソッド呼び出しに渡される引数値を格納するオブジェクト配列
49       * @return リモートオブジェクトに対するメソッド呼び出しからの戻り値
50       * @throws Throwable
51       *             リモートオブジェクトに対するメソッド呼び出しからスローされる例外
52       */
53      protected Object invoke(final URL targetURL, final Method method, final Object[] args)
54              throws Throwable {
55          final Call call = service.createCall();
56          call.setTargetEndpointAddress(targetURL.toString());
57          call.setOperationName(new QName(S2AxisConstants.OPERATION_NAMESPACE_URI, method.getName()));
58          return call.invoke(args);
59      }
60  }