Professional Documents
Culture Documents
Web Applications
At this point in the course, students should be familiar with the concept of web applications. Most should,
at this point, have written their own web application, integrating client, application and data storage tiers to
provide a variety of functionality.
However, there are two types of web applications:
• Presenation-oriented: A presentation-oriented web application generates interactive web pages
containing various types of markup language (HTML, XML etc.) and dynamic content in response
to requests. This is the form of web application we are familiar with and we have covered practical
implementations of such applications through the vast majority of this module.
• Service-oriented: A service-oriented web application implements the endpoint of a web service.
Presentation-oriented applications are often clients of service-oriented web applications. It is this form
of web application we are concerned with in this chapter.
The diagram above shows a generic architecture for Web Services. The core element of this relates to the
communication between the service requester and the service provider. This communication is handled via
the Simple Object Access Protocol (SOAP).
<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:GetStockQuote xmlns:ns1="urn:xmethods-quotes">
<SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<symbol xsi:type="xsd:string">IBM</symbol>
</ns1:GetStockQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The SOAP server, using the support of complex XML parsers, decodes the call and figures that you want to
get a stock quote. It then quickly fetches the stock quote and sends you back a packet like so:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<SOAP-ENV:Body>
<m:GetStockQuoteResponse xmlns:m="urn:xmethods-quotes">
<Price>34.5</Price>
</m:GetStockQuoteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This, after removing all the envelopes, simply tells you that the price of the IBM stock was 34.5. Most
commercial servers would return a LOT more information than just this, such as what currency, last traded
price etc. However, the example is displayed to show the basic structure of SOAP messages.
The SOAPAction header indicates the 'intent' of a request, and it is mandatory. Each SOAP server could
have multiple functions, and it could decide to use the SoapAction header to figure out which function is
being called. Also, firewalls etc. can filter content using this header. The SOAP response from the HTTP
server will be as follows:
HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
Setup
1. After starting Eclipse, select the Java EE perspective: Windows -> Open Perspective -> Others ->
Java EE
2. In the servers tab at the bottom of the page, right click in the window and select New -> Server
3. To download the Glasfish Server Adaptor, select Download additional server adaptors. Accept the
license and let Eclipse restart
4. After Eclipse has retstarted, you can create a new GlassFish V2 Java EE5 server
5. In the creation dialog select Installed Runtimes and select the directory where your Java EE has been
installed
6. We can then right click on the server instance to start up our Sun Application Server. Note: Ensure that
Tomcat had previous been shut down, as the Sun Application server and Tomcat server default ports are
both 8080.
Note: These five steps are a once off step. The setup stage can be skipped for future deployments.
package sample;
import javax.jws.WebService;
@WebService
public class Calculator {
public int sum(int param1, int param2){
return param1 + param2;
}
public int multiply(int param1, int param2) {
return param1 * param2;
}
}
You have now written and deployed a web service! However, before you shut down your computer and
settle into happy dreams for the night, you're going to need to deploy a client. A web service doesn't provide
any functionality without clients.
7. http://wiki.eeng.dcu.ie:8888/ee557/g3/743-EE.html (Calculator.java)
package sample;
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 2)
{
System.out.println("Usage - CalculatorClient num1 num2");
8. http://wiki.eeng.dcu.ie:8888/ee557/g3/746-EE.html (interfax.wsdl)
9. http://wiki.eeng.dcu.ie:8888/ee557/g3/744-EE.html (CalculatorClient.java)
//create proxy
Calculator proxy = service.getCalculatorPort();
//invoke
System.out.println("Sum of the arguments = " + proxy.sum(a,b));
System.out.println("Multiple of the arguments = " + proxy.multiply(a,b));
}
}
Fields
Name Value
Height 480
Width 640
Start Flash false
Loop false
Start video false
Start audio false
Navigation
Next: Chapter 11: Introduction to Ajax10
Previous: Chapter 9: Messaging with Java11