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. |
| ||||||
In this Issue | ||
Welcome to the Enterprise Java Technologies Tech Tips for March 27, 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 5 (Java EE 5). This issue covers: » Developing Web Services Using EJB 3.0 » Using Custom MBeans to Extend the GlassFish Administration System 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 Developing Web Services with EJB tip. You can download the sample archive for the Using Custom MBeans 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. | ||
DEVELOPING WEB SERVICES USING EJB 3.0 | ||
by Manisha Umbarje The specification Web Services for Java EE, JSR 109 defines two ways of implementing a web service. One way is based on the Java class programming model -- the web service is implemented by a Java class that runs in a web container. The other way is based on the Enterprise JavaBeans (EJB) programming model -- the web service is implemented as a stateless session bean that runs in an EJB container. A previous Tech Tip, Developing Web Services Using JAX-WS, described how to develop a web service using the Java class programming model and Java API for XML Web Services (JAX-WS) 2.0, JSR 224. In the following tip, you'll learn how to develop a web service using JAX-WS and the EJB programming model. In particular, you'll learn how to use an EJB 3.0 stateless session bean to implement a A sample package accompanies this tip. It demonstrates a standalone Java client accessing the EJB 3.0-based Writing the EJB 3.0 Stateless Session Bean Class Let's start by creating the stateless session bean for the service. One of the significant improvements in the Java EE 5 platform is a much simpler EJB programming model as defined in the Enterprise JavaBeans 3.0 Specification, JSR-220. One of the simplifications is that a bean implementation class is no longer required to implement the EJB 3.0 does specify additional rules for the bean implementation class:
Another simplification in EJB 3.0 is that a component interface or home interface is no longer required for a session bean. The one interface a session bean needs is a business interface that defines the business methods for the bean. Unlike business methods in a component interface, the business methods in a business interface are not required to throw Given these simplifications and rules, here is a stateless session bean for the package endpoint; import javax.ejb.Stateless; @Stateless public class Calculator { public Calculator() {} public int add(int i, int j) { int k = i +j ; System.out.println(i + "+" + j +" = " + k); return k; } } Because the EJB 3.0 bean doesn't need to implement the Marking the EJB 3.0 Bean as a Web Service To mark a bean as a web service simply annotate the class with the package endpoint; import javax.ejb.Stateless; import javax.jws.WebService; @Stateless @WebService public class Calculator { public Calculator() {} public int add(int i, int j) { int k = i +j ; System.out.println(i + "+" + j +" = " + k); return k; } } Marking a Java class with a Packaging the Web Service A web service based on the EJB programming model needs to be packaged as a JAR file. Using the With JSR 224, JSR 109, JSR 181 and JSR 220, an application server deployment tool can generate all the necessary artifacts such as a deployment descriptor (if not explicitly provided by the user) for deploying the web service. These artifacts, bundled in the EJB JAR file, are deployed in an EJB container. A deployer can choose to overwrite values specified by the endpoint/Calculator.class endpoint/jaxws/Add.class endpoint/jaxws/AddResponse.class The rest of the deployment artifacts are generated by the application server (in this case, GlassFish). Writing the Client After you deploy the web service, you can access it from a client program. A client uses a @WebServiceRef(wsdlLocation= "http://localhost:8080/CalculatorService/Calculator?WSDL") static endpoint.CalculatorService service; The value of the Looking further at the source code for endpoint.Calculator port = service.getCalculatorPort(); The After you get the port, you can invoke a business method on it just as though you invoke a Java method on an object. For example, the following line in int ret = port.add(i, 10); Running the Sample Code A sample package accompanies this tip. It demonstrates the techniques covered in the tip. To install and run the sample:
About the Author Manisha Umbarje is a member of the product engineering group for the Sun Java System Application Server. Back to Top | ||
USING CUSTOM MBEANS TO EXTEND THE GLASSFISH ADMINISTRATION SYSTEM | ||
by Nandini Ektare and Kedar Mhaswade One of the areas significantly enhanced in Java 2 Platform, Standard Edition (J2SE) 5.0 is monitoring and management. Among the key features J2SE 5.0 introduced is an instrumented Java virtual machine (JVM) and a java.lang.management API for monitoring and managing the JVM. The API enables local and remote access to a variety of JVM-related information such as memory usage, thread state, class loading activity, and garbage collection statistics. This enhanced and integrated support for management and monitoring can be used by any J2SE 5.0-based administration application. GlassFish and MBeans One tool that takes advantage of these capabilities is GlassFish, an open source application server implementation of Java EE 5. The GlassFish application server leverages all of the J2SE 5.0-based monitoring and management enhancements in its administration infrastructure. This includes the use of the platform MBean server to register application server MBeans. Management Beans (or "MBeans") are Java objects that follow design patterns conforming to the Java Management Extensions (JMX) specification -- they are used for instrumenting resources. This tip assumes that you're familiar with the basics of JMX. For an introduction to JMX, see the Tech Tip Understanding JMX Technology. The platform MBean server, also introduced in J2SE 5.0, is a JMX-based agent built into the JVM, that gives management applications access to MBeans. The agent can be shared by all managed components running in the JVM. Through the platform MBean server, GlassFish can provide a comprehensive and consolidated monitoring and management view of the system and application-specific MBeans. GlassFish uses this built-in agent instead of creating an instance of its own agent (as was required previous to J2SE 5.0). Because application server MBeans are registered in the platform MBean server repository, tools such as the Java Monitoring and Management Console (JConsole) can display information about all resources instrumented by the application server MBeans. GlassFish and Custom MBeans Significantly, you can extend GlassFish's administration features by creating and registering your own custom MBeans. Custom MBeans allow dynamic injection of monitoring and management features. In addition, instrumented custom MBean attributes can be persisted so that they survive even if the application server needs to be restarted. One place where custom MBeans demonstrate their utility is in GlassFish's Self Management Framework. This is a rule-based event management system, where users can add custom actions, implemented as custom MBeans, to the rules that govern the system. Example: Extending Monitoring and Management Capabilities This tip presents an example that uses custom MBeans to extend GlassFish's monitoring and management features. The example extends a Java EE application that processes data that it gets periodically from a web service. The administrative extension is to add an event to be monitored and an action for the application to take in response to that event. The event is an update to a list of email addresses. The action is to send emails to the updated list of email addresses. In this scenario, a custom MBean, which is also a client of the web service, would update the list of email addresses after polling the web service. However, to simplify things in this example, the string of email addresses is an attribute of the custom MBean. A user directly modifies the list using JConsole. When the attribute is modified, a listening custom MBean is notified. The listening custom MBean then processes the event by sending emails to the updated list of email addresses (that is, the updated value of the attribute). A sample archive accompanies this tip. It contains the source code and compiled classes for the example. It also includes javadoc for the classes used in the example. Step 1: Setup Let's start by doing some initial setup. If you haven't already done so, download GlassFish from the GlassFish Downloads page. Then set the following environment variables:
Step 2: Start GlassFish Start GlassFish by entering the following command: <GF_install_dir>/bin/asadmin start-domain domain1 where Step 3: Download the sample archive: Download the sample archive for the tip and extract its contents: jar xvf ttmar2006custmbean.jarAfter you extract the contents, you should see a META-INF directory, a techtip directory, and a javadoc directory. The techtip directory contains the source files and compiled classes for the example. Step 4: Create the custom MBeans This example uses two custom MBeans, one for the event source, and one to listen for the event (the event "sink"). You can find the source code for the two custom MBeans in the A custom MBean requires an MBean interface and an MBean implementation class. The custom MBean interface for the event source is After you create the source files for the custom MBeans, you can compile the files into the javac -d . EventSourceCustom.java EventSourceCustomMBean.java javac -d . EventSinkCustom.java EventSinkCustomMBean.java When you compile the Step 5: Copy the Custom MBean classes Copy the Step 6: Deploy the Event Source Custom MBean Deploy the event source custom MBean, <GF_install_dir>/bin/asadmin create-mbean --user admin --passwordfile password.txt --port 4848 com.example.mbeans.EventSourceCustom This registers You can verify that the custom MBean has been deployed by issuing the following command (the command should be entered on one line): <GF_install_dir>/bin/asadmin list-mbeans --user admin --passwordfile password.txt In response, you should see the following: com.example.mbeans.EventSourceCustom user:impl-class-name=com.example.mbeans.EventSourceCustom, name=com.example.mbeans.EventSourceCustom Enabled Command list-mbeans executed successfully. Step 7: Deploy the Event Sink Custom MBean Deploy the event sink custom MBean, <GF_install_dir>/bin/asadmin create-mbean --user admin --passwordfile password.txt --port 4848 --objectname "user:impl-class-name=com.example.mbeans.EventSinkCustom, name=custom-event-sink" --attributes HostName=<yourmailserver>:Id=<yourId>: Password=<yourpw> com.example.mbeans.EventSinkCustom Notice the As mentioned earlier, instrumented custom MBean attributes can be persisted so that they survive even if the application server needs to be restarted. So in specifying the parameters in the command, it configures the runtime parameters of the custom MBean. However after the MBean is created, the parameters persist across server restarts. Again, you can verify that the custom MBean has been deployed by issuing the following command (the command should be entered on one line): <GF_install_dir>/bin/asadmin list-mbeans --user admin --passwordfile password.txt In response, you should see the following: com.example.mbeans.EventSourceCustom user:impl-class-name=com.example.mbeans.EventSourceCustom, name=com.example.mbeans.EventSourceCustom Enabled com.example.mbeans.EventSinkCustom user:impl-class-name=com.example.mbeans.Event SinkCustom, name=custom-event-sink Enabled Command list-mbeans executed successfully. Step 8: Update the email list In this example, you use JConsole to update an attribute of the custom MBean that contains a string of email addresses. Start JConsole by issuing the following command: <JAVA_HOME>/bin/jconsole When you start JConsole, you should see a connection dialog box with tabs for local, remote, and advanced JMX connections. Click the Remote tab, and enter the appropriate host (localhost), port (GlassFish's JMX connection server listens at port 8686), user name (admin), and password (adminadmin) values.
Click the Connect button in the display for the remote tab. This connects to the platform MBean server using an RMI connector. In the subsequent Connection window, click on the MBeans tab. Expand the user branch in the MBean tree in the left pane of the window. Continue expanding the branches below the user branch until you see the server entry below
Click the Attributes tab in the right pane of the window. Then enter your email address in the value field for the attribute
The event source custom MBean sends a notification when you change the AttributeChangeNotification attrnotif = (AttributeChangeNotification) notif; String newEmailIdStr = (String)attrnotif.getNewValue(); The event sink custom MBean then sends email to the updated addresses. Step 9: Check for the email Check your email to verify that the listening custom MBean sent an email to your address. Your should receive the following message: For further information, see the following:
About the Author Nandini Ektare is a member of Sun Java System Application Server Development group at Sun Microsystems Inc. Her areas of interest include JMX and Java EE. Kedar Mhaswade is a staff engineer at Sun Microsystems Inc. He is a member of the Expert Group for JSR 003: Java Management Extensions. His areas of interest include open source software, JMX, and Java EE. Back to Top | ||
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:
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. |
You are receiving this e-mail {e-mail address} 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. |
Sun Java Studio Enterprise Developer NEWSLETTER | |
March 2006, Vol. 5 No. 03 |
|
|
Comments and Contact Information: There are three ways to send your feedback about the Sun Java Studio, Enterprise Developer Newsletter: Fill out the web form at http://developers.sun.com/contact/feedback.jsp?category=newslet Mail your feedback to the following address: Sun Java Studio Editorial Team, MS: 4150 Network Circle, Santa Clara, CA 95054, USA Subscribe/Unsubscribe: Subscribe to other Java technology newsletters: You can subscribe to these and other Sun Developer Network publications on the SDN Newsletters and Publications page. - To subscribe, visit https://softwarereg.sun.com/registration/developer/en_US/subscriptions, select the newsletters you want to subscribe to, and click "Update." - To unsubscribe, go to https://softwarereg.sun.com/registration/developer/en_US/subscriptions, uncheck the appropriate checkbox, and click "Update." IMPORTANT: Please read our Licensing and Terms of Use policies: http://developers.sun.com/berkeley_license.html http://www.sun.com/share/text/termsofuse.html Privacy Statement: Sun respects your online time and privacy (http://sun.com/privacy). You have received this based on your email preferences. If you would prefer not to receive this information, please follow the steps at the bottom of this message to unsubscribe. © 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. This document is protected by copyright. For more information, see: http://java.sun.com/developer/copyright.html This service may provide, or third parties may provide, links to other Internet sites or resources. Because Sun has no control over such sites and resources, you acknowledge and agree that Sun is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource. |
Please unsubscribe me from this newsletter. |
You are receiving this email because you elected to receive email 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. |
March 24, 2006 |
| ||
Core Java Technologies NEWSLETTER | |||
Here you'll find links to the latest products, tools, resources, and events relating to development with the Java Platform, Standard Edition (Java SE, formerly referred to as J2SE). |
|
|
Comments and Contact Information: There are three ways to send your feedback about the Core Java Technologies Newsletter: For comment about the content of this newsletter, fill out the Rate and Review form, above. For technical assistance about Newsletter delivery, broken links, or subscribe/unsubscribe help, fill out the web form. Write to us at: SDN Editorial Team, MS: UMPK18-113, 18 Network Circle, Menlo Park, CA 94025, USA Subscribe/Unsubscribe: Subscribe to other Java technology newsletters:
- To subscribe, visit the SDN Newsletters and Publications page, select the newsletters you want to subscribe to and click "Update." - To unsubscribe, go to the subscriptions page, uncheck the appropriate checkbox, and click "Update." IMPORTANT: Please read our Licensing, Terms of Use, and Privacy policies: http://developer.java.sun.com/berkeley_license.html http://www.sun.com/share/text/termsofuse.html Privacy Statement: Sun respects your online time and privacy (http://sun.com/privacy). You have received this based on your email preferences. If you would prefer not to receive this information, please follow the steps at the bottom of this message to unsubscribe. Archives: You'll find the Core Java Newsletter archives at: http://java.sun.com/developer/techDocs/Newsletters/jdc_newsletters.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. Sun Microsystems, Inc. 10 Network Circle, MPK10-209 Menlo Park, CA 94025 US |
Please unsubscribe me from this newsletter. |
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.