CXF Webservice response with XML content

I have an existing CXF Java webservice that returns a deep, complex, nested response type. The response type parts exist in the database, stored as a simple XML message (the same XML that should be returned).

An example of a response type: PartyResponse → PartyRec → PartyInfo and the PartyInfo structure is stored as XML in the DB.

How can I get the response back from Java by inserting the XML part without deserializing it to Java objects using JAXB, so that I can just serialize it again to XML via CXF right after?

+3


source to share


1 answer


You can use Jaxws Provider Payload mode. See http://cxf.apache.org/docs/provider-services.html

Then your service can simply return a Source object, which is just a generic XML object. Something like the one shown below:



import javax.xml.transform.Source;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceProvider;

@WebServiceProvider(serviceName="EchoService", portName="EchoPort")
@ServiceMode(value=Service.Mode.PAYLOAD)
public class EchoPayloadProvider implements Provider<Source> {
    public Source invoke(Source request) throws WebServiceException {
        // just echo back
        return request;
    }
}

      

+1


source







All Articles