Tech all over the world
Saturday, April 29, 2006
  Enterprise Java Technologies Tech Tips, April 29, 2006 (Porting Java WSDP 2.0 Web Services, Call Flow Monitoring)
You are receiving this e-mail because you elected to receive e-mail from Sun Microsystems, Inc. To update your communications preferences, please see the link at the bottom of this message. We respect your privacy and post our privacy policy prominently on our Web site http://sun.com/privacy/

Please do not reply to the mailed version of the newsletter, this alias is not monitored. Feedback options are listed in the footer for both content and delivery issues.
  Welcome to the Enterprise Java Technologies Tech Tips.
Enterprise Java Technologies
TECHNICAL TIPS
April 29, 2006
View this issue as simple text
In this Issue
 
Welcome to the Enterprise Java Technologies Tech Tips for February 25, 2006. Here you'll get tips on using enterprise Java technologies and APIs, such as those in Java 2 Platform, Enterprise Edition (J2EE) and Java Platform, Enterprise Edition (Java EE).

This issue covers:

» Porting Java WSDP 2.0-Based Web Services to Java EE 5
» Call Flow Monitoring in GlassFish

These tips were developed using an open source reference implementation of Java EE 5 called GlassFish. You can download GlassFish from the GlassFish Community Downloads page.

You can download the sample archive for the tip Porting Java WSDP 2.0-Based Web Services to Java EE 5. You can download the sample archive for the Call Flow Monitoring in GlassFish tip..

Any use of this code and/or information below is subject to the license terms.

See the Subscribe/Unsubscribe note at the end of this newsletter to subscribe to Tech Tips that focus on technologies and products in other Java platforms.

PORTING JAVA WSDP 2.0-BASED WEB SERVICES TO JAVA EE 5
 
by Vijay Ramachandran

One of the technologies available in J2EE for developing and deploying web services is Java API for XML-Based RPC (JAX-RPC). However, using JAX-RPC technology requires a developer to specify a lot of information in deployment descriptors such as webservices.xml, web.xml, and ejb-jar.xml. These requirements are seen by many programmers as cumbersome and confusing.

To simplify the web services programming model, the Java API for XML Web Services (JAX-WS) was introduced. The main focus of JAX-WS technology is ease of web services development and deployment. A lot of this simplicity results from annotations. An earlier Tech Tip, "Developing Web Services Using JAX-WS" showed some of these annotations in use. These and other JAX-WS features have eliminated the requirement for deployment descriptors.

JAX-WS technology was initially made available in the Java Web Services Developer Pack (Java WSDP) Version 2.0. This allowed early adopters to develop JAX-WS-based web services and deploy them on J2EE 1.4 implementations such as the J2EE 1.4 SDK (which includes the Sun Java System Application Server 8.2 Platform Edition) or Apache Tomcat. However, because JAX-WS technology became available after the release of J2EE 1.4, using it with that level of the platform required the addition of some platform-specific information in various deployment descriptors. Unfortunately, that platform-specific information restricts porting to Java EE 5 of any JAX-WS-based web services developed using Java WSDP 2.0.

This Tech Tip describes what you need to do to change a JAX-WS-based web service developed using Java WSDP 2.0 and deployed on the J2EE 1.4 platform so that it can be ported to the Java EE5 platform.

Getting Started

A sample package accompanies this tip to help demonstrate the migration process. It contains the source code and associated files for building a web service. Two versions of the code and files are provided. One version is for building a web service using Java WSDP 2.0 and deploying it on Java System Application Server 8.2 Platform Edition. The other version is for building and deploying a web service on GlassFish, an open source reference implementation of Java EE 5.

If you haven't already done so, download and install the following:

Then download the sample package for the tip and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/ttapr2006migws, where <sample_install_dir> is the directory in which you installed the sample package. You can find the two versions of the code and files in the jwsdp-as82 directory and jwsdp-gf directories below the ttapr2006migws directory.

Building a Web Service With Java WSDP 2.0

To build the web service, you need to:

  1. Write an endpoint implementation class.
  2. Compile the endpoint implementation class.
  3. Generate portable artifacts required for web service
  4. execution.
  5. Package the web service as a WAR file and deploy it.
An endpoint implementation class, AddNumbers, is provided in the jwsdp-82\endpoint directory. You can compile the web service and generate the portable artifacts it needs, by executing an asant task that's defined in the build file in the jwsdp-82 directory. First start Java Application Server 8.2 Platform Edition:
    %S1AS_HOME%\bin\asadmin start-domain  
Then execute the following command:
    <sample_install_dir>\jwsdp-82\asant service  
The service task compiles the endpoint implementation class and runs the wsgen tool to generate the portable artifacts.

