Virtual REST Service with multiple response type

We have a REST service based on Apache CXF that returns either XML or JSON based on what the consumer wants (indicated in the URL). How can we provide the same behaviour in centrasite ? Here is what i think:

  1. Create a REST service, and define a Resource in it with Content-Type as both JSON and XML
  2. Write two flow services for setting the BUILDER_TYPE context variable to xml and json respectively.
  3. Create two virtual services , one for JSON and one for XML. Specify the respective flow services in the Request Processing Step of these two virtual services.
  4. Consumers should then invoke the correct virtual service based on what response it wants.

Is this correct ? is there another/better way of doing this, specifically by using a single virtual service ?

CentraSite v8.2 Fix24.


If you want to get json or xml response use pub.flow:setResponse at the end of the invoked REST service and set the Content-Type as application/json or application/xml

Make sure the message string is also of same type

If anyone is still reading this, you can handle this on the request end without any changes to the flow. Just pass in an Accept header with values “application/json” or “text/xml” and the same REST service will respond appropriately to either request!

1 Like