Java Jazz Up
Java Jazz Up
Editorial
Dears Readers, We are back here with the May 2008 special issue of Java Jazz-up. This current May edition is designed as Web Services special issue. From the last issue we decided to release our magazine as special issue on a single technology. Our last issue was designed as Ajax special issue. The issue really proved very popular and valuable among our readers. We hope the issue will be more popular and valuable for all readers. Web Service is one of the most popular and useful techniques in the landscape of software development. Web Services allows different applications to talk to each other and share data and services among them. Other applications can also use the services of the web services. For example VB or .NET application can talk to java web services and vice versa. So, Web services are used to make the application platform and technology independent. In the issue, our readers will learn reating and deploying our own web services with xis2, Apaches Web services framework. In addition as per the growing popularity of Web Services we have included two relevant tutorials on Web Services published in IBM developerWorks with consent. We are thankful to the team of IBM for granting permission regarding the same. To make it interesting for readers we have categorized each section with different colors and images that would certainly lure readers while reading technological stuffs. We are providing it in PDF format that you can view and even download it as a whole or a part. This PDF version provides you a different experience. Please send us your valuable feedback about this issue and participate in the readers forum with your problems and issues concerned with the topics you want us to include in our next issues. Editor Deepak Kumar Java Jazz up
Editor-in-Chief
Deepak Kumar
Sr. Editor-Technical
Ravi Kant Noor-En-Ahmed
Graphics Designer
Santosh Kumar
Content
05 An introduction to Web Services | Web services are web-based application that translates your application into browser-based application using XML, SOAP, WSDL and UDDI. Why and how to use Web Services | Web services have the tendency of higher Interoperability that means web services allows the companies to communicate each other on the basis of business. Role of XML in Web Services | Because of its innovative characteristics, web services are called the nexgen (next generation) web technology. For developing any application or website, the programmers have to create lots of coding, generates many files which produces difficulties in handling those data if it is done manually. Web Services Components | Web service has three main components: Soap, WSDL and UDDI. Web Service Frameworks |There are many frameworks for web services. Here is the list of some frameworks available: Web Service Protocols | Here is the list of some protocols used for Web Services: What is Axis2?| Axis2 is Apaches Web services framework with two implementations Apache Axis2/Java and Apache Axis2/C. As discussed earlier Web services are very good means of inter application communication. Installing Axis2| Download axis2-1.4.zip (Standard Binary Distribution) from to http:// ws.apache.org/axis2. Developing Simple Web Service Example: Hello World Web Service| In this section, we will learn developing web services with Axis2 by an easy example HelloWorldService and deploying it on the tomcat web server. Web Services benefits | Exposing the function on to network: A Web service can be remotely invoked using HTTP. So, Web Services allows you to expose the functionality of your existing code over the network. Deploy Web services in Apache Geronimo| Deciding on an application server to support your Web services development efforts? Meet the Apache Geronimo application server, one of the latest projects from the Apache Software Foundation. Create collaborative and dynamic method content using Web 2.0| IT practitioners commonly use software development methodologies, such as the IBM Rational Unified Process (RUP). Methods like this can be applied across a variety of software development disciplines and industry verticals. Advertise with Us | We are the top most providers of technology stuffs to the java community. Our technology portal network is providing standard tutorials, articles, news and reviews on the Java technologies to the industrial technocrats. Valued JavaJazzup Readers Community | We invite you to post Java-technology oriented stuff. It would be our pleasure to give space to your posts in JavaJazzup. 06
08
09 11 12 13
14
15
21
23
29
35
36
Web Services
Web services are web-based application that translates your application into browser-based application using XML, SOAP, WSDL and UDDI. World Wide Web Consortium (W3C) has defined it as a software system designed to communicate machine to machine over a network without time-consuming custom coding. These applications usually allow organizations to communicate data without interfering in one anothers system. In web service, XML tags the data within the message; SOAP is a protocol specification that transfers the data, the Web Services Description Language (WSDL) defines the description of available service while Universal Description Discovery and Integration (UDDI) provides the list of available services. Web service does not provide the Graphics User Interface by default but the programmers can add it to provide it to the clients by making it as a specific web service application.
10
12
What is axis2?
What is axis2? Axis2 is Apaches Web services framework with two implementations Apache Axis2/Java and Apache Axis2/C. As discussed earlier Web services are very good means of inter application communication. This communication is possible with the help of XML. SOAP protocol defines the schema for a message to be sent when using web services. SOAP engine is required to create and interpret SOAP messages. AXIS2 is such a SOAP engine. Apache Axis2 supports both SOAP 1.1 and SOAP 1.2 and also has integrated support for the widely popular REST-style of web services. Apache Axis2 is more efficient, modular, and scalable than the older version Axis1.x. Axis2 provides many new features with enhanced functionality. Some of the main features are Speed, Low memory foot print, AXIOM, Hot Deployment, Asynchronous Web services, MEP Support, Flexibility, Stability, Component-oriented Deployment, Transport Framework, WSDL support, Add-ons, Composition and Extensibility.
Installing Axis2:
Installing Axis2:
Download axis2-1.4.zip (Standard Binary Distribution) from to http://ws.apache.org/ axis2. Unzip it into c:\axis2-1.4 folder. Set environment variable AXIS2_HOME to the path name of axis2 directory i.e. c:\axis21.4.
Make sure you have installed JDK(version 1.4 or later). Set the environment variable JAVA_HOME to the pathname of the directory into which you installed the JDK.
14
16
18
20
22
Java Specification request (JSR) 109 (implementing Enterprise Web Services 1.1) Java API for XML-based Remote Procedure Call (JAX-RPC) SOAP with Attachments API for Java (SAAJ) 1.2 Java API for XML Registries (JAXR) 1.0
Support for these standards makes Geronimo a viable option when deciding on an application server to support your Web services development efforts. If you've already used the open source projects that make up Geronimo, the transition to Geronimo as your deployment container should come naturally. To make development and deployment of J2EE applications on Geronimo even easier, several Eclipse plug-ins are also available. These plug-ins are part of the Eclipse Web Tools Platform (WTP) (scheduled to have its 1.0 launch in July 2005). See Resources for links to the WTP and related information. Using Amazon Web Services (AWS) as an example, you'll learn how to consume Web services with Geronimo. You'll be guided through taking the Web Services Description Language (WSDL) for AWS and using Apache Axis to build the consumer code. You'll see a simple Java class that consumes the Web service and learn how this class is invoked from a JSP file to display the results of the Web service. Finally, you'll bundle the code as a J2EE WAR file and deploy it on Geronimo. Consuming Amazon Web Services To consume AWS, you need to build the service consumer using Apache Axis as the SOAP implementation. (Axis is the underlying SOAP implementation that Geronimo supports.) If you have done this in the past and have the code, feel free to jump ahead. Requirements for generating AWS code Begin by setting up your environment. To generate the AWS consumer code, you need four things:
Java software development kit (JDK) 1.4.2 or later. (See Resources to link to the Java Web site.)
Set up your environment The next series of steps guides you through setting up your environment by downloading the elements listed above as follows:
Install the JDK into C:\jdk_142_05. Set the JAVA_HOME to this directory. Extract Apache Axis into C:\axis1-2, and define AXIS_HOME as this directory. Copy the WSDL file into the AXIS_HOME directory. Register for the AWS subscription ID.
Now that you have the basic environment ready to go, you can start generating the code to consume the Web service. Generate the Java code from the WSDL First, generate the Java code that will consume the Web service from the WSDL file. Apache Axis comes with a utility called WSDL2Java that performs this task for you. To run this tool, make sure the following Java Archive (JAR) files are in your classpath. The sample setenv.bat script shown in Listing 1 does this for you. Listing 1. Setenv.bat set AXIS_HOME=c:\axis-1-2 set CLASSPATH=. set CLASSPATH=%AXIS_HOME%\lib\axis.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\commons-discovery.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\commons-logging.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\jaxrpc.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\saaj.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\log4j-1.2.8.jar;%CLASSPATH% set CLASSPATH=%AXIS_HOME%\lib\wsdl4j.jar;%CLASSPATH% Now, from the AXIS_HOME directory, run the following command to generate the Java code: java org.apache.axis.wsdl.WSDL2Java AWSECommerceService.wsdl This process takes a few seconds to create a directory called com under AXIS_HOME. Now you can start creating a Web Archive (WAR) file that you will eventually deploy on Geronimo. Create a directory called C:\amazon-client. You'll use this directory to store the code for the WAR file. Under this directory, create a directory called WEB-INF and a directory called src. Copy the com directory from your AXIS_HOME to C:\amazon-client\WEB-INF\src. This code is the basic code for consuming a Web service. For now, you don't need to go into the details of this code. Write code to consume the Web service Next, write a client to the Web service. In this example, you'll write a simple Java class that calls the appropriate classes that were generated using WSDL2Java. (Tools such as Eclipse and IBM Rational Application Developer generate a stubbed version of this code for you automatically. Thus, I won't spend much time on the specifics of how to write this code.)
24
public Items[] lookupISBN(String isbn) throws Exception { try { System.out.println("Given ISBN is " + isbn); AWSECommerceServiceLocator locator = new AWSECommerceServiceLocator(); AWSECommerceServicePortType type = locator.getAWSECommerceServicePort(); String itemId[] = {isbn.trim()}; ItemLookup lookup = new ItemLookup(); lookup.setAssociateTag("MY ID"); // fill in your own lookup.setSubscriptionId("MY ID"); // fill in your own ItemLookupRequest lookupReq = new ItemLookupRequest(); lookupReq.setMerchantId("All"); lookupReq.setItemId(itemId); lookupReq.setResponseGroup(new String[] {"Medium", "OfferFull", "Variations", "Images"}); ItemLookupRequest[] requests = lookup.getRequest(); requests = new ItemLookupRequest[1]; requests[0] = lookupReq; lookup.setRequest(requests); ItemLookupResponse response = type.itemLookup(lookup); Items[] items = response.getItems(); if (items != null && items.length > 0) { System.out.println("Number of results "+ items.length); return items; } } catch (javax.xml.rpc.ServiceException se) { throw new Exception(se.getMessage()); }
May-08 Java Jazz Up 25
You must register with Amazon to get a subscription ID (see Consuming Amazon Web Services above). After you get your subscription ID, replace it in the code in Listing 2. Now you're ready to compile this code. After you have run the setenv.bat file, you should be able to compile the code easily by running javac *.java:. You get several class files in this directory. For simplicity of packaging, I copy the entire src directory into a new directory called WEB-INF/classes. Then, from WEB-INF/classes, I delete all the Java source files; from WEB-INF/src, I delete all the class files. If you use an integrated development environment (IDE), such as Eclipse, a lot of this manual work is done for you automatically. Now you can invoke your Web service and see the results. Use a JSP file to do this. Write a JSP file to display results from the Web service Under the amazonclient directory, create a JSP file called searchAmazon.jsp. The code is shown in Listing 3. In the JSP file shown in Listing 3, you're calling the AmazonClient class that you defined and receiving an array of Item objects. You then iterate over this array to display the values. You now have all the code you need. Final steps before deploying the code The last step is to set up the deployment descriptors so you can deploy the WAR file on Geronimo. Under the WEB-INF directory, create two simple XML deployment descriptors. The first is the standard J2EE WAR deployment descriptor, called web.xml (see Listing 4). Listing 4. web.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_3.xsd" version="2.3"> <display-name>Amazon Sample</display-name> <welcome-file-list> <welcome-file>t;searchAmazon.jsp</welcome-file> </welcome-file-list> </web-app> Geronimo requires a geronimo-jetty.xml descriptor. The code is shown in Listing 5. Listing 5. geronimo-jetty.xml descriptor
26
You have now successfully deployed your first Web services consumer in Geronimo. Standard J2EE Web services The example in this article is simple, but it has shown that Geronimo supports standard J2EE Web services. As an exercise in using Web services, you can try out other options available in AWS. For example, change the ISBN search to be a title or author search. Then, from the Web service results, figure out how to display a URL that links to Amazon.com, and show an image of the book. Another interesting exercise is to use other J2EE technologies along with Apache Axis to consume Web services, and then deploy them in Geronimo. For example, replace the AmazonClient.java Plain Old Java Object (POJO) with a stateless session Enterprise JavaBean (EJB) component, and then deploy it in Geronimo. You can take any Web service from webMethods or the Google Web services as an example. If you apply the same steps described in this article, you can quickly deploy a consumer to these Web services in Geronimo. Summary Now that you've met Geronimo and seen its Web services capabilities, you should be ready to get started using the Geronimo application server in your Web services development efforts.
28
Become outdated; for example, guidance artifacts such as templates, assets, or tool mentors become obsolete. Lack specific context details without being customized. For example, due to the nonspecific nature of the off-the-shelf method content, it needs to be adapted for the situation in which it's being applied, such as the organization, industry domain, roles, activities, assets, and tools. Customizations require republishing. Lack the ability to be augmented by the user or practitioner and, thus, can't take advantage of the user's contribution to community content development and enhancement. Consequently, opportunities for feedback and collaboration by the user community is often lost. Lack the ability to leverage media-rich content, such as videos, podcasts, and flash demonstrations because they typically become outdated quickly. Tend to lack detailed commercial off-the-shelf tool guidance. Off-the-shelf, lack guidance for organizational assets or tools.
There are several activities associated with this collaborative and dynamic content. Let's take a closer look at these activities. Extension point identification The process engineer identifies extension points in a static method. Typically these extension points are in areas of the method that describe new or improved techniques, or both, and in areas for which content needs to be built with the help of community or will quickly become out of date.
30
Collaborative guidance area The collaborative guidance content area provides up-to-date guidance on the method for this extension point. Typically the initial content in this page is populated by another process engineer skilled in the art of this particular extension point. The content in this area can be, for example, the latest information on tools and how to obtain them, and then used to execute this extension point more effectively. This collaborative area is also editable by the user (practitioner or architect) to allow for field-based lessons and input to be captured, thus keeping the best practices and fieldbased lessons learned about this extension point up to date. An example of a Web 2.0 implementation of this collaborative guidance area is a wiki. Dynamic content area The dynamic content area dynamically provides assets and artifacts to the user or practitioner to help him or her execute the task described by this extension point. The kinds of assets and artifacts can include social bookmarks; subject matter experts (including their instant messaging statuses); documents; publications; presentations; media-rich syndicated content, such as podcasts and movies; and education materials, including blogs, online course material, and classes. Because the information in this area is dynamic, the system builds content at the time the practitioner requests the page so that he or she is always guaranteed of the latest information. An example of a Web 2.0 implementation of this dynamic content area is aggregated Web feeds. The static method process engineer repeats the creation of extension pages for each extension point identified in the static method. By adopting this technique for creating a method, the dynamic content is automatically built when a user requests a specific page and includes information from many different sources outside of the core method contents. This dynamic content can be provided by practitioners, not just method authors (process engineers). This dynamic content is accessible from the method, not scattered over the Internet or intranet. Figure 2 illustrates where method contents are located (topology view). It's best to read the comments from bottom to top, starting from the consultant's local machine.
The advantages of adopting this kind of approach to software method development are:
Method content isn't restricted to what's being shipped by a method at a specific version. Method contents are always up to date. Practitioners, not just process engineers, can provide contents for the method. Practitioners don't need to download new versions of a frozen method. Contents are no longer restricted to what an engineering department can produce given their time, budget, and headcount constraints. Media-rich and innovative contents (for example, list of experts on a topic, podcasts, and flash movies) are easily integrated into method contents. Methods can contain both frozen (static) core contents and spots where organizations or communities can extend and customize contents. Practitioners can easily find experts on a given topic.
32
Identifies the points in the static method that can be extended. Provides links to collaboratively built dynamic contents from these extension points. For each link, provides a wiki page with two areas: Up-to-date editable textual information Dynamically populated Web feeds on social bookmarks, people, activities, blogs, or assets
Here's how the method works and is implemented for a particular Service-Oriented Architecture (SOA) analysis scenario (see Figure 3): Figure 3. Collaborative and dynamic method implementation
An example of how it can be used is as follows: A software architect in an SOA engagement is currently involved in the analysis of an SOA system. In SOA, one of the core activities is called service identification. Because SOA projects are by their very nature complex, and because SOA is still in the process of being understood, SOA activities and the tools to support these activities are fully understood only by a small number of practitioners. It's highly unlikely that a static method includes up-to-date content on the best practices around these activities or, indeed, the tooling that could make these activities more streamlined. To address this shortcoming, extension points are identified in the base method. Where the static method is rendered in HTML, these extension points are hyperlinks from inside the method. In this example, the SOA architect is doing service identification. The static method contains high-level guidance around service identification and a link to collaboratively built dynamic content on specific tools used for service identification. This link brings the architect to a collaborative Web site, such as a wiki
May-08 Java Jazz Up 33
Social bookmarks and subject matter experts of service identification (including their instant messaging status). Reusable assets from an asset repository (including documentation patterns and even tooling for services identification). Media-rich content (including technical presentations, movies, or podcasts). Educational content (including blogs, course material, other reading material, and IBM Redbooks). Activities that the architect needs to follow to complete the extension point around service identification successfully.
This is made possible by being able to embed all of this dynamic content in a wiki with syndicated Web feeds formatted as RSS or Atom. Each of the dynamic items above has its own Web feed, and these feeds are aggregated to provide all of the dynamic content. This is already possible, and by standardizing on Web 2.0 technology and tags, for example, all service identification-related content checked into an asset repository are tags with the service identification and dynamic-method keyword. After an item is checked into the Web feed-enabled asset repository with these keywords, the Web feed provided by the asset repository is automatically updated. As the extension page is refreshed for the service identification extension point, the updated content is now available to the method practitioner (architect). This can also be done with all of the content for the other dynamic feeds.
34
The http://www.roseindia.net network is the real deal for technical Java professionals. Contact me today to discuss your customized sponsorship program. You may also ask about advertising on other Technology Network. Deepak Kumar [email protected]
If theres something youre curious about, were confident that your curiosity, combined with the knowledge of other participants, will be enough to generate a useful and exciting Readers Forum. If theres a topic you feel needs to be discussed at JavaJazzup, its up to you to get it discussed. Convene a discussion on a specific subject If you have a topic youd like to talk about . Whether its something you think lots of people will be interested in, or a narrow topic only a few people may care about, your article will attract people interested in talking about it at the Readers Forum. If you like, you can prepare a really a good article to explain what youre interested to tell java technocrates about. Sharing Expertise on Java Technologies If youre a great expert on a subject in java, the years you spent developing that expertise and want to share it with others. If theres something youre an expert on that you think other technocrates might like to know about, wed love to set you up in the Readers Forum and let people ask you questions. Show your innovation We invite people to demonstrate innovative ideas and projects. These can be online or technology-related innovations that would bring you a great appreciations and recognition among the java technocrates around the globe. Hands-on technology demonstrations Some people are Internet experts. Some are barely familiar with the web. If youd like to show others aroud some familiar sites and tools, that would be great. It would be our pleasure to give you a chance to provide your demonstrations on such issues : How to set
36 Java Jazz Up May-08
38