2

I have generated a Soap webservice client using wsimport and trying to consume the webservice on Websphere 9.0.5.13

  • The application classloader is set to parent last
  • I added the following JVM argument in websphere: -Djavax.xml.bind.JAXBContext=com.sun.xml.internal.bind.v2.ContextFactory

When trying to call the webservice, it succeeds in the first call, and all the following calls fail with the exception:

[javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.mycompany.com", local:"MyOCRFileRequestRs"). Expected elements are (none)] 

My code is as follows:

private MyOCRFileRequestRsType callMyOCRService(MyOCRFileRequestRqType MyOCRRequest) throws Exception { String headerValue = "Bearer "+MyTokenClient.getToken(); MyOCRFileRequest port= esbOcrSerice.getMyOCRFileRequestSOAP11(); Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,ConfigManager.getMyOCRRequestUrl().split("[?]")[0]); requestContext.put("javax.xml.ws.http.request.headers", Collections.singletonMap("Authorization", Collections.singletonList(headerValue))); try { return port.MyOCRFileRequest(MyOCRRequest); } catch (Exception e) { throw e; } } 

The first call works fine with no issues, but all the subsequent calls fails with the following error:

[javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.mycompany.com", local:"MyOCRFileRequestRs"). Expected elements are (none)] 

MyOCRFileRequest interface:

@WebService(name = "MyOCRFileRequest", targetNamespace = "http://www.mycompany.com") @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @XmlSeeAlso({ ObjectFactory.class }) public interface MyOCRFileRequest { /** * * @param MyOCRFileRequestRq * @return * returns com.mycompany.idrak.MyOCRFileRequestRsType */ @WebMethod(operationName = "MyOCRFileRequest", action = "MyOCRFileRequest") @WebResult(name = "MyOCRFileRequestRs", targetNamespace = "http://www.mycompany.com", partName = "MyOCRFileRequestRs") public MyOCRFileRequestRsType MyOCRFileRequest( @WebParam(name = "MyOCRFileRequestRq", targetNamespace = "http://www.mycompany.com", partName = "MyOCRFileRequestRq") MyOCRFileRequestRqType MyOCRFileRequestRq); } 

MyOCRFileRequestRsType:

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "MyOCRFileRequestRs_Type", propOrder = { "msgRsHdr", "body" }) public class MyOCRFileRequestRsType { @XmlElement(name = "MsgRsHdr", required = true) protected MsgRsHdrType msgRsHdr; @XmlElement(name = "Body") protected MyOCRFileRequestRsBodyType body; public MsgRsHdrType getMsgRsHdr() { return msgRsHdr; } public void setMsgRsHdr(MsgRsHdrType value) { this.msgRsHdr = value; } public MyOCRFileRequestRsBodyType getBody() { return body; } public void setBody(MyOCRFileRequestRsBodyType value) { this.body = value; } } 

UPDATES:

I tried using the JVM custom property, and issue still exist

com.ibm.xml.xlxp.jaxb.opti.level=0 

Is there's any configuration I need to change in Websphere in order to fix that ?

8
  • Is there a sample codebase to reproduce this? Commented Mar 29 at 15:38
  • please provide the complete logs Commented Mar 30 at 4:12
  • Also please provide the xml data Commented Mar 30 at 4:35
  • 2
    WebSphere has its own jaxb and jaxws libraries (that usually slightly different from the open source ones). If I were you, I would remove that JVM argument that tells what jaxb factory JDK should use and put every jaxb- and jaxws related dependencies to provided scope (I am expecting you are using maven). Please try to follow the official documentation Commented Mar 31 at 7:53
  • Did you try the solutions mentioned here? Specifically try adding the @XmlRootElement annotation. Commented Apr 1 at 6:36

1 Answer 1

0

I have researched a lot for your issue (Starting from setting up IBM WebSphere Application Server 9.0 locally to deploying the JAX-WS war). I'm suggesting some changes that might help.

Note: I took the help of IBM official documentation for deploying the SOAP JAX-WS service created via wsimport to WebSphere Application Server 9.0.5 on Windows 10.

Also, Websphere already has its jaxb and jax-ws libraries. So, you don't need to add any extra changes or add explicit VM parameters.

I was able to deploy the JAX-WS Samples from IBM and running it on WAS without adding any VM parameters.

------------------

I will be showing on how IBM did but I have modifed their code and adjusted by your way for demonstration.

First create a package called ocr in your project. Let assume the package is com.example .

  • Update your MyOCRFileRequestRqType and move the class in that package.
package com.example; import java.xml.bind.annotatation.XmlAccessType; import java.xml.bind.annotatation.XmlAccessorType; import java.xml.bind.annotatation.XmlElement; import java.xml.bind.annotatation.XmlRootElement; import java.xml.bind.annotatation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {....}) @XmlRootElement(name = "myOCRFileRequestRqType") public class MyOCRFileRequestRqType { @XmlElement(name = "...") // fields annotated with @XmlElement with attributes set. // getters and setters } 
  • Update your MyOCRFileRequestRsType and move the class in that package.
package com.example; import java.xml.bind.annotatation.XmlAccessType; import java.xml.bind.annotatation.XmlAccessorType; import java.xml.bind.annotatation.XmlElement; import java.xml.bind.annotatation.XmlRootElement; import java.xml.bind.annotatation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {"msgRsHdr", "body"}) @XmlRootElement(name = "myOCRFileRequestRsType") public class MyOCRFileRequestRsType { @XmlElement(name = "MsgRsHdr", required = true) protected MsgRsHdrType msgRsHdr; @XmlElement(name = "Body") protected MyOCRFileRequestRsBodyType body; public MsgRsHdrType getMsgRsHdr() { return msgRsHdr; } public void setMsgRsHdr(MsgRsHdrType value) { this.msgRsHdr = value; } public MyOCRFileRequestRsBodyType getBody() { return body; } public void setBody(MyOCRFileRequestRsBodyType value) { this.body = value; } } 

Create the ObjectFactory class in that package.

package com.example; import javax.xml.bind.annotation.XmlRegistry; @XmlRegistry public class ObjectFactory { public ObjectFactory() { } public MyOCRFileRequestRsType createMyOCRFileRequestRsType() { return new MyOCRFileRequestRsType(); } public MyOCRFileRequestRqType createMyOCRFileRequestRqType() { return new MyOCRFileRequestRqType(); } } 
  • Keep your .wsdl file in the WebContent/WEB-INF/wsdl directory.

  • Create the Web Service interface class MyOCRServicePortType and keep in the same package.

package com.example; import javax.jms.WebMethod; import javax.jms.WebParam; import javax.jms.WebResult; import javax.jms.WebService; import javax.jms.soap.SOAPBinding; import javax.jms.soap.SOAPBinding.ParameterStyle; @WebService(name = "MyOCRServicePortType", targetNamespace = "http://www.mycompany.com") @SOAPBinding(parameterStyle = ParameterStyle.BARE) public interface MyOCRServicePortType { /** * * @param request * @return * returns com.example.MyOCRFileRequestRsType */ @WebMethod(action = "ocrOperation") @WebResult(name = "myOCRFileRequestRsType", targetNamespace = "http://www.mycompany.com", partName = "parameter") public MyOCRFileRequestRsType ocrOperation( @WebParam(name = "myOCRFileRequestRqType", targetNamespace = "http://www.mycompany.com", partName = "parameter") MyOCRFileRequestRqType parameter); } 
  • Create the Web Service Implementation class MyOCRServicePortImpl and keep it in the same package.
package com.example; import javax.jms.WebMethod; import javax.jms.WebParam; import javax.jms.WebResult; import javax.jms.WebService; import javax.jms.soap.SOAPBinding; import javax.jms.soap.SOAPBinding.ParameterStyle; @WebService(endpointInterface = "com.example.MyOCRServicePortType", targetNamespace = "http://www.mycompany.com", serviceName = "MyOCRService", portName = "MyOCRServicePort", wsdlLocation = "WEB-INF/wsdl/Ocr.wsdl") public class MyOCRServicePortImpl { // declaration member variables.... public MyOCRFileRequestRsType ocrOperation(MyOCRFileRequestRqType parameter) { MyOCRFileRequestRsType response = new ObjectFactory().createMyOCRFileRequestRsType(); response.setMsgRsHdr(....); response.setBody(.....) return response; } } 
  • Update the code which is doing the business logic for OCR:
private MyOCRFileRequestRsType callMyOCRService(MyOCRFileRequestRqType parameter) throws Exception { String headerValue = "Bearer "+MyTokenClient.getToken(); MyOCRServicePortType port= esbOcrSerice.getMyOCRFileRequestSOAP11(); Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,ConfigManager.getMyOCRRequestUrl().split("[?]")[0]); requestContext.put("javax.xml.ws.http.request.headers", Collections.singletonMap("Authorization", Collections.singletonList(headerValue))); try { return port.ocrOperation(parameter); } catch (Exception e) { throw e; } } 

I don't have any much idea apart from this. Please refer to the JAX-WS samples. Just try to replicate what they have done. You will know where is the issue.

---------------

References:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.