My CXF
provided REST
services usually return javax.ws.rs.core.Response
for the usual reason, to encapsulate the result entity data marshaled as XML and a return code:
@GET
@Path("/getPojo")
@Produces("application/xml")
public Response getPojo() {
SomePojo resultObj = ...;
Response result = Response.status(200).entity(resultObj).build();
return result;
}
which requires that SomePojo
contains proper annotations:
@XmlRootElement(name = "somePojo")
@XmlAccessorType(XmlAccessType.FIELD)
public class SomePojo implements Serializable {
...
}
However, now I am facing a scenario where the annotation convention does not work for me and I have to build my own JAXBElement
. How can I include the custom-marshaled JAXBElement in the Response
instead of using Response.ResponseBuilder.entity(resultObj)
, which relies on the annotation configuration? I am marshaling something similar to what is explained here but he's just printing the marshaled XML into the console and I would like to print it into the Response (and not just HttpResponse
out).
Response
because I want to encapsulate both a return code + object – Fatuity