I used xjc to generate my JAXB classes and I have a very frustrating weird problem when marshalSendAndReceive tries to unmarshall the response object. I saw the response XML in my logs and it looks fine. When I save the XML response locally and use the same unmarshaller that is defined in applicationContext.xml it works fine but not when I connect to the webservice. Most responses are unmarshalled fine only some run into the error but even those responses get unmarshalled fine if I save the response XML locally and do unmarshalling.
Here is my code that uses marshalSendAndReceive to unmarshall and runs into error:
With Tracing I see the response XML comes through fine and looks fine too but the above call throws exception.Code:response = (GetMyResponseType) ((JAXBElement<?>) myWebServiceTemplate.marshalSendAndReceive(request)).getValue();
I save the response XML and used the following code which unmarshall's the response fine.
The following is the Error details I get on marshalSendAndReceive.Code:private GetMyResponseType localXMLResponse() { GetMyResponseType getResponseType = new GetResponseType(); org.springframework.oxm.Unmarshaller unMarshaller; FileInputStream is = null; try { is = new FileInputStream("/getDataItemResponse.xml"); unMarshaller = myWebServiceTemplate.getUnmarshaller(); getResponseType = (GetMyResponseType) ((JAXBElement<?>) unMarshaller.unmarshal(new StreamSource(is))).getValue(); } catch (Exception e) { LOGGER.error("failed to load local data response file", e); } finally { if (is != null) { try { is.close(); } catch (Exception e2) { } } } return getDataItemResponseType; }
Code:org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: null; nested exception is javax.xml.bind.UnmarshalException - with linked exception: [java.lang.NullPointerException] at org.springframework.oxm.jaxb.JaxbUtils.convertJaxbException(JaxbUtils.java:92) at org.springframework.oxm.jaxb.AbstractJaxbMarshaller.convertJaxbException(AbstractJaxbMarshaller.java:143) at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:425) at org.springframework.ws.support.MarshallingUtils.unmarshal(MarshallingUtils.java:62) at org.springframework.ws.client.core.WebServiceTemplate$3.extractData(WebServiceTemplate.java:374) at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:560) at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:351) at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:345) at gov.dhs.ice.oi.lecad.search_ui.springws.integration.wsclient.impl.GetDataItemDetailsTemplate.getDataItemRequest(GetDataItemDetailsTemplate.java:55) at gov.dhs.ice.oi.lecad.search_ui.springws.services.impl.GetDataItemImpl.getDataItemRequest(GetDataItemImpl.java:26) at gov.dhs.ice.oi.lecad.search_ui.mvc.action.SearchAction.execute(SearchAction.java:110) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at org.apache.struts2.interceptor.validation.JSONValidationInterceptor.doIntercept(JSONValidationInterceptor.java:116) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)


Reply With Quote