This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes How can I create a simple soap client servlet to send XML? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How can I create a simple soap client servlet to send XML?" Watch "How can I create a simple soap client servlet to send XML?" New topic
Author

How can I create a simple soap client servlet to send XML?

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi all-

After quite a bit of messing around to get Apache Muse working for a subscribe notify request I have run into quite a few problems: wsdl2java errors , authentication support and other issues. It seems that the Muse project is no longer even supported.

Since the msg I want to send is sent rarely (basically to turn on subscription notification) I want to send the xml manually through a soap client. I have the correct soap xml (including soap header) from using soapUI to test the service.

Now I want to send the soap msg using a servlet.

There must be a straightforward way to do this but I can't find one. I'm using Jboss 4.2 (JAX-WS which was not compatible with Muse) and the Jboss Seam app framework as well, although I can and probably will skip seam to get this working.

I just want to fire off a prebuilt soap msg.

thanks for any suggestions

Max
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you considered Apache HttpClient?
Strictly speaking, if you just want to send a HTTP request carrying a payload (the SOAP message), then Java SE is sufficient.
Are there any requirements regarding interpreting the response?
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
You can certainly use an existing copy of the XML client SOAP message as a template and send the request with HttpClient.

I did exactly that for a client, saving a whole bunch of fiddling with AXIS2 classes. I modified the template by replacing values with "@1" *@2" etc placeholders which got replaced with new values while sending the request.

Bill

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Bill/Ivan - Thanks for the replies

HttpClient - Great suggestion. I have used that in the past and had forgotten about it.

I do need to read the response to ensure the request was successful, which I can do.

HttpClient may well be the solution since I have to embed WSSE security info in the SOAP header and configuring security for this one message is a royal pain.
This msg will basically be sent once. If we ever need to turn subscriptions off, I will have another servlet to send an unsubscribe.

thanks again!
Max
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Bill-

I just read another post you commented on regarding this subject a couple of years ago:

"httpclient for accessing webservice"

You suggested using HttpURLConnection - I think this is the approach I want, correct, since I am invoking a web service - and I need to read the response?
I need to send via a Post.

Max
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I create a simple soap client servlet to send XML?
 
Similar Threads
Generating Soap msg from a xml file
Must I create new file when client invoke soap method?
Seam in Action : How is ease of use
Seam2.1 and Netbeans 6.8
Sending requests in xml