0

The client (Browser) expects to receive a JSON string in response. I have the JSON string to send at the service side. However the calling function (axis2_invoke) expects axiom_node_t which make it return XML.

Is there a way to send my response in a way I want to and not as axiom objects

arpit772
  • 1
  • 3

1 Answers1

0

AxiOM is a data abstraction layer, not XML.

When talking about Axis2/C-unofficial which supports JSON natively, you will get response depending of your request format:

  • if you setup Content-Type of your request to application/json you will get response in JSON format;
  • if you setup Content-Type of your request to application/soap+xml you will get response in SOAP format.

Your response AxiOM is to be be converted to appropriate format by Axis2/C's transport sender.

loentar
  • 5,111
  • 1
  • 24
  • 25
  • Thank you for your answer. However I am not using the unofficial one (the official version I believe has support only for XML when going through the data abstraction layer). Is there a way to send the response message back from where the service method is invoked or may be intercept the message after message out phase in out flow by adding a module. – arpit772 Dec 01 '15 at 05:44
  • No, it's not possible to change response format. To send something other than XML you must implement own transport. As example on how to integrate JSON transport you can see this: https://github.com/loentar/axis2c-unofficial/commit/dbefc8c7c90155274d34ea3d9071b9d9891bde3d . Another approach is to develop your own proxy module (standalone binary or as web server's module) which converts XML to JSON. – loentar Dec 01 '15 at 08:31
  • For details of JSON support by the official branch (Axis2/C-1.7.0) please see: https://issues.apache.org/jira/browse/AXIS2C-1645 . The patch for Axis2/C-1.7.0 itself is: https://issues.apache.org/jira/secure/attachment/12601463/axis2c_json_port_from_unofficial_v2.patch – loentar Dec 01 '15 at 08:43
  • Thanks a lot for your inputs :) . They were very helpful. – arpit772 Dec 01 '15 at 10:30
  • Hi, loentar .. I am making a Restful web service and wish to send Image from service to the client (currently browser). How should I proceed with the problem at hand. (I have switched to using Apache Axis2C unofficial) – arpit772 Dec 02 '15 at 11:53
  • I think you should look into MTOM: http://axis.apache.org/axis2/c/core/docs/axis2c_manual.html#mtom – loentar Dec 02 '15 at 12:56