Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soap service works locally but on another server is raising ClassCast Exception

Can someone please help me with a strange problem?

I have a service:

@WebMethod
@WebResult(name = "sendCustomerCommunicationResponse", targetNamespace = "......something/Underwriting/Correspondance/V1", partName = "Body")
public SendCustomerCommunicationResponse sendCustomerCommunication(
    @WebParam(name = "sendCustomerCommunicationRequest", targetNamespace = "........something/Underwriting/Correspondance/V1", partName = "Body")
    SendCustomerCommunicationRequest body)
    throws ServiceException_Exception, SystemException_Exception
;

And locally I'm calling it with :

SendCustomerCommunicationResponse response = correspondanceServicePort.sendCustomerCommunication(sendCustomerCommunicationRequest);

And this works well. But when I'm deploying the application on another server, I'm receiving:

"java.lang.ClassCastException: 
    it.usi.xframe.ub1.batch.services.esb.SendCustomerCommunicationRequest incompatible with 
    it.usi.xframe.ub1.batch.services.esb.SendCustomerCommunicationResponse"

P.S. The application is running on WebSphere server

The request is :

<soapenv:Envelope ...someSchema...>
   <soapenv:Header>
      <v1:TechnicalHeader>
         <v1:correlationId>12742</v1:correlationId>
         <v1:sender>userName</v1:sender>
         <v1:countryCode/>
         <v1:channelId/>
         <v1:userID>userName</v1:userID>
         <v1:operationId>CHANGE_STATUS</v1:operationId>
      </v1:TechnicalHeader>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                                    <wsse:UsernameToken>
                                                <wsse:Username>someUser</wsse:Username>
                                                <wsse:Password>somePassoword</wsse:Password>
                                    </wsse:UsernameToken>
                        </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <v11:sendCustomerCommunicationRequest>
         <v11:eventCode>{"header":{"publishingDate":1474016634749,"eventId":"DEL-NEG","applicationCode":"UB3","correlationId":"9999","language":"IT","channelId":"MOB"},"body":{"ndg":"5106215","additionalInfo":{}}}</v11:eventCode>
      </v11:sendCustomerCommunicationRequest>
   </soapenv:Body>
</soapenv:Envelope>
like image 269
Aditzu Avatar asked Dec 15 '16 10:12

Aditzu


3 Answers

Maybe it could be a WebSphere JAXB issue, related to the version you're using or your server may miss some fixings. Take a look at what the docs say:

The JAXB Unmarshaller generates stub classes at runtime to assist in unmarshalling the document. These generated classes are cached and may be reused by other JAXBContexts in the application.

When a JAXBContext contains a class which has an element wildcard (i.e. @XmlAnyElement) it was possible that the Unmarshaller would use incompatible generated stub classes from another JAXBContext which could result in a ClassCastException being thrown during unmarshalling. The problem was resolved by improving the collision checking done on previously generated stub classes so that a new stub class is generated from the current JAXBContext if the previously generated stub class found in the cache is not compatible.

That's hard to guess because of IBM's nature regardless the version you're using. Also, refer some other fixings:

like image 103
diogo Avatar answered Oct 06 '22 19:10

diogo


Q:

  • how is SendCustomerCommunicationResponsedefined? does it include @Xml.. annotations? (eg @XmlRoot ..
  • just for testing, could you set a name for the @WebResult return variable to something different than the name of the return class (SendCustomerCommunicationResponse)
  • what are ServiceException_Exception and SystemException_Exception? your own exceptions? It seems those are JAX-RS/JAXB generated exceptions..
like image 1
titou10 Avatar answered Oct 06 '22 19:10

titou10


It looks like a class version mismatch issue.

One of the scenarios where the developers create Web-Service stubs and build them in their project using a newer version whereas the server classpath has an older version of some dependent jar file. I would recommend the following steps to rule out this option of mismatched dependency versions.

  1. Get the dependency tree and for the files which are failing. You should get a list of dependent jar files. (Check specifically the jar file that is responsible for the creation of the Request and Response objects in your local machine)
  2. Compare the classpath of the WebSphere server and add any missing jars.
  3. replace any dependent jar files in the WebSphere classpath if they belong to an older version.

The second approach can be to do a remote debug, if possible, after enabling the de-compiler in your IDE. Check the class files where the exception occurs and ensure that the editor is linked to the navigator view, to ensure that your navigator shows the file in the jar that being debugged. You should be able to find the exact jar file that is invoked at the time of the exception.

like image 1
Amal Gupta Avatar answered Oct 06 '22 18:10

Amal Gupta