View Javadoc

1   /*
2    *
3    * The Seasar Software License, Version 1.1
4    *
5    * Copyright (c) 2003-2004 The Seasar Project. All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or
8    * without modification, are permitted provided that the following
9    * conditions are met:
10   *
11   * 1. Redistributions of source code must retain the above
12   *    copyright notice, this list of conditions and the following
13   *    disclaimer.
14   *
15   * 2. Redistributions in binary form must reproduce the above
16   *    copyright notice, this list of conditions and the following
17   *    disclaimer in the documentation and/or other materials provided
18   *    with the distribution.
19   *
20   * 3. The end-user documentation included with the redistribution,
21   *    if any, must include the following acknowledgement:
22   *    "This product includes software developed by the
23   *    Seasar Project (http://www.seasar.org/)."
24   *    Alternately, this acknowledgement may appear in the software
25   *    itself, if and wherever such third-party acknowledgements
26   *    normally appear.
27   *
28   * 4. Neither the name "The Seasar Project" nor the names of its
29   *    contributors may be used to endorse or promote products derived
30   *    from this software without specific prior written permission of
31   *    the Seasar Project.
32   *
33   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR
34   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE SEASAR PROJECT
37   * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38   * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42   * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING
43   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
44   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45   */
46  package org.seasar.remoting.axis.connector;
47  
48  import java.lang.reflect.Method;
49  import java.net.URL;
50  
51  import javax.xml.namespace.QName;
52  import javax.xml.rpc.Call;
53  import javax.xml.rpc.Service;
54  import javax.xml.rpc.encoding.TypeMapping;
55  
56  import org.apache.axis.constants.Use;
57  import org.apache.axis.encoding.TypeMappingDelegate;
58  import org.apache.axis.encoding.TypeMappingRegistry;
59  import org.seasar.remoting.axis.S2AxisConstants;
60  import org.seasar.remoting.common.connector.impl.TargetSpecificURLBasedConnector;
61  
62  /***
63   * Webサービスを呼び出すS2Remotingコネクタの実装クラスです。
64   * 
65   * @author koichik
66   */
67  public class AxisConnector extends TargetSpecificURLBasedConnector {
68      //instance fields
69      protected Service service;
70  
71      /***
72       * Axisサービスを設定します。
73       * 
74       * @param service
75       *            Axisサービス
76       */
77      public void setService(final Service service) {
78          this.service = service;
79  
80          final TypeMappingRegistry tmr = (TypeMappingRegistry) service.getTypeMappingRegistry();
81          TypeMapping tm = tmr.getTypeMapping(Use.DEFAULT.getEncoding());
82          ((TypeMappingDelegate) tm).setDoAutoTypes(true);
83      }
84  
85      /***
86       * Axisサービスを使用してリモートメソッドの呼び出しを実行し、その結果を返します。
87       * 
88       * @param targetURL
89       *            リモートオブジェクトのURL
90       * @param method
91       *            呼び出すメソッド
92       * @param args
93       *            リモートオブジェクトのメソッド呼び出しに渡される引数値を格納するオブジェクト配列
94       * @return リモートオブジェクトに対するメソッド呼び出しからの戻り値
95       * @throws Throwable
96       *             リモートオブジェクトに対するメソッド呼び出しからスローされる例外
97       */
98      protected Object invoke(final URL targetURL, final Method method, final Object[] args)
99              throws Throwable {
100         final Call call = service.createCall();
101         call.setTargetEndpointAddress(targetURL.toString());
102         call.setOperationName(new QName(S2AxisConstants.OPERATION_NAMESPACE_URI, method.getName()));
103         return call.invoke(args);
104     }
105 }