Results 1 to 1 of 1
- 09-27-2011, 03:46 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
Problem: Sending JSON messages to a SOAP Web service using Axis2
Hi,
I currently have a SOAP Web service in Axis2!
For using the web services for mobile applications I'm trying to send the messages in JSON. This way, less text has to be send. (I know it's probably better for using rest + json, but now I'm looking for a quick temporary fix)
I have a generated client (with a stub), which generates soap messages, sends the messages and parses the response. All this in xml.
I'm trying to alter this so I can send JSON messages instead of xml.
What have I done? :
- in axis2.xml : added
- In the client code:Java Code:<messageFormatters> <messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/> <!-- more message formatters --> </messageFormatters> <messageBuilders> <messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/> <!-- more message builders --> </messageBuilders>
the Tunify2Stub constructor uses the configurationContext and the url of the WSDLJava Code:File configFile = new File("axis2.xml"); ConfigurationContext confContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, configFile.getAbsolutePath()); this._webservice = new Tunify2Stub(confContext, tunifyURL); this._webservice._getServiceClient().getOptions().setProperty(Constants.Configuration.MESSAGE_TYPE, "application/json"); this._webservice._getServiceClient().getOptions().setTimeOutInMilliSeconds(2*60*1000); this.loginUser(credentials);
- the loginUser method basically does:
with the correct loginUser object.Java Code:LoginUserResponse response = this._webservice.loginUser(loginUser);
When I run this code with de messageType "application/soap+xml" there is no problem. The request is handled perfectly.
But when I change the messageType to "application/json" (used in axis2.xml), I guess the request is parsed to JSON and sent to the server, but then I receive a fault of "unexpected subelement ..." , which is the case when the server receives a request which is in conflict with the wsdl.
Does anyone know a possible reason for this ?
I tried many things and searched a long time on the web, but no solution.
my json request looks like this:
Is there something wrong with the construction of the generated JSON ?Java Code:"{"ns1:loginUser":{"@xmlns":{"ns1":"http:\/\/www.tunify.com"},"userName":{"@xmlns":{"$":""},"$":"blabla1"},"userPassword":{"@xmlns":{"$":""},"$":"blablaPassw"},"appID":{"@xmlns":{"$":""},"$":"15"},"appPassword":{"@xmlns":{"$":""},"$":"password15"}}}"
Thanks in advance!!
Similar Threads
-
Netbeans axis2 java web service: Results not shown with input variable in URL
By wk3000sg in forum Advanced JavaReplies: 0Last Post: 09-11-2011, 04:34 PM -
Suppressing soap header in Axis2 client
By MonsM in forum Advanced JavaReplies: 1Last Post: 05-12-2011, 01:16 PM -
Problem with Axis2 and JSON when calling web service in javascript
By pista in forum Advanced JavaReplies: 2Last Post: 01-18-2011, 10:19 AM -
Help sending messages using TCP with small chat application
By Ernie- in forum NetworkingReplies: 7Last Post: 03-28-2009, 06:20 PM -
All JSP expert / Is there JSP code for calling & sending messages? please help me
By java student in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 12-02-2008, 10:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks