Reputation: 7522
I have an existing CXF Java webservice which returns a deep, complex, nested response type. Parts of the response type exists in the DB stored as plain XML message (the exact same XML what should get returned).
Example response type: PartyResponse -> PartyRec -> PartyInfo and PartyInfo structure is stored as XML in DB.
How could I return the response from Java, inserting the XML part without deserializing it to Java objects with JAXB just to serialize it again to XML via CXF right after?
Upvotes: 3
Views: 1059
Reputation: 68
You can use jaxws Provider's Payload mode. See http://cxf.apache.org/docs/provider-services.html
Your service can then just return a Source object that is just a generic XML object. Something like 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;
}
}
Upvotes: 1