To package the web service as a WAR file and deploy it, execute the following command (on one line):
    %S1AS_HOME%\bin\asadmin deploy     <sample_install_dir>\jwsdp-82\build\jwsdp-add.war 
What's significant here from a portability point of view is that this process requires various descriptor files: a web.xml file (in this case, jwsdp-web.xml) and sun-jaxws.xml. These need to be packaged with the web service for deployment.

The web.xml file includes a <listener> element that registers a servlet context listener for the web application being deployed.
    <listener>     <listener-class>     com.sun.xml.ws.transport.http.servlet.WSServletContextListener     </listener-class>    </listener> 
The registration of the servlet context listener is required by the Java WSDP 2.0 to do all the needed initialization for the web service endpoint when the WAR is deployed.
    <servlet>      <servlet-name>AddService</servlet-name>      <servlet-class>       com.sun.xml.ws.transport.http.servlet.WSServlet      </servlet-class>      <load-on-startup>1</load-on-startup>    </servlet> 
The web.xml file also includes a <servlet> element that points to com.sun.xml.ws.transport.http.servlet.WSServlet. This reference is specific to the Java WSDP platform. It's required so that all requests for the URL defined for this web service endpoint get routed through a common servlet. The common servlet then routes the requests to the appropriate web service endpoint.

The sun-jaxws.xml file contains additional information about the endpoint.

After you deploy the web service, you can view its generated WSDL file by pointing your browser to the URL http://localhost:8080/jwsdp-add/addnum?wsdl. A client references this WSDL file to use the web service.

Although the deployed web service is certainly valid and usable by J2EE and Java EE 5 clients, it's not portable to all Java EE containers. That's because the content of the jwsdp-web.xml file contains platform-specific information. In addition, the sun-jaxws.xml file is a vendor-specific file.

Now let's look at how to make the web service portable so that you can use it in Java EE 5.

Making the Web Service Portable

The specification "Implementing Enterprise Web Services", JSR-109, specifies the programming model for implementing a web service in Java EE 5. To make a web service developed using Java WSDP 2.0 and deployed on the J2EE 1.4 platform deployable on the Java EE5 platform, you need to ensure that it conforms to the JSR-109 specification.

You still need to provide an endpoint implementation class and compile it. However based on JSR-109, you no longer package the vendor-specific descriptor file, sun-jaxws.xml. All information required about the endpoint is derived by the platform implementation from the @WebService annotation in the endpoint implementation class.

Also, you no longer need to package a web.xml file. If you don't provide the file, the platform will define a default one. However if you do provide it for packaging with the web service, you need to ensure that:
  • The web.xml file points to the latest servlet schema:
          <web-app xmlns="http://java.sun.com/xml/ns/javaee"       xmlns:j2ee="http://java.sun.com/xml/ns/javaee"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       version="2.5" xsi:schemaLocation=      "http://java.sun.com/xml/ns/javaee       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    This is important because annotation processing will happen only for applications that use Java EE5-based descriptors.


  • There is no need for the <listener> element in the web.xml file. All the required initializations are done as part of the deployment of the web service in Java EE platform.


  • A <servlet> element is required in which the <servlet-name> is the port-component-name of the web service endpoint (that is, @WebService.name). For example:
          <servlet>      <servlet-name>AddNumbers</servlet-name>      <servlet-class>endpoint.AddNumbers</servlet-class>      <load-on-startup>1</load-on-startup>      </servlet> 
    If you don't provide a <servlet-name> element, the name defaults to the simple name of the endpoint implementation class, and the <servlet-class> defaults to the full name of the endpoint implementation class.

You can see this by examining the files provided in the jwsdp-gf directory of the sample archive. Notice that there is no sun-jaxws.xml file. Also notice that in the jwsdp-web.xml file there is no <listener> element, and the <servlet> element follows the rules mentioned previously.

One other important item of note: You have the option of running the wsgen tool to generate portable artifacts or not. If you don't run wsgen, the Java EE 5 platform implementation will generate portable artifacts for you at the time of deployment.

You can build and deploy the same JAX-WS-based web service as you did for J2EE 1.4. This time you'll build and deploy it in Java EE 5, using the files in the jwsdp-gf directory. You can find the endpoint implementation class, AddNumbers, in the jwsdp-web.xml file\endpoint directory.

Start GlassFish as follows:

     %GLASSFISH_HOME%\bin\asadmin start-domain  

Then execute the following commands:

    <sample_install_dir>\jwsdp-gf\asant service          %GLASSFISH_HOME%\bin\asadmin deploy     <sample_install_dir>\jwsdp-gf\build\javaee-add.war 

