• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Trouble hand rolling SOAP request

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Matt Kidd
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Get me the mayor's office! I need to tell her about this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic