0

現在、プレーンな xml から多数の Web サービスを変換しています。それらをsoapUIにロードし、クライアントポートとモックサービスを作成しましたが、リクエスト応答は完全に機能しています. だから今、私はxml複合型オブジェクトをJavaに作成/変換しようとしていますが、失敗しています。

soapUI では、応答としてこれがあります。

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://client.serviceweb.xxx">
   <soapenv:Header/>
   <soapenv:Body>
      <cli:versionResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <result xsi:type="java:ResultatVersion" xmlns:java="java:xxx.serviceweb">
            <messagexxx xsi:type="xsd:string">message</messagexxx>
            <resultatxxx xsi:type="xsd:int">1</resultatxxx>
            <version xsi:type="java:Version">
               <numero xsi:type="xsd:string">1.0.0</numero>
            </version>
         </result>
      </cli:versionResponse>
   </soapenv:Body>
</soapenv:Envelope>

それをJavaオブジェクトに変換する方法はありますか? 元の xml を見ると、フィールド メッセージと結果を含む親オブジェクトがありますが、バージョンの部分がわかりません。

これはどう?

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxx="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://client.serviceweb.xxx">
   <soapenv:Header/>
   <soapenv:Body>
      <cli:testResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <result xsi:type="java:ResultatImage" xmlns:java="java:xxx.serviceweb.xxx.xxx">
            <messagexxx xsi:type="xxx:string">message</messagexxx>
            <resultatxxx xsi:type="xxx:int">result</resultatxxx>
            <image xsi:type="xxx:base64Binary">cid:1325182441595</image>
         </result>
      </cli:testResponse>
   </soapenv:Body>
</soapenv:Envelope>

以前に使用した動作中の Jaxb クライアントが既にあり、既に動作していますが、上記のサンプルを呼び出す方法がわかりません。

私は持っています:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}resultatImage>

私が作成した ResultatImage クラスに応答がマッピングされていないようです。

何かご意見は?

リクエストを送信してレスポンスをアンマーシャリングする方法。

try {
    JAXBContext jc = JAXBContext
            .newInstance("com.ipiel.response");
    Unmarshaller u = jc.createUnmarshaller();
    client = new MyClient(httpClient, targetHost, u);
    client.test();
} catch (Exception e) {
    e.printStackTrace();
}

public void test() {
    String url = "/xxxClientsPort/test";
    HttpPost httpPost = new HttpPost(url);

    HttpResponse response = httpClient.execute(targetHost, httpPost);
    log.info("response: " + response);
    if (response.getStatusLine().getStatusCode() == 200) {
        HttpEntity respEntity = response.getEntity();
        if (respEntity != null) {
            InputStream instream = respEntity.getContent();
            try {
                ResultatImage responseEntity = (ResultatImage) unmarshaller
                        .unmarshal(instream);
                /*
                 * FileWriter writer = new FileWriter(new
                 * File("c:\\tmp\\output")); IOUtils.copy(instream, writer,
                 * "UTF-8"); String theString = writer.toString();
                 * writer.flush(); writer.close();
                 * System.out.println(theString);
                 */
            } finally {
                instream.close();
            }
        }
    }
}

パッケージ com.ipiel.response にはクラス Resultat と ResultatImage があり、どちらも @XmlRootElement としてマークされています。また、 @XmlRegistry としてマークされた ObjectFactory も含まれています

ありがとう、
ツェツヤ

4

2 に答える 2

0

ここでの主な問題は、間違ったバージョンの Axis を使用して SoapUI 内で Java クラスを生成していたことです。私は Axis2 で試していましたが、後で Web サービスが実際には Axis1 で実行されていることがわかりました。したがって、同様の問題が発生した場合は、最初に Web サービスのバージョンとクライアントのライブラリが同じかどうかを確認してください。

于 2013-01-14T02:46:24.627 に答える
0

WSDL を使用して Web サービスを SOAP UI にロードします。Wsdl には、クラスのスキーマが含まれています。
WSDL を Java クラスに変換するには、Eclipse
wsdl2java プラグインのプラグインを使用できます。

または、次のようなMavenプラグインを使用できます

<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>  

<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
于 2012-09-01T21:46:57.560 に答える