org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element

Solution Unverified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 6.X

Issue

  • All of the services are implemented as JAX-WS services
  • Here's the problem. From time to time the Entity services may require additional elements. We would like to be able to add the additional elements to the entity webservice without impacting the composite webservices that currently use them.
  • When we add elements to the entities we get the following type of error in the composite services that use them:
    [org.apache.cxf.phase.PhaseInterceptorChain] (http-/0.0.0.0:8880-2) Interceptor for
  • Unmarshalling Error: unexpected element {uri:”com.example.MyClass”, local:”MyClass”)

Resolution

  • This is a code level problem (JAXB).

  • There's a JAXB property you can use to set-jaxb-validation-event-handler to resolve this.

  • Set this on the client like this:
    requestContext = ((javax.xml.ws.BindingProvider)port).getRequestContext(); 
    requestContext.put("set-jaxb-validation-event-handler",  "false");
  • The main issue is, the stubs need to be regenerated for the client-side based on the new WSDL that you have on the server-side
    When you modified the server and recompiled, the client-side will need to be updated.

Ideally, is wanted to separate the DB entities and web service and not expose what is essentially the DB structure to the outside world.

Root Cause

  • Marshalling errors like this occurs because the WSDL that the client proxies are generated against don't match what just came back from the service (because it's changed since the client was created) and now it doesn't know how to handle the new element.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments