2014-10-16 3 views
0

wsimport 명령 줄 (JAX-WS)을 사용하여 웹 서비스 클라이언트를 생성하고 JAXB를 사용하여 Java 객체를 생성하고 XSD 파일.JAX-WS 클라이언트, 잘못된 비누 요청 - 루트 요소 다음의 문서에서 마크 업은 올바른 형식이어야합니다.

하지만 요청을 시도하면 서버 측에서 다음과 같은 오류가 발생합니다.

SAXException, cause: The markup in the document following the root element must be well-formed.

샘플 비누 메시지로 비누 요청을 확인했습니다. 그렇다면이 두 메시지 사이에는 다른 점이 있음을 깨달았습니다.

1. 샘플 작업 메시지.

<m:getMyDetail xmlns:m="http://axis.frontend.hi.example.net"> 
<MyDetailRQ xmlns="http://www.example.net/schemas/1005/06/messages" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.example.net/1005/06/messages ../xsd/MyDetailRQ.xsd" 
version="2013/12"> 

2. 웹 서비스 클라이언트는 SOAP 메시지를 생성합니다. 당신이 볼 수 있듯이

<ns3:getMyDetail xmlns:ns3="http://axis.frontend.hi.example.net" xmlns="http://www. 
example.net/schemas/1005/06/messages" xmlns:ns2="http://www. example.net/wsdl/1005/06" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MyDetailRQ"> 

, 예상 MyDetailRQ 래퍼 태그 요소 위에 누락되어 있지만 XSI로 생성 : = "MyDetailRQ"속성 유형입니다.

왜 이런 일이 발생하고 클라이언트 프로젝트 구성을 통해이 문제를 해결할 수 있는지 잘 모르겠습니다.

귀하의 도움과 조언에 감사드립니다.

감사

- 관련 WSDL 부분

<wsdl:types> 
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://axis.frontend.h1.example.com"> 
     <element name="getMyDetail" type="xsd:anyType"/> 
    </schema> 
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/wsdl/2005/06"> 
     <element name="getMyDetailReturn" type="xsd:anyType"/> 
    </schema> 
</wsdl:types> 
<wsdl:message name="getMyDetailRequest"> 
    <wsdl:part element="tns1:getMyDetail" name="part"/> 
</wsdl:message> 
<wsdl:message name="getMyDetailResponse"> 
    <wsdl:part element="impl:getMyDetailReturn" name="getMyDetailReturn"/> 
</wsdl:message> 
<wsdl:portType name="MyService"> 
    <wsdl:operation name="getMyDetail"> 
     <wsdl:input message="impl:getMyDetailRequest" name="getMyDetailRequest"/> 
     <wsdl:output message="impl:getMyDetailResponse" name="getMyDetailResponse"/> 
    </wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="MyServiceSoapBinding" type="impl:MyService"> 
    <wsdl:operation name="getMyDetail"> 
     <wsdlsoap:operation soapAction=""/> 
     <wsdl:input name="getMyDetailRequest"> 
      <wsdlsoap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="getMyDetailResponse"> 
      <wsdlsoap:body use="literal"/> 
     </wsdl:output> 
    </wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="MyServiceService"> 
    <wsdl:port binding="impl:MyServiceSoapBinding" name="MyService"> 
     <wsdlsoap:address location="http://interface.example.com/xmls/ws/MyService"/> 
    </wsdl:port> 
</wsdl:service> 

- 관련 XSD 부분

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns="http://www.example.net/schemas/1005/06/messages" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.net/schemas/1005/06/messages" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
    <xs:include schemaLocation="MyCommonTypes.xsd"/> 
    <xs:element name="MyDetailRQ"> 

- 관련 자바 객체

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "MyDetailRQ", propOrder = { 
    "myCode" 
}) 
@XmlRootElement(name = "MyDetailRQ") 
public class MyDetailRQ 
    extends MainRequest 
{ 
} 

- 웹 서비스 클라이언트 - (17 ~ 10 월 - 2014 년 업데이트) 서비스 인터페이스

@WebService(name = "MyService", targetNamespace = "http://www.example.net/wsdl/1005/06") 
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 
@XmlSeeAlso({ 
    com.myp.hi.frontend.axis.ObjectFactory.class, 
     com.myp.ObjectFactory.class 
}) 
public interface MyService { 
    /** 
     * 
     * @param part 
     * @return 
     *  returns java.lang.Object 
     */ 
     @WebMethod 
     @WebResult(name = "getMyDetailReturn", targetNamespace = "http://www.example.net/wsdl/1005/06", partName = "getMyDetailReturn") 
     public Object getMyDetail(
      @WebParam(name = "getMyDetail", targetNamespace = "http://axis.frontend.hi.example.net", partName = "part") 
      Object part); 

} 

- (17 ~ 10 월 - 2014 년 업데이트) ObjectFactory를 클래스

@XmlRegistry 
public class ObjectFactory { 

    private final static QName _GetMyDetail_QNAME = new QName("http://axis.frontend.hi.example.net", "getMyDetail"); 


    public ObjectFactory() { 
    } 

