現在、プレーンな 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 も含まれています
ありがとう、
ツェツヤ