Newsletter:

(Article) Create a Java applet to download information in remote Web services

Article : Create a Java applet to download information in remote Web services

Description
Start with a Java™ applet and build a server-based proxy system that uses your browser to access an arbitrary Web service. You'll use JavaScript code to access applet-based information and call a servlet, which retrieves the remote information. Thus, you bypass the same-server restrictions on what an applet can and cannot do.

Applets have always been designed to play in a 'sandbox' in which they can't hurt anything on a user's system, so their security is tighter than that of their server-based application counterparts. For example, a Java application can easily make a network connection to another server to request a Web service response; an applet can, too -- as long as it's talking only to the server on which it was originally hosted. But what if you want an applet that can make arbitrary Web requests?

In this article, I show you how to create a system that uses your browser to request and interact with Web service data from an arbitrary source. First, I create the basic Java applet, then I create the JavaScript code that pulls the data into the Web page. Finally, I create a servlet that acts as a proxy for non-local requests

A simple request
First, take a look at the request you're ultimately going to make from the applet. Although this technique works for any kind of data you can pass through a URL, this article focuses on Web services, so I'll start with the simple SOAP message in Listing 1.

  • Listing 1. A simple SOAP message

    <SOAP-ENV:Envelope 
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="urn:chaosmagnet-quote"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    <ns1:getQuoteResponse>
    <return xsi:type="xsd:string">The early bird gets the worm, but it's the 
    second mouse that gets the cheese...</return>
    </ns1:getQuoteResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>...

[Read More..]

Courtesy: Ibm.com


Google Groups
Subscribe to IndiJava - India Java User Group & Java Community.
Email:
Visit this group