Notice that the service task does not run wsgen. There is no wsgen in the build file for the task. The portable artifacts are generated automatically when you deploy the WAR file.

After you deploy the web service, you can view its generated WSDL file by pointing your browser to the URL http://localhost:8080/javaee-add/addnum?wsdl.

In summary, the Java EE 5 platform makes the service portable by:
  • Not requiring you to package all portable artifacts. Because of that, you do not need to run platform-specific tools such as wsgen.
  • Not requiring you to package platform-specific descriptors such as sun-jaxws.xml.
  • Not requiring a web.xml file for packaging. However, if you provide a web.xml for packaging, its contents do not have any platform-specific information.
About the Author

Vijay Ramachandran is a senior member of the Sun Java Application Server team. He has worked in the J2EE group for the last six years, and was a key contributor to the deployment and web services-related features of Sun Java System Application Server versions 8.X and 9.X. Previously, Vijay was the technical lead for Java BluePrints team, where he co-authored books on the J2EE 1.3 and 1.4 platforms.

Back to Top

CALL FLOW MONITORING IN GLASSFISH
 
by Harpreet Singh and Anissa Lam

The January 28, 2006 Tech Tip, Monitoring Web Services describes how you can use GlassFish, an open source application server implementation of Java EE 5, to monitor web services. However, there are other useful monitoring and management capabilities in GlassFish. One important GlassFish feature called Call Flow enables you to monitor applications deployed in the application server. A developer can use this feature at development time to see how the application behaves. An administrator can use this feature to monitor the runtime behavior of deployed applications.

Call Flow collects runtime information about an application, such as the time spent in various containers, and time spent in the application code. This information can help in performance tuning and debugging an application. Calls from the application are monitored as they flow through various containers in the application server and through the application code. For example, consider a servlet in the application that calls a method on an enterprise bean. In this scenario, Call Flow monitors the request as it enters the web container, and continues monitoring the request as it flows from the servlet's service method, to the EJB container, and finally to the enterprise bean method. CallFlow then writes the collected information to a persistent storage device.

You can then examine the recorded information. You can also "drill down" to get further information about a specific application request.

This Tech Tip shows you how to use Call Flow from the GlassFish Administration Console to monitor an enterprise application.

Step 1: Getting Started

If you haven't already done so, download GlassFish from the GlassFish Community Downloads page.

Then set the following environment variables:
  • GLASSFISH_HOME: This should point to where you installed GlassFish (for example C:\Sun\AppServer)

  • JAVA_HOME: This should point to the location of JDK 5.0 on your system.

Step 2: Start GlassFish

Start GlassFish by entering the following command:
    <GF_install_dir>/bin/asadmin start-domain domain1 
where <GF_install_dir> is the directory in which you installed GlassFish.

Step 3. Start the Administration Console

After GlassFish starts, open the Administration Console by pointing your browser to:
    http://localhost:4848 
The host ID localhost is the default host ID and 4848 is the default port number for the Administration Console. Change these values, as appropriate, for your configuration.

Then login with the appropriate administrator user name and password (the default username is admin, and the default password is adminadmin).

Step 4: Enable Call Flow

You can enable Call Flow either in the Administration Console or by command.

To enable Call Flow from the Administration Console, do the following:
  1. In the tree component, select the Application Server node.
  2. Click the Monitor tab.
  3. Click the Call Flow tab. The Call Flow page appears.
  4. Check the Enabled checkbox in the Configuration section of the page to initiate Call Flow monitoring for the server.
  5. Optionally, specify the client host IP address and user ID for which you want to enable monitoring. Doing this can be very useful in a production system to track the flow (and possible performance problems) for a particular type of request.
  6. Click Save

To enable Call Flow by command, enter the following command (on one line):
     <GF_install_dir>/bin/asadmin asadmin     start-callflow-monitoring server 

Step 5: Download and Deploy the Sample Archive

Download the sample archive for the tip. The sample archive is a deployable archive for an enterprise application that you will monitor with Call Flow.

After you download the sample archive deploy it. You can do this in various ways. For example, you can copy the sample archive to the GlassFish autodeploy directory (<GF_install_dir>/domains/domain1/autodeploy), or you can use the Administration Console to deploy the sample archive.

Step 6. Run the Application

Run the deployed application by entering the URL http://localhost:8080/helloworld in a browser window other than the one running the Administration Console. You should see a page that says "Hello World Sample Application". You should also see a prompt to enter a name.

Enter a name, for example "Duke" and click the Process button. In response you should see a page that says something like this:
    Hello World !     Good morning, Duke. Enjoy your morning.  

Step 7: Display Call Flow Data

