2011-08-08 4 views
3

文字列を入力として受け取り、文字列を出力として返す単純なWebサービスを作成しようとしています。 私はEcelipse HeliosとAxis 2.15を使用しています。XStreamでワイヤを介して送信されたStringの直列化解除に関する問題

  1. 私は同じもののために簡単なWSDLを書いています。
  2. 私は、コードジェネレータを使用してスタブを生成しています。

    New - > code generator - > java class from wsdl-> WSDLを与え、Javaのスケルトンを生成します。

  3. そしてスケルトンでは、パラメータとして来るものだけを出力しています。同じ値を返します。
  4. Webサービスのメソッドを呼び出すためのクライアントコードを記述しました。これはStringをとります。
  5. 私がこのメソッドを呼び出そうとしているとき、私は例外になってきています。それはWebサービスに当たっていません。

Infact私はClient/WebServiceと共にXStreamを使用しています。

コードは、Webサービスのスケルトンのためにこのように書きます:

public com.url.pkg.ShowInputResponse showInput(
     com.url.pkg.ShowInput showInput) { 
    // TODO : fill this with the necessary business logic 
    String inputString = showInput.getInputString(); 
    System.out.println("INput String is :\n" + inputString); 
    XStream xStream = new XStream(); 
    System.out.println("After XStream Declaration..."); 
    SOVO vo = null; 
    try { 
     vo = (SOVO) xStream.fromXML(inputString); 
    } catch (Throwable e) { 
     System.out.println(e); 
     e.printStackTrace(); 
    } 
    System.out.println("After SOVO casting from XML"); 
    System.out.println(vo.getName()); 
    System.out.println(vo.getParams()); 
    // TODO: business logic 
    ShowInputResponse response = new ShowInputResponse(); 
    response.set_return(inputString); 
    return response; 
} 

私のクライアントコードはこのように書きます:

public static void main(String[] args) throws Exception { 
     BasicServiceStub stub = new BasicServiceStub(); 
     ShowInput request = new ShowInput(); 
     SOVO sovo = new SOVO(); 
     sovo.setName("I am the post for SO"); 
     Map params = new HashMap(); 
     params.put("key1", "val1"); 
     params.put("key2", "val2"); 
     sovo.setParams(params); 
     XStream xStream = new XStream(); 
     String soVoString = xStream.toXML(sovo); 
     // System.out.println(soVoString); 
     request.setInputString(soVoString); 
     ShowInputResponse response = stub.showInput(request); 
     System.out.println("...................................."); 
     System.out.println("response = " + response.get_return()); 
    } 

SOVOは、クライアントとWebサービスの両方に存在しているシンプルなPOJOです側。

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://pkg.url.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://pkg.url.com"> 
    <wsdl:types> 
     <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://pkg.url.com"> 
      <xs:element name="showInput"> 
       <xs:complexType> 
        <xs:sequence> 
         <xs:element minOccurs="0" name="inputString" nillable="true" type="xs:string"/> 
        </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
      <xs:element name="showInputResponse"> 
       <xs:complexType> 
        <xs:sequence> 
         <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/> 
        </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
     </xs:schema> 
    </wsdl:types> 
    <wsdl:message name="showInputRequest"> 
     <wsdl:part name="parameters" element="ns:showInput"/> 
    </wsdl:message> 
    <wsdl:message name="showInputResponse"> 
     <wsdl:part name="parameters" element="ns:showInputResponse"/> 
    </wsdl:message> 
    <wsdl:portType name="BasicServicePortType"> 
     <wsdl:operation name="showInput"> 
      <wsdl:input message="ns:showInputRequest" wsaw:Action="urn:showInput"/> 
      <wsdl:output message="ns:showInputResponse" wsaw:Action="urn:showInputResponse"/> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="BasicServiceSoap11Binding" type="ns:BasicServicePortType"> 
     <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 
     <wsdl:operation name="showInput"> 
      <soap:operation soapAction="urn:showInput" style="document"/> 
      <wsdl:input> 
       <soap:body use="literal"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap:body use="literal"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:binding name="BasicServiceSoap12Binding" type="ns:BasicServicePortType"> 
     <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 
     <wsdl:operation name="showInput"> 
      <soap12:operation soapAction="urn:showInput" style="document"/> 
      <wsdl:input> 
       <soap12:body use="literal"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap12:body use="literal"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:binding name="BasicServiceHttpBinding" type="ns:BasicServicePortType"> 
     <http:binding verb="POST"/> 
     <wsdl:operation name="showInput"> 
      <http:operation location="BasicService/showInput"/> 
      <wsdl:input> 
       <mime:content type="text/xml" part="showInput"/> 
      </wsdl:input> 
      <wsdl:output> 
       <mime:content type="text/xml" part="showInput"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="BasicService"> 
     <wsdl:port name="BasicServiceHttpSoap11Endpoint" binding="ns:BasicServiceSoap11Binding"> 
      <soap:address location="http://localhost:8080/axis2/services/BasicService"/> 
     </wsdl:port> 
     <wsdl:port name="BasicServiceHttpSoap12Endpoint" binding="ns:BasicServiceSoap12Binding"> 
      <soap12:address location="http://localhost:8080/axis2/services/BasicService"/> 
     </wsdl:port> 
     <wsdl:port name="BasicServiceHttpEndpoint" binding="ns:BasicServiceHttpBinding"> 
      <http:address location="http://localhost:8080/axis2/services/BasicService"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

と例外のスタックトレースは、私は変更する必要があります:

public class SOVO { 

    private String name; 
    private Map params; 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public Map getParams() { 
     return params; 
    } 

    public void setParams(Map params) { 
     this.params = params; 
    } 

} 

そして最後に最も重要なWSDLは、ここにあるのは、Webサービス層を打つ場合

、私は非常にわかりません。

Caused by: org.apache.axis2.AxisFault: string 
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446) 
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371) 
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417) 
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) 
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 
     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 
     at com.url.pkg.BasicServiceStub.showInput(BasicServiceStub.java:184) 
     at com.url.pkg.Client.main(Client.java:30) 

これは、XStreamのデシリアライズの問題があるようです。 SOVOがクラスパスにあるにもかかわらず、なぜ起こっているのですか?何か不足していますか?

私は文字列としてXXXXXを送信しようとすると、それは伝え:

開始タグではなくX(位置:START_DOCUMENTはX見... @ 1:1)の前に許可された唯一の空白コンテンツ

私は、送信しようとすると、 "いくつかの値が" それは言う:

空白のみコンテンツが開始タグとないの前に許容される(位置:START_DOCUMENT見S ... @ 1:1)

何が問題なのかよくわかりません。あなたのshowInput方法の有効なテスト要求を生成するために、別のクライアント

使用soapUI

テストサービス:

+2

WSDLといくつかのコードを投稿できますか? – Thomas

+0

@Thomasが言ったように、WSDLは素晴らしいでしょう...クライアントコードも – home

+0

Webサービスエクスプローラでテストすることで、Webサービスが正しく動作していることを確認することをお勧めします(実行 - >下部項目.. Eclipse私は仮定します)。 – bdares

答えて