2012-09-01 42 views
0

현재 여러 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을 사용하여

답변

0

가장 큰 문제처럼 받는다는 플러그인을 사용할 수있는 자바 클래스에 WSDL을 변환
는 것이 었습니다 Axis의 잘못된 버전을 사용하여 SoapUI 내부에서 Java 클래스를 생성했습니다. Axis2로 시도했지만 웹 서비스가 실제로 Axis1에서 실행 중임을 알았습니다. 따라서 비슷한 문제가 발생하면 먼저 웹 서비스 버전과 클라이언트 라이브러리가 동일한 지 먼저 확인하십시오.

0

당신 부하 웹 서비스 SOAP의 UI에 @XmlRegistry

감사합니다,
czetsuya으로 표시가 포함되어 있습니다. Wsdl에는 클래스의 스키마가 들어 있습니다. 이클립스
에 대한 wsdl2java plugin

를 플러그인을 사용하거나 여기

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

<groupId>org.apache.cxf</groupId> 
<artifactId>cxf-codegen-plugin</artifactId> 
+0

안녕하세요. 응답 해 주셔서 감사합니다. wsdltojava에 대해 알고 있지만 클라이언트 스텁을 생성하고 싶지 않습니다. 나는 JAXBContext와 Unmarshaller를 사용하고있다. 위 코드에 요청을 보내고 응답을 언 마샬링하는 코드를 추가했습니다. – czetsuya