Use the Administration Console to view the data that was recorded by Call Flow. Although Call Flow needs to be enabled to monitor and record call flow data, it doesn't need to be enabled for you to view data it already recorded. So you can optionally disable Call Flow before you view the data. (See "Step 8: Disable Call Flow" for instructions on how disable Call Flow.)

You can find the call flow data in the Call Flow Data section of the Call Flow page in the Administration Console. The data is displayed in a table, with each row of the table displaying data for a specific request. You should see a row of data for the Hello World sample application that you ran.

The table includes data such as the time stamp when the request was processed by the application server, the principal used to send the request (a call that is made without any user principal is displayed in the table as "anonymous"), and the name of the application to which the request was sent to.

If you want to delete the data for a request listed in the table, check the checkbox of that row and click the Delete button. This will remove the data permanently. There is a drop down menu that allows you to filter the request. By default, data for all requests to the server are displayed. You can filter the displayed data based on:
  • The final status of a request, that is, Success or Failure

  • The start container, that is, the container in which the request originated. The containers are WEB, Web Service, EJB, Timer EJB, and Asynchronous Message. Note that JMS messages directed to the application server are flagged as asynchronous messages. So if you want data displayed about JMS messages, select Asynchronous Message as the start container. Also, if you want data about IIOP messages displayed (as well as data about EJB requests), select EJB as the start container.
Filtering does not delete any recorded data, it simply controls what is displayed in the table.

You can display more detailed data about a request by clicking on the entry for the request in the Time Stamp column. In response, you should see a Call Flow Details page that displays information such as the response time for the request, and how much time the request spent in each container. You'll also see a table that presents in sequence the call flow of the request through the containers. For each step in the calling sequence, the table displays the pertinent container, component, and method.

You can display the a parent-child view of the methods called in the call flow by clicking the View Tree button.

Step 8: Disable Call Flow

As is the case for enabling Call Flow, you can disable it from the Administration console or by command. To display Call Flow from the Administration Console, uncheck the Enabled checkbox on the Call Flow configuration page.

To disable Call Flow by command, enter the following command (on one line):
    <GF_install_dir>/bin/asadmin asadmin     stop-callflow-monitoring server 

Note that Call Flow is automatically disabled when you stop the application server. After you next start the application server, you can reenable Call Flow by rechecking the Enabled checkbox on the Call Flow configuration page.

Additional Information About Call Flow

For more information about Call Flow, see the GlassFish project CallFlow home page.

About the Authors

Harpreet Singh is a member of Sun Java System Application Server group at Sun Microsystems. He has been involved in J2EE development from the last seven years. His current interests are call flow monitoring and web services management. In the past, he has been a key contributor in security infrastructure of the Application Server.

Anissa Lam is a member of the Sun Java System Application Server group at Sun Microsystems. She has worked in the J2EE group for the last five years, focusing on various IDEs, such as Sun Java Studio, and deployment tools. Anissa has been a key contributor to the Administration Console function of the Application Server.

Back to Top

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.
Comments? Send your feedback on the Tech Tips: http://developers.sun.com/contact/feedback.jsp?category=newslet

Subscribe to the following newsletters for the latest information about technologies and products in other Java platforms:
  • Core Java Technologies Tech Tips. Get tips on using core Java technologies and APIs, such as those in the Java 2 Platform, Standard Edition (J2SE).
  • Wireless Developer Tech Tips. Get tips on using wireless Java technologies and APIs, such as those in the Java 2 Platform, Micro Edition (J2ME).
You can subscribe to these and other Java technology developer newsletters or manage your current newsletter subscriptions on the Sun Developer Network Subscriptions page

IMPORTANT: Please read our Terms of Use, Privacy, and Licensing policies:
http://www.sun.com/share/text/termsofuse.html
http://www.sun.com/privacy/
http://developer.java.sun.com/berkeley_license.html

ARCHIVES: You'll find the Enterprise Java Technologies Tech Tips archives at:
http://java.sun.com/developer/EJTechTips/index.html

© 2006 Sun Microsystems, Inc. All Rights Reserved. For information on Sun's trademarks see: http://sun.com/suntrademarks
Java, J2EE, J2SE, J2ME, and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.



Please unsubscribe me from this newsletter.


 
Comments: Post a Comment



<< Home
News, Articles, events from all over the world

My Photo
Name:
Location: India

Born on shraavana shudha chauthi of dundubhi naama samvaswara, Im kiran alias kini alias kiri bought up by loving parents. Being from agricultural family I have learnt plowing, carting but never learnt climbing trees. Now away from home I have lost touch with the agricultural skills.

ARCHIVES
January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 /


Powered by Blogger