Search code examples
javawebservice-client

javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error


I have a problem invoking services from a web service. I'm unable to figure the below unmarshalling error that I'm receiving. Please help. I have reviewed passed posts and I don't know whats going on because the error description it's very generic.

To generate the Java client code from WSDL I use: wsimport -b binding.xml service.wsdl

where binding.xml is:

<bindings xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://localhost:8080/services/service?wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
    <!-- Disable default wrapper style -->
    <enableWrapperStyle>false</enableWrapperStyle>
</bindings>

(Unfortunately i couldn't attach my WSDL due to the limit of body size of message)

So, after I generated my client and implemented the call to the service I obtained this error message: javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156) at com.sun.proxy.$Proxy151.protocolInsert(Unknown Source) ...

Here a piece of code:

import javax.xml.ws.BindingProvider;
//other import
public class ProtocolHandler{
....
    private ProtocolloServicePortType initServiceProtocol() throws                                       Exception
    {
        // Init client WS
        ProtocolloService invoiceProcolWs = new ProtocolloService();
        ProtocolloServicePortType port = invoiceProcolWs.getProtocollo();
        BindingProvider bp = (BindingProvider) port;

        // Setting endopoint
        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, getUrl());

        return port;
    }

    private void createProtocol(){
        try{
           //Initialize service
           ProtocolloServicePortType protocolService = initServiceProtocol();
           //Create a request
           ProtocolInsertRequest request = prepareRequest();
           //Call the method service protocolInsert
           ProtocolResponse response = protocolService.protocolInsert(request);
        }catch(Exception e){
             //manage Exception
        }

    }
}

I use JDK 1.7.0_25, Eclipse Jee Neon.

My project use several libraries: could be these error related to an incompatibility issue?

There are jaxbw-plugin-1.0.jar, jaxb-xjc-2.0.jar, jaxb-impl-2.0.jar, jaxb-api-2.0.jar, javaee-api-6.0.jar.

UPDATE 18/10/2018

I found out the problem. With a SOAPHandler I've noticed that in my request are missing the date value, when in I've valorized them (debugging I've see that my request have each date valorized).

<ns5:protocolInsert xmlns="http://insielmercato.it/protocollo-ws/data/common" xmlns:ns2="http://insielmercato.it/protocollo-ws/data/anagrafic" xmlns:ns3="http://insielmercato.it/protocollo-ws/data/filing" xmlns:ns4="http://insielmercato.it/protocollo-ws/data/protocol" xmlns:ns5="http://insielmercato.it/protocollo-ws/services/protocolloService">
<ns4:user>
    <code>USER</code>
    <password>PSWD</password>
</ns4:user>
<ns4:operatingOfficeCode>OFFICE</ns4:operatingOfficeCode>
<ns4:officeCode>GEN</ns4:officeCode>
<ns4:registerCode>GEN</ns4:registerCode>
<ns4:direction>A</ns4:direction>
<ns4:sequenceCode>SEQUENCE</ns4:sequenceCode>
<ns4:subjectDocument>Test protocollazione notifica fattura passiva</ns4:subjectDocument>
<ns4:subjectProtocol>PROTOCOLLAZIONE DOC. PROVA000002</ns4:subjectProtocol>
<ns4:receptionSendingDate/>
<ns4:documentDetails>
    <number>PROVA000002</number>
    <date/>
    <year>2018</year>
    <documentTypeCode>FAT</documentTypeCode>
</ns4:documentDetails>
<ns4:senderList>
    <ns4:sender>
        <code>SENDER</code>
    </ns4:sender>
</ns4:senderList>

As you can see tags <ns4:receptionSendingDate/> and <date/> (inside <ns4:documentDetails>) are null, but I valorized them in my methods. Removing this tags from my request the call to the service it functions properly without the Unmarshalling Error.

How is possible this?

Thanks at all for the attention.


Solution

  • I've found out the source of the problem.

    Debugging again I've noticed that my XMLGregorianCalendar had hour, minute, second and timezone setted to -2147483648 because the library Utils contained in my project was setting the XMLGregorianCalendar in this way:

    GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
    
        XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate(
                cal.get(Calendar.YEAR),
                cal.get(Calendar.MONTH)+1,
                cal.get(Calendar.DAY_OF_MONTH),
                DatatypeConstants.FIELD_UNDEFINED);
    

    So first I've changed this method in

    XMLGregorianCalendar xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    

    and second I've "scolded" who made this XD.

    And my problem was resolved