★ wanayoo — archive 1999 http://javaboutique.webdeveloper.com/tutorials/SOAP/client2.htmlNouvelle recherche | Portail wanayoo
80211 Planet


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Internet News
Internet Investing
IT
Windows Technology
Linux/Open Source
Developer
Interactive Marketing
xSP Resources
Small Business
Wireless Internet
Downloads
Internet Resources
Internet Lists
International
EarthWeb
Career Resources

Search internet.com
Advertise
Corporate Info
Newsletters
E-mail Offers
Be a Commerce Partner
Register Domains
Breathing Problems?
Reach IT Professionals
Software Store
Find a Web HostFind a Web Host
Track Defects Online
Business Search
Website Monitoring
Tech Magazines - FREE
Find a Consultant
FlashKit
Gif.com
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:


Tutorials : Using SOAP with Java :

The client

Now we come to the most important part of writing the client. As described in previous sections, the client now has the added responsibilities of defining the type mappings and the Serializer/DeSerialzer classes to be used and set them correctly in the SOAP mapping registry.

public static void main(String[] args)
    {
        String urlString = args[0];
        String name = args[1];
        SoapClient client = new SoapClient(urlString);
        System.out.println("*** Assigned the url for the sopa router as: "+urlString);
        /** construct a Person object**/
        Person nameObject = new Person();
        nameObject.setName(name);
        nameObject.setAge(22);

Now we can prepare the Call object as usual.

Call call = new Call();
       call.setTargetObjectURI("urn:greetingService");
       call.setMethodName("sayGreeting");
       call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

Here we will define and setup the mapping registry. We first create a new instance of the SOAPMappingRegistry.

    //create the type mapping registry
           SOAPMappingRegistry smr = new SOAPMappingRegistry();

Now we create a new instance of the BeanSerializer class.

//new instance of the serializer class
BeanSerializer bsr = new BeanSerializer();

We will create a QName object to represent the compound Person data-type.

//create a qname object
QName qn = new QName("urn:greetingService", "sam.soap.client.Person");

Now we will create the type mapping by invoking the maptype method on the SOAPMappingRegistry object.

//map the type
smr.mapTypes
   (Constants.NS_URI_SOAP_ENC, qn, sam.soap.client.Person.class, bsr, bsr);

The mapTypes method accepts the encoding style, the QName object, the class of the java bean , serializer class and the deserializer class as the arguments. If you recall the discussion on the mechanism of the serialization, then you will at once understand that these parameters are used to construct the four Hashtables defined.

Now we set the type mapping to the SOAP mapping registry.

//telling the call object to use this mapping
           call.setSOAPMappingRegistry(smr);

We will create a Parameter object with the Person object and pass it to the call object subsequently.

//creating the parameters
        Vector v = new Vector();
        Parameter param1 = 
 new Parameter("name", sam.soap.client.Person.class, nameObject, null);
        v.addElement(param1);
        call.setParams(v);

As you have noticed that the parameter object now holds a compound type Person object. The Person object in turn holds the value for its properties name and age. If we now invoke the remote method, we will see the required result.

//invoke the soap method
      System.out.println("invoking....");
      Response res = call.invoke(new URL(client.urlString), "");
      
      //if there is no fault in the method invocation, get the result
      if( res.generatedFault() ==false)
      {
          Parameter retValue = res.getReturnValue();
          Object value = retValue.getValue();
          System.out.println(value);
      }else
      {
          System.out.println("The fault is: "+res.getFault().getFaultString());
      }

If you deploy the service properly with the new deployment descriptor and run the client you will get the desired result.

Conclusion

In this installment we have examined how to use customised Java beans as parameters to the SOAP Remote Procedure Call. We have also analysed the underlying principles and protocols of Serialization mechanism underlying SOAP. The world is much brighter for us. But surely if you are an astute reader, you might have figured out that the world may be full of more complex objects which are more than Java beans. Next month we will see how to write our own Serializers and will also learn some exciting new aspects of SOAP. Happy coding.


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
J2EE Deployment Specification
Why is it that J2EE applications written in the same language, Java, may not coexist on different servers? While the answer isn't simple Sun has set out to alleviate these problems with the "J2EE Deployment Specification".
... [more articles]

New Tutorial:
Designing Packages for Stability
Are your designs stable? This month Samudra will focus on the change impact relationship involved in designing classes showing us how to take them into account when designing the package relationship.
... [more Tutorials]

Year in Review:
The Best of 2002
The year 2002 saw 201 new applets posted to JavaBoutique. Check out the 2 most popular apps from each month of 2002!
... [popular applets]

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo




Developer News

JBoss Group: Defections Aren't a Big Deal

IE Object Tag Buffer Overflow Patched

SCO Shuts Down German Site



Database Journal Launched!
Jupiter Media has announced the launch of Database Journal. DBJ offers SQL courses and other database related resources for beginner to expert developers.



JWizardPane
Build modern wizard style interface quickly. API easy to use. Bulti-in show dialog and frame support.
Download of the Week
BSCOutline v5.10
BSCOutline Java Outline Applet is a customizable tree view control for use in Web pages, similar to that used by Windows File Manager or Explorer. BSCOutline has been written to be the simple to use and small to store.

JB User Poll
How does .NET fit into your programming?
The JavaBoutique Top 15:
1. ChompText
2. RushHour
3. PulseText
4. PingPong
5. DJPopMenu
6. NavBar
7. 3DMaze
8. Encyclo
9. AnimLetters_anim
10. AScroll2
11. Nibbly
12. SonaliCalendar
13. BMMenu
14. BMI
15. SlideMenu
Want more? Check out our Top 100!

Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Verizon Ordered to Reveal Names of Music Pirates
The U.S. Court of Appeals Wednesday afternoon rejected Verizon's for request for a stay in earlier court ruling ordering the telecom giant to turn over the names of two subscribers suspected of illegally downloading copyrighted music.

E-mail Archiving Emerges as Critical Function
In today's corporate world, e-mail holds a company's critical information. Now a growing number of businesses are realizing that they need to save these e-mails. And they just can't pack them away like receipts you toss in a box at home.

The Deadly Duo: Spam and Viruses, May 2003
Spam attacks increase another 6+% for the month, as the global ratio of unwanted messages in business e-mail breaks the 50% mark.


100's of firms that help your Web site be found

Copyright 2003 Jupitermedia Corporation All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/