    @XmlElementDecl(namespace = "http://axis.frontend.hi.example.net", name = "getMyDetail") 
      public JAXBElement<Object> createGetMyDetail(Object value) { 
      return new JAXBElement<Object>(_GetMyDetail_QNAME, Object.class, null, value); 
    } 


} 

-MyServiceService 클래스 (2014 년 10 월 17 일에 업데이트 됨)

@WebServiceClient(name = "MyServiceService", targetNamespace = "http://www.example.net/wsdl/1005/06", wsdlLocation = "http://interface.example.com/xmls/ws/MyService?wsdl") 
@GZIP 
public class MyServiceService 
    extends Service 
{ 

    private final static URL MYSERVICESERVICE_WSDL_LOCATION; 
    private final static WebServiceException MYSERVICESERVICE_EXCEPTION; 
    private final static QName MYSERVICESERVICE_QNAME = new QName("http://www.example.net/wsdl/1005/06", "MyServiceService"); 

    static { 
     URL url = null; 
     WebServiceException e = null; 
     try { 
      url = new URL("http://interface.example.com/xmls/ws/MyService?wsdl"); 
     } catch (MalformedURLException ex) { 
      e = new WebServiceException(ex); 
     } 
     MYSERVICESERVICE_WSDL_LOCATION = url; 
     MYSERVICESERVICE_EXCEPTION = e; 
    } 

@WebEndpoint(name = "MyService") 
    public MyService getMyService() { 

     MyService port = super.getPort(new QName("http://www.example.net/wsdl/1005/06", "MyService"), MyService.class); 
     return port; 
    } 

private static URL __getWsdlLocation() { 
     if (MYSERVICESERVICE_EXCEPTION!= null) { 
      throw MYSERVICESERVICE_EXCEPTION; 
     } 
     return MYSERVICESERVICE_WSDL_LOCATION; 
    } 


} 

- (17 ~ 10 월 - 2014 년 업데이트) 내 테스트 클래스

MyService myService = new MyServiceService().getMyService(); 

MyDetailRQ myDetailRQ = new MyDetailRQ(); 


myDetailRQ.setCredentials(credentials); 
myDetailRQ.setLanguage("ENG"); 
myDetailRQ.setMyCode("52319"); 

MyDetailRS myDetailRS = (MyDetailRS) myService.getMyDetail(myService); 
+0

어떻게 'getMyDetail' 인스턴스를 구성합니까? – lexicore

+0

테스트 클래스를 포함한 모든 정보를 가지고 문제를 업데이트 한 방법으로 ObjectFactory를 사용하기를 바랍니다. 확인해 주셔서 감사합니다. – Unknown

+0

MyDetailRQ에서 @XmlType (name = "", propOrder = { "hotelCode"})을 비워두면 다음 오류가 발생합니다. 'org.apache.cxf.interceptor.Fault : 마샬링 오류 : "com.myp.hi.dataobject.MyDetailRQ"의 인스턴스가 "java.lang.Object"를 대체하지만 "com.mpy.hi.dataobject.MyDetailRQ"는 다음과 같습니다. 익명의 타입에 묶여있다. ' – Unknown

답변

0

나는 해결책을 찾았지만 완벽한 하나의 여부를 확실하지.

내가 한 것은; XML 문자열을 전달하여 서비스에서 문자열로 응답을 얻습니다. 그런 다음 수동으로 마샬링 및 언 마샬링을 수행하십시오.

아래 예를 참조하십시오.

MyService myService = new MyServiceService().getMyService(); 

MyDetailRQ myDetailRQ = new MyDetailRQ(); 


myDetailRQ.setCredentials(credentials); 
myDetailRQ.setLanguage("ENG"); 
myDetailRQ.setMyCode("52319"); 

String requestStr = getStringFromJaxb(myDetailRQ.class, myDetailRQ); 

String responseStr = (String) myService.getMyDetail(requestStr); 

MyDetailRS myDetailRS = (MyDetailRS) getJaxbFromString(MyDetailRS.class, responseStr); 




private static Object getJaxbFromString(Class<?> clazz, String xmlString) { 
     StringReader input = null; 
     Object o = null; 
     try { 
      input = new StringReader(xmlString); 
      JAXBContext context = JAXBContext.newInstance(clazz); 
      Unmarshaller um = context.createUnmarshaller(); 
      o = um.unmarshal(input); 
      if (o instanceof JAXBElement) 
       o = ((JAXBElement<?>) o).getValue(); 
     } catch (JAXBException e) { 
      e.printStackTrace(); 
     } finally { 
      if (input != null) 
       input.close(); 
     } 
     return o; 
    } 



/** 
    * Helper method to get xml string from JAXB Object. 
    * @param clazz 
    * @param o 
    * @return 
    */ 
    private static String getStringFromJaxb(Class<?> clazz, Object o) { 
     String theXML = ""; 
     try { 
      StringWriter writer = new StringWriter(); 
      JAXBContext context = JAXBContext.newInstance(clazz); 
      Marshaller m = context.createMarshaller(); 
      m.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE); 
      m.marshal(o, writer); 

      // output string to console 
      theXML = writer.toString(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return theXML; 
    }