How do I make a simple SOAP client request in java?

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
I need to make a request to a website that provides tv listings. Basically I just need to make a simple SOAP request for the listings and the site provides them in XML format.

What's the easiest way to do this? Do I need to download a package like Axis2 or JAX-WS? These seem kind of overkill for what I want to do, since I don't need to run a server. Is there something in the Java standard libraries that will do this? Is it difficult to just write the code for this my self?
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Axis2 would work. If it's a basic SOAP service without security, you could construct the SOAP XML envelope yourself, set the SOAPAction HTTP header and simply POST it to the URL.
 

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
Originally posted by: MrChad
Axis2 would work. If it's a basic SOAP service without security, you could construct the SOAP XML envelope yourself, set the SOAPAction HTTP header and simply POST it to the URL.

I read the basic SOAP documentation and could probably figure out how to construct the SOAP envelope, but how do I post it to the URL?

Edit: nvm found the answer. I'll try it when I get home.
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
Instead of building SOAP envelope yourself why not use something like WSDL2Java to generate java classes from .wsdl/.xsd. Then the actual soap call comes down to 3-4 lines of java code.
 

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
I can post the SOAP envelope, and the server sends back a long generic response without the TV listings. I think the problem is I need to login to the site first because the listings are customized for my account. How do I do this by just posting SOAP messages?

Here is the sample envelope the site gives for developers:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<m:download xmlns:m="urn:TMSWebServices" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<startTime xsi:type="xsd:dateTime">2005-02-22T19:00:00Z
</startTime>
<endTime xsi:type="xsd:dateTime">2005-02-22T21:00:00Z
</endTime>
</m:download>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I tried adding:
<login xmlns="urn:hostnameofsite">
<username>myusername</username>
<password>mypassword</password>
</login>
to the beginning of the body but it didn't work.
 

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
Here's a PHP script that does exactly what I want to do:

$username='username';
$password='password';

$data_url='http://docs.tms.tribune.com/te...ct/tvDataDelivery.wsdl';
$start=gmdate("Y-m-d\TH:i:s\Z",time());
$stop =gmdate("Y-m-d\TH:i:s\Z",time()+3600*24);

$client = new SoapClient($data_url, array('exceptions' => 0,
'user_agent' => "php/".$_SERVER[SCRIPT_NAME],
'login' => strtolower($username),
'password' => $password));
$data = $client->download($start,$stop);

print_r($data);

What's the easiest way to do this in java?