Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CXF Webservice response with XML content

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?

like image 878
Kristof Jozsa Avatar asked Dec 17 '25 16:12

Kristof Jozsa


1 Answers

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;
    }
}
like image 196
elakito Avatar answered Dec 20 '25 09:12

elakito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!