my dog learned polymorphism*
The moose likes Web Services and the fly likes Trouble hand rolling SOAP request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Trouble hand rolling SOAP request" Watch "Trouble hand rolling SOAP request" New topic
Author

Trouble hand rolling SOAP request

Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
My hands are tied and I'm fairly limited in what is available to me to make a SOAP request (not all of 1.6 is available I think, but please recommend a library if you know of a native one that will make this easier, I may be able to get it added to the server) so I'm hand rolling a POST to a SOAP service. We have a proprietary HttpClient and HttpResponse (wrappers more or less) that after some tweaking I'm able to get a 200 OK but the moment I try and send some actual parameters to the service I get a 403.



That is the packet I send that gives me a 200 OK but the response says it's an invalid XML request. Fair enough as I didn't actually send any parameters.

Here is what I send that gives me the 400:



I also set the SOAP Action to the method I want to call as well as set the content type to "text/xml; charset=utf-8" per SOAP 1.1.

I'm completely lost as to what is wrong with my request as everything is a String created manually.

Does anything pop out as erroneous? Do I need to encode the string or something?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
If this was my problem I would try leaving out the <?xml :

because the SOAP message is already a valid XML document so making a second xml declaration it probably throwing an exception from the parser.

Bill
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
William Brogden wrote:If this was my problem I would try leaving out the <?xml :

because the SOAP message is already a valid XML document so making a second xml declaration it probably throwing an exception from the parser.

Bill


Thanks Bill. I just tried that and I still got 400 errors. I tried removing the leading xml tag, the trailing tag, both tags, and urlencoding the whole packet.

I think I've either got to try buidling the dom, using sax, or pestering the feed provider developer for help.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I'm completely lost as to what is wrong with my request as everything is a String created manually.


There is a SOAP API in Java which can be used to easily manually build SOAP requests, i.e. javax.xml.soap
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
Jimmy Clark wrote:
I'm completely lost as to what is wrong with my request as everything is a String created manually.


There is a SOAP API in Java which can be used to easily manually build SOAP requests, i.e. javax.xml.soap


Thanks Jimmy. This library is in the class path. Going to switch to this.
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
Are either of these links sufficient for communicating with a SOAP endpoint/service?

http://users.skynet.be/pascalbotte/rcx-ws-doc/saajpost.htm
http://docs.sun.com/source/817-2174-10/wsgjaxm.html#wp1009917
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
Slight clarification needed: what is the difference between a mime header and a soap header?

I need to add a SOAPAction header to the request and I'm given two ways to do this it seems via these two links:

http://www.java2s.com/Code/Java/JDK-6/SendingaSOAPMessage.htm
http://users.skynet.be/pascalbotte/rcx-ws-doc/saajpost.htm
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 576

Hi Matt,
Slight clarification needed: what is the difference between a mime header and a soap header?

To be simple,
mime header is present at the transport level(HTTP, MQ, SMTP, etc.)
soap header is present at the message level(within only SOAP messages)

SOAPAction attribute in mimeheader denotes the request is HTTP SOAP message request though I think it is optional!
If you are using SAAJ1.2, please note this
Note; in SOAP 1.2, the SOAPAction header has been replaced with the “action” attribute on the application/soap+xml media type. But it works almost exactly the same way as SOAPAction.

[For more details and source of this excerpt: http://www.oreillynet.com/xml/blog/2002/11/unraveling_the_mystery_of_soap.html]


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 259
Thanks for the help everyone. I'm at a point now where communication is consistent. The only issue now is the integration of the xml into the soap. I realize it was said that I should remove the second xml definition tag but until I get confirmation from the client for my current server side errors (as reported by their service....not 500 or 403 or anything like that) this is how it's set up in the documentation.

My problem currently is when printing to the console using System.out.println I intially get an output of this for the xml I create as outputted by XMLOutputter#outputString() from JDOM:



However, when I try and print the request/response to the System.out.println I get something that looks like this using SOAPMessage.writeTo():



The soap message itself prints out just fine to system.out for both the request and response. It's just the created textNode I guess.





Any thoughts? I've thought of CDATA as an option for the xml between the <xml></xml> tags but still figuring out how JDOm does that.

Addendum: I'm confused. The code I printed here is exactly what I get yet it displays normally on the web.
 
Consider Paul's rocket mass heater.
 
subject: Trouble hand rolling SOAP request
 
Similar Threads
error while connecting to webservices
SOAP Fault for SOAP Action property
How to convert string to xml file in java
how to set an attribute like SOAPAction in the Header?
how to write soap sending message with java?