spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / java / webservices / chap3 / 2 To page 1To page 2To page 3To page 4current page
[previous]

Professional Java Web Services

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Let's look at two Apache SOAP API's that are used in the application: Call and Response. The Call object is responsible for setting up the details of the request:

  // Build the SOAP RPC request message using the Call object
  Call call = new Call();
  call.setTargetObjectURI("urn:HelloWorldService");
  call.setMethodName("getMessage");
  call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

The above code snippet builds a SOAP request message that specifies that the RPC method call request should be routed to the "HelloWorld" service and that the getMessage() method should be invoked.

The Call.invoke() method sends the request to the SOAP server. The following code snippet depicts this:

  // Create a URL object, which represents the endpoint
  URL url = new URL(endPoint);

  // Send the SOAP RPC request message using invoke() method
  Response resp = call.invoke(url, "");

In the above code snippet a java.net.URL object is constructed from the string representation of the endpoint for the Apache SOAP runtime. If the user doesn't provide a different endpoint as a parameter then the endpoint will be http://localhost:8080/soap/servlet/rpcrouter. The return value is a Response object, which contains the response from the server.

The following code snippet checks the response received back from the server and displays a SOAP Fault message if an error occurred. Otherwise, it displays the value returned by the getMessage() method:

// Check the response.
  if (resp.generatedFault ()) { // Error Occured
    Fault fault = resp.getFault ();
    System.out.println ("The Following Error Occured: ");
    System.out.println ("  Fault Code   = " + fault.getFaultCode ());
    System.out.println ("  Fault String = " + fault.getFaultString ());
  } else {                                // Completed Successfully
    Parameter result = resp.getReturnValue ();
    System.out.println (result.getValue ());
  }

The SOAP request message generated by the HelloWorldClient application is below:

POST /soap/servlet/rpcrouter HTTP/1.0
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: 414
SOAPAction: ""

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 
                   xmlns:xsi=http://www.w3.org/1999/XMLSchema-instance 
                   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <SOAP-ENV:Body>
    <ns1:getMessage xmlns:ns1="urn:HelloWorldService"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    </ns1:getMessage>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The SOAP response message sent back to the application is below:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 485
Date: Wed, 19 Dec 2001 04:10:28 GMT
Server: Apache Tomcat/4.0.1 (HTTP/1.1 Connector)
Set-Cookie: JSESSIONID=D712520676C524504110A4C5D6E672E9;Path=/soap

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <SOAP-ENV:Body>
    <ns1:getMessageResponse xmlns:ns1="urn:HelloWorldService"
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <return xsi:type="xsd:string">Hello World!</return>
  </ns1:getMessageResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

home / programming / java / webservices / chap3 / 2 To page 1To page 2To page 3To page 4current page
[previous]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: May 23, 2002
Revised: May 23, 2002

URL: http://webreference.com/programming/java/webservices/chap3/2/5.html