0
votes

[com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 1; unexpected element (uri:"http://service.example.com/", local:"custDetails"). Expected elements are <{http://schemas.xmlsoap.org/soap/envelope/}Body>,<{}Customer>,<{http://schemas.xmlsoap.org/soap/envelope/}Envelope>,<{http://schemas.xmlsoap.org/soap/envelope/}Fault>,<{http://schemas.xmlsoap.org/soap/envelope/}Header>]

Problem statement: Camel is not expecting to receive the custDetails (webmethod) and the namespace.
Expectation : to use camel-soap to unmarshal the payload to soapJaxb out of the box.

  1. Generated JAXB classes using maven-jaxb2-plugin for the xsd below. Results produced three classes with annotations - Customer.java, ObjectFactory,java , Order.java.

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified"
           >
    <xs:element name="Customer">
    <xs:complexType >
    <xs:sequence>
      <xs:element name="Id" type="xs:string"/>
      <xs:element name="Address" type="xs:string"/>
      <xs:element name="ListOfOrders" type="order" minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:complexType name="order">
    <xs:sequence>
          <xs:element name="Id" type="xs:string"/>
          <xs:element name="ProductName" type="xs:string"/>
          <xs:element name="ListOfDevice" minOccurs="0" >
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="DeviceName" type="xs:string"/>
                    <xs:element name="ManufactureDate" type="xs:date"/>
                </xs:sequence>
            </xs:complexType>
          </xs:element>
       </xs:sequence>
    </xs:complexType>
    </xs:schema>
    
  2. Expose webservice custDetails(..) as follows using cxf endpoint with DataFormat set to PAYLOAD. [UPDATED with @Configuration]

        @Configuration
       public class WebServiceConfig {
         @Autowired 
        private Bus bus;
    
        @Bean 
        public CxfEndpoint getCustomerDetails() {
            CxfEndpoint cxfEndpoint = new CxfEndpoint();
            cxfEndpoint.setAddress("/customerProvide");
            cxfEndpoint.setServiceClass(CustomerSvc.class);
            cxfEndpoint.setBus(bus);
            cxfEndpoint.setDataFormat(DataFormat.PAYLOAD);return cxfEndpoint ;}
    
        @Webservice
        public interface CustomerSvc {
        @WebMethod
        Customer  custDetails ( @WebParam(name="Customer")Customer Customer ) ;}
    
        // Simple route in Route class.
        @Component
        public class CustomerRoute extends RouteBuilder {
          public void configure (){
        SoapJaxbDataFormat soapDF 
        = new SoapJaxbDataFormat("com.example.service", new TypeNameStrategy());
    
         from("cxf:bean:getCustomerDetails").unmarshal(soapDF)
        .log("receive : ${body}")
        }
    
  3. Wsdl generated and imported to soapUI. sample SOAPUI request to test is as follows.

    <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ser="http://service.example.com/">
    <soapenv:Header/>
    <soapenv:Body>
      <ser:custDetails>
         <ser:Customer>
            <Id>1-abc</Id>
            <Address>23 Sydney Oxley road</Address>
            <ListOfOrders>
               <Id>P1344</Id>
               <ProductName>DRAM</ProductName>
               <ListOfDevice>
                  <DeviceName>20nm</DeviceName>
                  <ManufactureDate>15-8-2017</ManufactureDate>
               </ListOfDevice>
            </ListOfOrders>
         </ser:Customer>
      </ser:custDetails>
     </soapenv:Body>
    </soapenv:Envelope>
    
  4. When I try to unmarshal PAYLOAD with soap dataformat, camel is throwing an error. It is the hitting namespace error. I am not sure why package-info class is not generated. Any help is greatly appreciated. Thank you.

  5. UPDATE, wsdl given below. <?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.example.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="CustomerSvcService" targetNamespace="http://service.example.com/"> <wsdl:types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.example.com/" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://service.example.com/"> <xs:element name="Customer"> <xs:complexType> <xs:sequence> <xs:element name="Id" type="xs:string"/> <xs:element name="Address" type="xs:string"/> <xs:element minOccurs="0" name="ListOfOrders" type="tns:order"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="order"> <xs:sequence> <xs:element name="Id" type="xs:string"/> <xs:element name="ProductName" type="xs:string"/> <xs:element minOccurs="0" name="ListOfDevice"> <xs:complexType> <xs:sequence> <xs:element name="DeviceName" type="xs:string"/> <xs:element name="ManufactureDate" type="xs:date"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> <xs:element name="custDetails" type="tns:custDetails"/> <xs:complexType name="custDetails"> <xs:sequence> <xs:element minOccurs="0" ref="tns:Customer"/> </xs:sequence> </xs:complexType> <xs:element name="custDetailsResponse" type="tns:custDetailsResponse"/> <xs:complexType name="custDetailsResponse"> <xs:sequence> <xs:element minOccurs="0" ref="tns:Customer"/> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> <wsdl:message name="custDetails"> <wsdl:part element="tns:custDetails" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:message name="custDetailsResponse"> <wsdl:part element="tns:custDetailsResponse" name="parameters"> </wsdl:part> </wsdl:message> <wsdl:portType name="CustomerSvc"> <wsdl:operation name="custDetails"> <wsdl:input message="tns:custDetails" name="custDetails"> </wsdl:input> <wsdl:output message="tns:custDetailsResponse" name="custDetailsResponse"> </wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CustomerSvcServiceSoapBinding" type="tns:CustomerSvc"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="custDetails"> <soap:operation soapAction="" style="document"/> <wsdl:input name="custDetails"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="custDetailsResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="CustomerSvcService"> <wsdl:port binding="tns:CustomerSvcServiceSoapBinding" name="CustomerSvcPort"> <soap:address location="http://localhost:12000/services/customerProvide"/> </wsdl:port> </wsdl:service> </wsdl:definitions>

1

1 Answers

0
votes

EDIT due to updated question

You try to unmarshal the request payload with Jax-B based on the XML schema you posted at the top of your question.

But in this schema the element custDetails does not exist. It exists in the schema part of your WSDL, but not in the schema?!? Therefore the error unexpected element.