현재 여러 xml 웹 서비스를 일반 xml에서 변환 중입니다. 내가 soapUI에서로드했고, 클라이언트 포트와 모의 서비스를 만들었고 요청 응답이 완벽하게 작동합니다. 그래서 지금은 만들/xml 복잡한 형식 개체를 자바로 변환 할 노력하고있어,하지만 실패 해요.웹 서비스 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>
어떤 생각이 어떻게 자바 객체에 그 변환? 원본 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 클라이언트를 가지고있다.
나는 데 : 응답이 내가 만든 ResultatImage 클래스에 매핑되지 않은 것처럼
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are <{}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으로 표시된 클래스를 갖는다. 또한 그것은 ObjectFactory를이 WSDL을 사용하여
안녕하세요. 응답 해 주셔서 감사합니다. wsdltojava에 대해 알고 있지만 클라이언트 스텁을 생성하고 싶지 않습니다. 나는 JAXBContext와 Unmarshaller를 사용하고있다. 위 코드에 요청을 보내고 응답을 언 마샬링하는 코드를 추가했습니다. – czetsuya