Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Oracle.
Main | Next page »

http://blogs.sun.com/arungupta/date/20100208 Monday February 08, 2010

TOTD #121: JDBC resource for MySQL and Oracle sample database in GlassFish v3

This blog clearly explains how to configure the MySQL sample database (sakila) with GlassFish. Even though the instructions use a specific database but should work for other databases (such as Oracle, JavaDB, PostgreSQL, and others) as well. The second half of the blog provide specific syntax for the Oracle sample database.

  1. Download sakila sample database and unzip the archive.
  2. Install the database as described here - basically load and run "sakila-schema.sql" and "sakila-data.sql" extracted from the archive.
  3. Create a new MySQL user account using MySQL CLI Admin and assign the privileges
    1. Using "root" user (sudo mysql --user root)
      CREATE USER glassfish IDENTIFIED BY 'glassfish';
      GRANT ALL PRIVILEGES ON *.* TO 'glassfish'@'localhost' IDENTIFIED BY 'glassfish';
      FLUSH PRIVILEGES;
      
    2. Using "glassfish" user (sudo mysql --user glassfish)
      source sakila-schema.sql;
      source sakila-data.sql;
      
  4. Download Connector/J, unzip and copy "mysql-connector-java-5.x.x-bin.jar" to "glassfish/domains/domain1/lib/ext" directory.
  5. Start GlassFish server as:
    asadmin start-domain
    
    
  6. Create a JDBC resource
    1. Create JDBC connection pool as:
      asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.DataSource --property "User=glassfish:Password=glassfish:URL=jdbc\:mysql\://localhost/sakila" jdbc/sakilaPool
      
    2. Test the JDBC connection pool as:
      asadmin ping-connection-pool jdbc/sakilaPool
      
    3. Create the JDBC resource as:
      asadmin create-jdbc-resource --connectionpoolid jdbc/sakilaPool jdbc/sakila
      

That's it!

Creating a JDBC resource for any other database requires the following updates to the steps mentioned above. Lets consider modifying these steps for the Oracle sample database.

  1. Use the client interface SQL*PLus and connect as:
    sqlplus "/ as sysdba"
    

    create user and grant the privileges as:
    CREATE USER glassfish IDENTIFIED BY glassfish DEFAULT tablespace users TEMPORARY tablespace temp;
    GRANT CONNECT TO glassfish IDENTIFIED BY glassfish;
    GRANT UNLIMITED TABLESPACE TO glassfish;
    GRANT CREATE TABLE TO glassfish;
    GRANT CREATE SEQUENCE TO glassfish;
    
  2. Copy the appropriate JDBC driver (ojdbc6.jar).
  3. Create the JDBC resource as:
    asadmin create-jdbc-connection-pool --datasourceclassname oracle.jdbc.pool.OracleDataSource --restype javax.sql.DataSource --property "User=hr:Password=hr:URL=jdbc\:oracle\:thin\:@localhost\:1521\:orcl" jdbc/hr
    asadmin ping-connection-pool jdbc/hr
    asadmin create-jdbc-resource --connectionpoolid jdbc/hr jdbc/hr
    

    as explained in TOTD #108.

Here are a few other related entries:

Technorati: totd javaee glassfish v3 jpa mysql sakila oracle

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100205 Friday February 05, 2010

TOTD #120: Deployment Descriptor-free Java EE 6 application using JSF 2.0 + EJB 3.1 + Servlets 3.0

Here is trivial Java EE 6 application that is keeping you away from any deployment descriptors. It uses Java Server Faces 2.0, Enterprise Java Beans 3.1, and Servlet 3.0. This application shows the following Java EE 6 features:

  1. No-interface view for EJB
  2. EJBs packaged in a WAR file
  3. Optional "faces-config.xml" for Java Server Faces
  4. FacesServlet registered using Servlet 3.0 programmatic registration APIs
  5. Java Server Faces navigation rules using convention-over-configuration
  6. Optional "web.xml" for Servlets 3.0

The WAR file structure is:

./index.jsp
./index.xhtml
./META-INF
./show.xhtml
./WEB-INF
./WEB-INF/classes
./WEB-INF/classes/org
./WEB-INF/classes/org/glassfish
./WEB-INF/classes/org/glassfish/samples
./WEB-INF/classes/org/glassfish/samples/SimpleBean.class
./WEB-INF/classes/org/glassfish/samples/SimpleEJB.class
./WEB-INF/classes/org/glassfish/samples/SimpleServlet.class

Look ma, no deployment descriptors!

So how do you create this application:

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.glassfish.samples -DartifactId=simplewebapp

This application is purposely not generated as a web application (missing "-DarchetypeArtifactId=maven-archetype-webapp"). If you specify this property then it will generate "WEB-INF/web.xml" which we don't intend to use.

Change "pom.xml" to:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.glassfish.samples</groupId>
   <artifactId>simplewebapp</artifactId>
   <packaging>war</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>simplewebapp</name>
   <url>http://maven.apache.org</url>
   <repositories>
     <repository>
       <id>glassfish-repository</id>
       <name>Java.net Repository for Glassfish</name>
       <url>http://download.java.net/maven/glassfish</url>
     </repository>
   </repositories>
   <build>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.0.2</version>
         <configuration>
           <source>1.5</source>
           <target>1.5</target>
         </configuration>
       </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
         <version>2.1-beta-1</version>
         <configuration>
           <failOnMissingWebXml>false</failOnMissingWebXml>
         </configuration>
       </plugin>
     </plugins>
   </build>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
    <dependency>
       <groupId>javax</groupId>
       <artifactId>javaee-api</artifactId>
       <version>6.0</version>
       <scope>provided</scope>
    </dependency>
   </dependencies>
</project>

In the above code:
  • "maven-compiler-plugin" needs to be specified as the default source level for Maven compile plugin is JDK 1.3. It's been over 9 years JDK 1.3 was released, not even listed on Java SE standard downloads page, EOLed many years ago. Vote/Comment for the issue MCOMPILER-80 if you'd like this bug to be fixed.
  • Adding "failOnMissingWebXml" ensures that Maven packages the WAR file even though no "web.xml" is present.
  • The complete list of Maven coordinates for GlassFish are available here.

Create the directory structure as:

./src/main
./src/main/java
./src/main/java/org
./src/main/java/org/glassfish
./src/main/java/org/glassfish/samples
./src/main/java/org/glassfish/samples/SimpleBean.java
./src/main/java/org/glassfish/samples/SimpleEJB.java
./src/main/java/org/glassfish/samples/SimpleServlet.java
./src/main/webapp
./src/main/webapp/index.jsp
./src/main/webapp/index.xhtml
./src/main/webapp/show.xhtml

Once again, there are no deployment descriptors, just plain Java files and XHTML/JSP pages.

Here are the different source files with explanation after each one of them:

SimpleBean.java
package org.glassfish.samples;

import javax.faces.bean.ManagedBean;

@ManagedBean(name="simplebean")
public class SimpleBean {
    private String name;
    private int age;

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public int getAge() { return age; }
    public void setAge(int age) { this.age = age; }
}

This is currently a simple JSF managed bean. TOTD #109 explains how to convert a JSF managed bean to use CDI. A future blog will show how to convert this sample to use CDI.

SimpleEJB.java

package org.glassfish.samples;

import javax.ejb.Stateless;

@Stateless
public class SimpleEJB {
    public String sayHello(String name) {
        return "Hello " + name + "!!!";
    }
}

The session bean has no interface, just the @Stateless annotation.

SimpleServlet.java

package org.glassfish.samples;

import javax.ejb.EJB;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.PrintWriter;
import java.io.IOException;

/**
 * Hello world!
 */
@WebServlet(urlPatterns={"/SimpleServlet"})
public class SimpleServlet extends HttpServlet {
    @EJB SimpleEJB bean;

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h2>Serving at: " + request.getContextPath() + "</h2>");
        out.println("<h2>Invoking EJB: " + bean.sayHello("Duke") + "</h2>");
        out.println("</body></html>");
    }
}

The servlet injects the EJB in the application, display the servlet context and the result of invoking the business operation of the EJB.


index.jsp

<html>
<body>
<h2>Hello World!</h2>
Invoke the Servlet by clicking <a href="SimpleServlet">here</a>.
</body>
</html>

This is just a placeholder for invoking the servlet.

index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm
l1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:ui="http://java.sun.com/jsf/facelets"
 xmlns:h="http://java.sun.com/jsf/html">
 <h:head>
 <title>Enter Name &amp; Age</title>
 </h:head>
 <h:body>
 <h1>Enter Name &amp; Age</h1>
<h:form>
 <h:panelGrid columns="2">
 <h:outputText value="Name:"/>
 <h:inputText value="#{simplebean.name}" title="name" id="name" required="true"/>
 <h:outputText value="Age:"/>
 <h:inputText value="#{simplebean.age}" title="age" id="age" required="true"/>
 </h:panelGrid>
 <h:commandButton action="show" value="submit"/>
 </h:form>
 </h:body>
</html>


JSF 2 uses Facelets as viewing technology and so an ".xhtml" file is used for all the JSF tags. This page is intentionally kept simple and not using any templating, composition, or any other features of Facelets. This page renders an HTML form with two text boxes and a command button, binds the value of text box to the managed bean, and displays the page "show.xhtml" when the command button is clicked. The default JSF 2 navigation handler try to match a view on the disk ("show.xhtml" in this case) based upon the "action" attribute.

show.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtm
l1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:h="http://java.sun.com/jsf/html">
 <h:head>
 <title>Show Name & Age</title>
 </h:head>
 <h:body>
 <h1>Show Name & Age</h1>
<h:form action="show">
 <h:panelGrid columns="2">
 <h:outputText value="Name:"/>
 <h:outputText value="#{simplebean.name}" />
 <h:outputText value="Age:"/>
 <h:outputText value="#{simplebean.age}" />
 </h:panelGrid>
 </h:form>
 </h:body>
</html>

This page reads the bean properties (stored from previous page) and displays them on the page.

How do you build this entire application ?

mvn clean package

Lets deploy the application on a Java EE 6 compliant application server, GlassFish v3 (download here):

./bin/asadmin deploy --force=true ~/samples/javaee6/simplewebapp/target/simplewebapp-1.0-SNAPSHOT.war

And now your application is accessible at "http://localhost:8080/simplewebapp-1.0-SNAPSHOT/index.jsp" and looks like:

Clicking on "here" looks like:

The JSF page is accessible at "http://localhost:8080/simplewebapp-1.0-SNAPSHOT/index.jsf" and looks like (after entering the values):

Notice that even though the page is named "index.xhtml", it's accessed as "index.jsf". This is because the JSF specification provides recommended mapping for FacesServlet to "*.faces" and "/faces/*". In addition, Mojarra (Reference Implementation of JSF2 in GlassFish) also adds a mapping to "*.jsf". Any views using these URL pattersn are routed through FacesServlet. So alternative URLs for our page are "http://localhost:8080/simplewebapp-1.0-SNAPSHOT/index.faces" and "http://localhost:8080/simplewebapp-1.0-SNAPSHOT/faces/index.xhtml".

Clicking on "Submit" shows the following page:



That's it!

Here are several other useful entries:

  • TOTD #109 : How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?
  • TOTD #108 : Java EE 6 web application (JSF 2.0 + JPA 2.0 + EJB 3.1) using Oracle, NetBeans, and GlassFish
  • TOTD #102 : Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse
  • TOTD #99 : Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse
  • TOTD #98 : Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
  • TOTD #95 : EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application - Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3
  • TOTD #94 : A simple Java Server Faces 2.0 + JPA 2.0 application - Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3
  • TOTD #93 : Getting Started with Java EE 6 using NetBeans 6.8 M1 & GlassFish v3 - A simple Servlet 3.0 + JPA 2.0 app

The next follow up blog will show "Hello World"s of Context & Dependency Injection, Bean Validation, Java API for Restful Web services, Java Persistence API, Interceptors, and other Java EE 6 specifications in this application.

Technorati: totd javaee glassfish v3 javaserverfaces servlet3 ejb maven

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100201 Monday February 01, 2010

Screencast #29: Web service using NetBeans 6.8 and GlassFish v3 (Accessing database in business method)

GlassFish v3 comes bundled with Metro - a secure, reliable, transactional, and .NET interoperable Web services stack. Metro is compliant with JAX-WS and provides additional quality of service attributes that can be easily enabled using NetBeans IDE.

This blog contains a screencast that shows how to create a simple Web service using NetBeans 6.8, implement the business logic by accessing a database table using Java Persistence API, and deploy on GlassFish v3.

Please post your questions to users@glassfish.dev.java.net.

Several other screencasts on GlassFish v3and related topics are available here.

Technorati: netbeans jax-ws metro webservice glassfish jpa database

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100128 Thursday January 28, 2010

GlassFish strategy by Oracle+Sun

Hear Hasan Rizvi, Senior Vice President, Oracle Fusion Middleware, talk about GlassFish in Oracle and Sun Application Server Strategy webcast. The first part of the webcast is about the overall strategy and then the GlassFish part starts around 5:23 in the video.

Here is a summary for those who want a quick juice:

  • GlassFish joins WebLogic Server in the best java EE application server offering in the industry
  • GlassFish continues as the Java EE reference implementation
  • HotSpot and Java System Web Server augment Oracle's application grid portfolio to provide the most comprehensive, integrated, and open middleware foundation
  • All existing customers current on support will be fully supported according to their existing agreements

Some more detailed points captured from the webcast ...

  • GlassFish continues as the Java EE reference implementation and as an open source project.
  • Oracle's strategic application server, Oracle WebLogic Server, together with GlassFish, provide world class Java EE infrastructure.
  • GlassFish Enterprise Server and WebLogic Server expected to share core components.
  • Oracle plans to add GlassFish Enterprise Server all WebLogic offerings.
  • Hotspot and JRockit become Oracle's strategic JVMs.
  • Java System Web Server part of new Oracle Web Tier offering.
  • GlassFish Web Stack maintained for existing customers.
  • GlassFish Message Queue remains as the GlassFish messaging infrastructure.
  • Oracle plans to license GlassFish Enterprise Server and Java System Web Server with all WebLogic Server offerings.
  • GlassFish also available as standalone offering.
  • GlassFish will continue to be supported and maintained for an extended time period for customers current on support.
  • GlassFish open source projects thrive
  • On-going commitment by Oracle to java.net and other open source projects that make up GlassFish
    • Continue collaboration
    • Blogs - TheAquarium
    • Enhancements - java.net
    • GlassFish wiki

oracle.com/AppServer for more details. The complete list of webcasts on Oracle Fusion Middleware Strategy shares the overall strategy (still evolving).

Also checkout the slides presented by Thomas Kurian on Software Strategy at the webcast yesterday. The complete list of webcasts + slides from yesterday's event are now available.

There are several other articles (in no particular order):

Also check out the FAQ for Developer Community.

Technorati: sun oracle glassfish strategy

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100122 Friday January 22, 2010

TOTD #119: Telnet to GlassFish v3 with NetBeans 6.8 - "Could not open connection to the host"

As explained in TOTD #118, one of the ways to manage OSGi bundles in GlassFish is by giving the command "telnet localhost 6666".

This straight forward command works fine if you installed either the Sun GlassFish Enterprise Server or the GlassFish community bits. The "domain.xml" in both of them is pre-configured for the telnet port to 6666 using the "jvm-options" as shown below:

<jvm-options>-Dosgi.shell.telnet.port=6666</jvm-options>

However if you installed GlassFish as part of NetBeans 6.8, then you might see an error message as shown below:

C:\Users\Arun>telnet localhost 6666
Connecting To localhost...Could not open connection to the host, on
port 6666: Connect failed

This error is more prominent in Windows Vista / 7 because of the Windows User Account Control (UAC). Or anywhere where GlassFish is installed in a directory that require root/administrator/sudo access to read/write. This Tip Of The Day will explain how to workaround this issue.

The default NetBeans installation directory is "C:\Program Files\NetBeans 6.8" and GlassFish goes in "C:\Program Files\sges-v3". At first start of NetBeans (typically as a non-Administrator), it tries to register the pre-configured domain in GlassFish installed in "C:\Program Files". But the non-Adminstrator user do not have read/write access to "C:\Program Files" and any sub-directories. So NetBeans create a new "personal" domain and assign a random port available at that moment for telnet. It shows all the ports assigned during the domain creation as shown below:

The image shows the port number "22007" for OSGI_SHELL.

How do you find that port later ? - Go to "Services" tab, expand "Servers", right-click on "Personal GlassFish v3 Domain", select "Properties" from the popup menu to see the following window:

The "Domains folder" shows the directory location of newly created domain and "Domain Name" has the domain name. The exact assigned port can be found by looking at "Domains folder"\"Domain Name"\config\domain.xml. On my Windows7, it showed the following line:

<jvm-options>-Dosgi.shell.telnet.port=22007</jvm-options>


So I tried "telnet localhost 22007" and voila, it worked!

Some other possible solutions that will work:

  1. Delete ".netbeans" directory and restart NetBeans by right-clicking on selecting "Run as administrator". This will provide the required rights for NetBeans to read/write "C:\Program Files\sges-v3\glassfish\domains\domain1" directory. And so instead of creating a new "personal" domain, it'll register the existing domain in "\Program Files\sges-v3\glassfish". Then "telnet localhost 6666" will work as expected.
  2. During NetBeans installation, specify GlassFish installation directory in a user directory such as:



    This will ensure that NetBeans will have required privileges to read/write the "domains\domain1" directory.
  3. Delete the "Personal GlassFish v3 Domain" and register a new instance that is already installed in a user directory.
  4. Disable UAC.

A complete archive of all the TOTDs is available here.

Technorati: totd netbeans glassfish v3 felix osgi telnet

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100121 Thursday January 21, 2010

TOTD #118: Managing OSGi bundles in GlassFish v3 - asadmin, filesystem, telnet console, web browser, REST

GlassFish v3 and OSGi integration is now known for almost two years. Several blogs have been published on this topic and googling on "glassfish osgi" shows 817,000 results. This blog has published four entries on the topic so far.

This Tip Of The Day (TOTD) will show the different ways you can manage OSGi bundles in GlassFish v3.

The first part is to create a trivial OSGi bundle as explained in TOTD #36.

  1. Create a simple Maven project using the command as shown below:
    ~/samples/v3/osgi >mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.glassfish.samples.osgi.helloworld -DartifactId=helloworld
    [INFO] Scanning for projects...
    [INFO] Searching repository for plugin with prefix: 'archetype'.
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Maven Default Project
    [INFO]    task-segment: [archetype:create] (aggregator-style)
    [INFO] ------------------------------------------------------------------------
    [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
    [INFO] Setting property: velocimacro.messages.on => 'false'.
    [INFO] Setting property: resource.loader => 'classpath'.
    [INFO] Setting property: resource.manager.logwhenfound => 'false'.
    [INFO] [archetype:create]
    [WARNING] This goal is deprecated. Please use mvn archetype:generate instead
    [INFO] Defaulting package to group ID: org.glassfish.samples.osgi.helloworld
    [INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
    [INFO] ----------------------------------------------------------------------------
    [INFO] Using following parameters for creating OldArchetype: maven-archetype-quickstart:RELEASE
    [INFO] ----------------------------------------------------------------------------
    [INFO] Parameter: groupId, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: packageName, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: package, Value: org.glassfish.samples.osgi.helloworld
    [INFO] Parameter: artifactId, Value: helloworld
    [INFO] Parameter: basedir, Value: /Users/arungupta/samples/v3/osgi
    [INFO] Parameter: version, Value: 1.0-SNAPSHOT
    [INFO] ********************* End of debug info from resources from generated POM ***********************
    [INFO] OldArchetype created in dir: /Users/arungupta/samples/v3/osgi/helloworld
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 11 seconds
    [INFO] Finished at: Wed Jan 20 14:12:41 PST 2010
    [INFO] Final Memory: 12M/80M
    [INFO] ------------------------------------------------------------------------
    
  2. Change the generated App class in "src/main/java/org/glassfish/samples/osgi/helloworld" folder so that it looks like:
    package org.glassfish.samples.osgi.helloworld;
    
    import org.osgi.framework.BundleActivator;
    import org.osgi.framework.BundleContext;
    
    /**
     * Hello world!
     *
     */
    public class App implements BundleActivator {
        public void start(BundleContext context) throws Exception {
            System.out.println("Hey!");
        }
        public void stop(BundleContext context) throws Exception {
            System.out.println("Bye!");
        }
    }
    
    
    This is a trivial Activator class but sitll shows the key methods. The changes are highlighted in bold.
  3. Update "pom.xml" with the following changes:
    1. Change <packaging> to "bundle" from the default value of "jar".
    2. Add <dependency> on "org.osgi.core".
    3. Add the <plugin> maven-bundle-plugin and provide <instructions> to generate the appropriate MANIFEST.MF.
      <project xmlns="http://maven.apache.org/POM/4.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                        http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>org.glassfish.samples.osgi.helloworld</groupId>
       <artifactId>helloworld</artifactId>
       <packaging>bundle</packaging>
       <version>1.0-SNAPSHOT</version>
       <name>helloworld</name>
       <url>http://maven.apache.org</url>
       <dependencies>
         <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>3.8.1</version>
           <scope>test</scope>
         </dependency>
         <dependency>
           <groupId>org.apache.felix</groupId>
           <artifactId>org.osgi.core</artifactId>
           <version>1.0.0</version>
         </dependency>
       </dependencies>
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.felix</groupId>
             <artifactId>maven-bundle-plugin</artifactId>
             <extensions>true</extensions>
             <configuration>
               <instructions>
                 <Export-Package>${pom.groupId}</Export-Package>
                 <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                 <Bundle-Activator>${pom.groupId}.App</Bundle-Activator>
               </instructions>
             </configuration>
           </plugin>
         </plugins>
       </build>
      </project>
      

  4. Generate the OSGi bundle as shown below:
    ~/samples/v3/osgi/helloworld >mvn install
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building helloworld
    [INFO]    task-segment: [install]
    [INFO] ------------------------------------------------------------------------
    [INFO] [resources:resources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:compile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/osgi/helloworld/target/classes
    [INFO] [resources:testResources]
    [INFO] Using default encoding to copy filtered resources.
    [INFO] [compiler:testCompile]
    [INFO] Compiling 1 source file to /Users/arungupta/samples/v3/osgi/helloworld/target/test-classes
    [INFO] [surefire:test]
    [INFO] Surefire report directory: /Users/arungupta/samples/v3/osgi/helloworld/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.glassfish.samples.osgi.helloworld.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 sec
    
    Results :
    
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] [bundle:bundle]
    [INFO] [install:install]
    [INFO] Installing /Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar to /Users/arungupta/.m2/repository/org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] [bundle:install]
    [INFO] Parsing file:/Users/arungupta/.m2/repository/repository.xml
    [INFO] Installing org/glassfish/samples/osgi/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar
    [INFO] Writing OBR metadata
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8 seconds
    [INFO] Finished at: Wed Jan 20 14:18:31 PST 2010
    [INFO] Final Memory: 20M/80M
    [INFO] ------------------------------------------------------------------------
    
    
    The generated "target/helloworld-1.0-SNAPSHOT.jar" has the following contents:

     META-INF/MANIFEST.MF
     META-INF/
     META-INF/maven/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.properties
     META-INF/maven/org.glassfish.samples.osgi.helloworld/helloworld/pom.xml
     org/
     org/glassfish/
     org/glassfish/samples/
     org/glassfish/samples/osgi/
     org/glassfish/samples/osgi/helloworld/
     org/glassfish/samples/osgi/helloworld/App.class
    

    And the generated "MANIFEST.MF" looks like:
    Manifest-Version: 1.0
    Export-Package: org.glassfish.samples.osgi.helloworld;uses:="org.osgi.
     framework"
    Built-By: arungupta
    Tool: Bnd-0.0.357
    Bundle-Name: helloworld
    Created-By: Apache Maven Bundle Plugin
    Bundle-Version: 1.0.0.SNAPSHOT
    Build-Jdk: 1.6.0_17
    Bnd-LastModified: 1264025910352
    Bundle-ManifestVersion: 2
    Bundle-Activator: org.glassfish.samples.osgi.helloworld.App
    Import-Package: org.glassfish.samples.osgi.helloworld,org.osgi.framewo
     rk;version="1.3"
    Bundle-SymbolicName: helloworld
    

Lets install this newly created OSGi bundle in GlassFish v3. First, fire up GlassFish as:

~/tools/glassfish/v3/74b/glassfishv3/glassfish >./bin/asadmin start-domain -v
Jan 20, 2010 2:30:39 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: JVM invocation command line:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/java
-cp
/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/glassfish.jar
-XX:+UnlockDiagnosticVMOptions
-XX:MaxPermSize=192m
-XX:NewRatio=2
-XX:+LogVMOutput

. . .

Jan 20, 2010 2:30:40 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFO: Successfully launched in 52 msec.
Jan 20, 2010 2:30:40 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Felix platform

Welcome to Felix
================

[#|2010-01-20T14:30:49.437-0800|INFO|glassfishv3.0|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=11;_ThreadName=FelixStartLevel;|Perform lazy SSL initialization for the listener 'http-listener-2'|#]

[#|2010-01-20T14:30:49.527-0800|INFO|glassfishv3.0|com.sun.grizzly.config.GrizzlyServiceListener|_ThreadID=12;_ThreadName=Thread-11;|Starting Grizzly Framework 1.9.18-k - Wed Jan 20 14:30:49 PST 2010|#]

. . .

[#|2010-01-20T14:30:58.668-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/org.apache.felix.scr.jar|#]

[#|2010-01-20T14:30:58.786-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/osgi-web-container.jar|#]

[#|2010-01-20T14:31:00.436-0800|INFO|glassfishv3.0|null|_ThreadID=23;_ThreadName=ping;|Total number of available updates : 0|#]

There are several ways to manage the OSGi bundles in GlassFish v3:

  1. The "asadmin" command (explained here)
  2. Filesystem operations using the pre-installed Apache Felix File Install bundle (explained here)
  3. A Telnet shell using pre-installed Apache Felix Remote Shell (explained here and TOTD #103)
  4. A Web browser using the Apache Felix Web Console (needs to be installed separately and more details below)
  5. A RESTful client by installing the REST console (need to be installed separately and more details below)


Lets explore each option in detail now.

Option 1: Manage the OSGi bundle using the "asadmin" command

  1. Deploy the generated OSGi bundle using asadmin command:
    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin deploy --type osgi helloworld-1.0-SNAPSHOT.jar 
    Application deployed successfully with name helloworld-1.0-SNAPSHOT.
    
    
    Command deploy executed successfully.
    
    The server log shows the following output:
    [#|2010-01-20T16:15:10.553-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=36;_ThreadName=http-thread-pool-4848-(2);
    |Hey!|#]
    
    
    Notice "Hey!" message in the server log as the bundle gets started.
  2. Verify the installed bundle as:
    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin list-applications
    helloworld-1.0-SNAPSHOT 
    
    Command list-applications executed successfully.
    

    Or if there are multiple applications deployed then only the OSGi bundles can be queried as:

    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin list-applications --type osgi
    helloworld-1.0-SNAPSHOT 
    
    Command list-applications executed successfully.
    
  3. The bundle can be undeployed as:

    ~/samples/v3/osgi/helloworld/target >~/tools/glassfish/v3/74b/glassfishv3/glassfish/bin/asadmin undeploy helloworld-1.0-SNAPSHOT 
    
    Command undeploy executed successfully.
    
    
    And then the following message is shown on the console:
    [#|2010-01-20T16:22:19.554-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=37;_ThreadName=http-thread-pool-4848-(1);
    |Bye!|#]
    
    
    Notice "Bye!" message in second line of the log output indicating the bundle is stopped.

Option 2: Manage the OSGi bundle using file system operations

  1. Copy the generated jar (target/helloworld-1.0-SNAPSHOT.jar) in "modules/autostart" directory as:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >cp ~/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar modules/autostart/
    
    
    and that shows the log output as:
    [#|2010-01-20T16:29:04.625-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Installed /Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/
    helloworld-1.0-SNAPSHOT.jar|#]
    
    [#|2010-01-20T16:29:04.635-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Hey!|#]
    
    [#|2010-01-20T16:29:04.636-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart
    /helloworld-1.0-SNAPSHOT.jar|#]
    
    
    Notice "Hey!" message in the second line of log output as the bundle gets started.
  2. The bundle can be undeployed by removing the JAR file from "modules/autostart" directory as:

    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >rm modules/autostart/helloworld-1.0-SNAPSHOT.jar
    
    
    that shows the following output:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >[#|2010-01-20T16:32:04.677-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Uninstalling bundle 224 (helloworld)|#]
    
    [#|2010-01-20T16:32:04.679-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Bye!|#]
    
    [#|2010-01-20T16:32:04.682-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName={felix.fileinstall.poll=5000, felix.fileinstall.bundles.new.start=true, felix.fileinstall.dir=/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish
    /modules/autostart/, felix.fileinstall.debug=1};|Uninstalled /Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart
    /helloworld-1.0-SNAPSHOT.jar|#]
    
    
    Notice "Bye!" message in second line of the log output indicating the bundle is stopped.

Option 3: Manage the OSGi bundle using a remote Telnet Shell

  1. Connecting to the Felix Remote Shell as:
    ~/tools/glassfish/v3/74b/glassfishv3/glassfish >telnet localhost 6666
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    
    Felix Remote Shell Console:
    ============================
    
    ->
    
  2. Install the bundle as:
    -> install file:///Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar
    Bundle ID: 225
    
    The command output shows "225" as the bundle id. This id is used to start / stop / uninstall the bundle.
  3. Check the bundle status as:
    -> find hello
    START LEVEL 1
       ID   State         Level  Name
    [ 225] [Installed  ] [    1] helloworld (1.0.0.SNAPSHOT)
    
    
    and then start, stop, and uninstall the bundle as:
    -> start 225
    -> stop 225
    -> uninstall 225
    -> find hello
    No matching bundles found
    
    
    which shows following output in the logs:
    [#|2010-01-20T16:43:45.399-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=38;_ThreadName=telnetconsole.shell remote=/127.0.0.1:4894;|Hey!|#]
    
    [#|2010-01-20T16:43:58.516-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=38;_ThreadName=telnetconsole.shell remote=/127.0.0.1:4894;|Bye!|#]
    

    Notice "Hey!" and "Bye!" messages in the log output as the bundle is started and stopped.


Option 4 - Manage the OSGi bundle using a Web browser

Lets see how the OSGi bundles in GlassFish can be managed using Apache Felix Web Console. This is originally explained in Sahoo's blog.

  1. Copy GlassFish OSGi HTTP Service bundle from here (latest) and save it in the "modules/autostart" directory.

  2. Copy Apache Felix Web Console bundle from here (latest) and save it in the "modules/autostart" directory.

  3. Ignore the "NoClassDefFoundError" in the server log. The key is to look for the following message in server log:

    Started bundle: file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/org.apache.felix.webconsole-2.0.4.jar|#]
    
  4. Open the URL "http://localhost:8080/osgi/system/console/bundles" in a browser and use "admin" as the username and "admin" as the password as shown below:



    I had to enter the credentials couple of times for the login to work but finally the following window showed up:



    It shows a complete summary of all the OSGi bundles available/installed/active etc in GlassFish v3. A new OSGi bundle can be installed by clicking on "Choose File" button. Several administration commands such as Start/Stop, Update, Uninstall, Refresh Import Packages can be issued for each bundle by clicking on associated buttons.

  5. Install the OSGi bundle by clicking on "Choose File" and selecting "helloworld-1.0.-SNAPSHOT.jar" and then click on "Install or Update" button. The following message is shown in the server log:

    [#|2010-01-20T17:04:46.654-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com.
    sun.enterprise.v3.services.impl|_ThreadID=39;_ThreadName=Background Install /var/folders/+E/+E6YtSvGGEKNwOA77I-9Fk+++TI/-Tmp-/install1657418488877506078.tmp;
    |Hey!|#]
    

    The bundle gets installed and started as identified by "Hey!" message.
    The recently installed "HelloWorld" bundle looks like:

    Clicking on "helloworld" shows the complete status about the bundle as shown below:

     

  6. The bundle can be stopped by clicking on the Stopped, Refreshed Package Imports, Updated, and Uninstalled by clicking on the respective buttons in the "Actions" column. Clicking on the Stop button shows the following message:

    [#|2010-01-20T17:10:56.359-0800|INFO|glassfishv3.0|javax.enterprise.system.std.com
    .sun.enterprise.v3.services.impl|_ThreadID=25;_ThreadName=http-thread-pool-8080-(2);
    |Bye!|#]
    
    
    Notice "Bye!" message indicating the bundle has stopped.

Option 5: Manage the OSGi bundle using a REST console

  1. If not done already, copy GlassFish OSGi HTTP Service bundle from here (latest) and save it in the "modules/autostart" directory.
  2. Download the REST console bundle (latest) in "modules/autostart" directory.
  3. The complete list of bundles is available in Text or XML format by accessing the URL "http://localhost:8080/osgi/restconsole/bundles/.txt" or "http://localhost:8080/osgi/restconsole/bundles" respectively. Here is how the text output looks like:
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 16198    0 16198    0     0  1173k      0 --:--:-- --:--:-- --:--:-- 1173kbundles 
         bundle 
              id 
                   0 
              symbolic-name 
                   org.apache.felix.framework 
    
    . . .
    
              description 
                   Generated using Pax-Construct 
              vendor 
              version 
                   1.0.0.SNAPSHOT 
              location 
                   file:/Users/arungupta/tools/glassfish/v3/74b/glassfishv3/glassfish/modules/autostart/
    com.knokode.osgi.restconsole.main-1.0-PREVIEW01.jar 
              state 
                   ACTIVE
    
  4. The OSGi bundle should be installed by issuing the following command:
    curl -X PUT file:///Users/arungupta/samples/v3/osgi/helloworld/target/helloworld-1.0-SNAPSHOT.jar http://localhost:8080/osgi/restconsole/bundles
    
    but it's giving a "Segmentation fault". Am following with @fdiotalevi.

    Anyway, the complete usage information of the REST console is described here.

So how do you manage OSGi bundles in GlassFish v3 - asadmin, file system operations, telnet console, web browser, or REST ?

A complete archive of all the TOTDs is available here.

Technorati: totd glassfish v3 osgi apache felix bundles maven

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100112 Tuesday January 12, 2010

TOTD #117: Invoke a JAX-WS Web service from a Rails app deployed in GlassFish

A user on GlassFish Forum tried invoking a JAX-WS Web service from a Rails application and faced some issues. This Tip Of The Day (TTOD) will discuss the different approaches and shows their current status.

A Rails app can be deployed on GlassFish in 3 different ways:

  1. Directory Deployment in GlassFish v3 Server - TOTD #72 explains how to deploy a trivial Rails application (with just a scaffold) on GlassFish v3 server. Even though the blog uses a Rails application, any Rack-based application can be deployed on the server. This server is also the Reference Implementation for Java EE 6 and can also run Grails and Django applications.
  2. Directory Deployment using light-weight GlassFish Gem - GlassFish Gem is a light-weight version of the full-blown server and is stripped to run, just like the server, any Rack-based application such as Merb, Rails, and Sinatra. TOTD #70 shows how to deploy the same application using GlassFish Gem.
  3. WAR file in GlassFish v2.x or v3 - TOTD #73 explains how to deploy a Rails application as WAR file on GlassFish v2. The JNDI connection pooling part of the blog may be skipped to simplify the steps but the concepts are still valid. TOTD #44 shows how to do JNDI connection pooling for GlassFish v3. As GlassFish v2 has in-built support for session replication, TOTD #92 demonstrate how Rails application can leverage that functionality.

Now lets get to the issue reported by the user using these 3 deployment models.

First, lets deploy a simple Web service endpoint and generate a JAR file of the client-side artifacts:

  1. This blog will use a simple Web service as defined in screencast #ws7. The Web service endpoint looks like:
    package server;
    
    import javax.jws.WebService;
    
    /**
     * @author arungupta
     */
    @WebService()
    public class HelloService {
     public String sayHello(String name) {
     return "Hello " + name;
     }
    }
    

  2. Generate Web service client-side artifacts as:
    ~/samples/v3/rails/webservice/tmp >wsimport -keep http://localhost:8080/HelloWebService/HelloServiceService?wsdl
    parsing WSDL...
    
    
    generating code...
    
    
    compiling code...
    
  3. Create a Web service client jar file as:
    jar cvf wsclient.jar ./server
    

Now lets write a Rails application and invoke this Web service:

  1. Create a simple Rails application as:
    jruby -S rails webservice
    

    Optionally you may specify "-d mysql" to use MySQL database. Or better un-comment the following line:
    # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
    

    in "config/environment.rb" as no database interaction is required.
  2. Create a controller and view as:
    jruby script/generate controller home index
    
  3. Update the Controller in "app/controllers/home_controller.rb" as:
    include Java
    
    class HomeController < ApplicationController
     def index
     service = Java::server.HelloServiceService.new
     port = service.getHelloServicePort
    
     @result = port.sayHello("Duke")
     end
    
    end
    
  4. Change the View in "app/views/home/index.html.erb" as:
    <h1>Home#index</h1%gt;
    <p>Find me in app/views/home/index.html.erb</p>
    
    <%= @result %>
    

Now lets deploy this Web service using the 3 different deployment models mentioned above.

GlassFish v3 allows a directory-based deployment of Rails applications. This application needs to locate the Web service client classes. The "wsclient.jar" can be copied to the "lib" directory of Rails application ("webservice/lib" in our case), "domains/domain1/lib/ext" or "JRUBY_HOME/lib". The library can also be passed during deployment using "--libraries" switch. None of this approach seem to work correctly as explained in issue# 11408. So for now, invoking a JAX-WS Web service from a Rails application deployed directly on GlassFish v3 is not possible, at least until the bug is fixed.

In order to deploy the same application using GlassFish Gem, you can copy "wsclient.jar" to the "lib" directory of your Rails application. And also add the following line to "app/controllers/home_controller.rb":

require 'lib/wsclient.jar'

Alternatively you can copy it to "JRUBY_HOME/lib" directory if this Web service client is accessed my multiple applications. In this case there is no need to add any "require" statement to your Controller. Anyway, running the application as:

jruby -S glassfish

and accessing "http://localhost:3000/home/index" shows the following output:

And finally as explained in TOTD #73, bundle up your original Rails application as WAR and then deploy on GlassFish v3 as:

asadmin deploy webservice.war

Make sure to copy "wsclient.jar" to the "lib" directory of your Rails application and then Warbler will copy it to "WEB-INF/lib" of the generated WAR file. The output is shown as below:

So if you want to invoke a Metro/JAX-WS Web service from a Rails application, then run your Rails application using GlassFish Gem or deploying as a WAR file. It'll work on GlassFish v3 server when issue# 11408 is fixed.

Here are some additional links:

  • TOTD #104 also shows how popular Rails applications such as Redmine, Typo, and Substruct can be easily deployed on GlassFish.
  • Rails applications can be easily clustered using Apache + mod_proxy or  nginx.

A complete archive of all the TOTDs is available here.

Technorati: totd glassfish v3 jruby rails webservice jax-ws metro

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100105 Tuesday January 05, 2010

2009 Running Summary - 1286 miles, 71% of running days

Here is a summary of my running logs in 2009:

And a bar chart that shows mileage for each day:

And finally a summary for each quarter:

Quarter Summary
Jan 1 - Mar 31, 2009
Apr 1 - Jun 30, 2009
Jul 1 - Sep 30, 2009
Oct 1 - Dec 31, 2009


The last quarter was just terrible in terms of number of running days and pace but was a good recovery period as well. However I can certainly feel it in terms of the overall reduced pace. The biggest reasons for missed out running in 2009 were falling sick or traveling with no gym facility in the hotel.

Two goals for 2010:

  • Reduce the number of missed days of running - With no upcoming travel plans, this might be a good time to catch up on this goal.
  • Increase the overall mileage - This will require more than a few long distance runs and so will try to get them early on.

The charts shown above can be easily generated using using a Rails application or a Wicket application on GlassFish.

Technorati: glassfish running logs 2009

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20100104 Monday January 04, 2010

FREE Java EE 6 1-week online Codecamp - Jan 12th, 2010

Happy New Year!

Java EE 6, GlassFish v3, and NetBeans 6.8 were released last month. Are you interested in learning how this awesome combination of technologies and products make your life simpler ? Do you want to brush up your skill set and learn to write Java EE 6 code using NetBeans 6.8 and GlassFish v3 ? Would you like to learn  tips & techniques from the experts in GlassFish community ? Do you want to start 2010 with a complete immersion in Java EE 6 & GlassFish v3 ?

If answer to any of the above questions is "yes", then you should consider attending the upcoming free Java EE 6 online code camp. You are certainly welcome to attend the sessions otherwise as well :-)

The goal of this code camp is to let you write code, lots of code, exercising key Java EE 6 technologies.

The sessions are distributed over multiple days (schedule subject to change) as shown below:

Topics Date/Day
Getting Java EE 6 sample codes Jan 12th, 2010 (Tuesday)
Servlet 3.0 Jan 12th, 2010 (Tuesday)
Context and Dependency Injection (JSR 299) Jan 13th, 2010 (Wednesday)
JPA 2.0 Jan 14th, 2010 (Thursday)
EJB 3.1 Jan 15th, 2010 (Friday)
JSF 2.0 Jan 18th, 2010 (Monday)
Java EE 6 End-to-end Examples Jan 19th, 2010 (Tuesday)
GlassFish v3 Jan 20th, 2010 (Wednesday)


Here is what you need to do before attending the hands-on lab session:

  1. Watch the corresponding video-taped sessions from Java EE 6 & GlassFish v3 Virtual Conference.
  2. Send an email to javaee6-codecamp+subscribe@googlegroups.com to register for the course. All discussions can be seen from the web-based forum.
  3. Download & Install JDK 6.0. (1.6.0_017+ for Operating Systems other than MacOS, 1.6.0_015+ for MacOS)
  4. Download & Install NetBeans 6.8 with GlassFish v3 ("Java" or "All" bundle)

If you finish the homework from each lab, yeah there is optional homework ;-), then you'll also be awarded a certificate of completion.

So strap your seat belts and get ready for the Java EE 6 hands-on journey next week!

Always check Java EE 6 Online Codecamp for latest updates.

Technorati: conf glassfish v3 javaee handson lab

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091225 Friday December 25, 2009

Java EE 6 & GlassFish v3 Deep Dive

Merry Christmas!

Get a quick overview of Java EE 6 & GlassFish v3 in this 2-part Deep Dive video (running time of 19:17 mins) with Ed Ort from Sun Developer Network.

Here are some other relevant links:

Technorati: javaee glassfish v3 deepdive interview

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091217 Thursday December 17, 2009

IndicThreads Conference 2009 - Trip Report

I attended my first IndicThreads conference, fourth otherwise, in Pune last week.

This local conference fits very well with "Think Globally, Act Locally" theme. The topics were quite varied ranging from Scala, Lift, Google App Engine, Android, GWT, Distributed Scrum, and of course Java EE 6 & GlassFish v3. All the speakers were well versed with the content and the audience was pretty interactive. Keeping global warming into consideration, the conference adopted the theme of  Go Green. The conference setup provided a great opportunity for social networking.

Here are some of the reasons to attend / sponsor IndicThreads:

  • The conference is the oldest independent event in India focused on Java technology.
  • Pune contributed Rs 25,000 crore ($5.3 billion) in 2008-09 in IT exports with an impressive growth of 24%.
  • There are several major companies like Wipro, Infosys, Cognizant, Accenture, Sybase, Tech Mahindra, WebEx based in Pune.
  • October to March is the best time to visit Pune.
  • The city of Pune certainly offers a really fine cuisine, as evident in the images below.

I presented on:

and the slides are available. Unfortunately the graphics card of my MacBook failed the evening before the conference. So I had to rush to Apple Care center and retrieve my presentations from the hard disk. Fortunately that worked and the slides could be used. There are several blog pointers through out the presentation for the demos shown during the talk:

  • NetBeans and Eclipse tooling for Java EE 6 using GlassFish v3
  • GlassFish v3 Administration and REST interface
  • Ruby on Rails, Groovy and Grails, Python and Django deployment on GlassFish v3
  • Develop / Deploy / Debug Rails application using NetBeans and GlassFish v3
  • GlassFish Gem for Rails / Merb / Sinatra / Rack

Get the complete set of presentations at the conference from this playlist:


SlideShare

Sun Microsystems raffled a Sunspot to the winner of "Java and Green" quiz. Here are the questions:

  1. When was the GlassFish community started ? Tick the right answer.

    1. 2004

    2. 2005

    3. 2006

    4. 2007

  2. Which framework is not supported natively by GlassFish ?

    1. Ruby on Rails

    2. Django

    3. Groovy and Grails

    4. Java EE

  3. Which specifications is not new or did not get a major update in Java EE 6.

    1. Context & Dependency Injection

    2. Managed Beans

    3. Servlet 3.0

    4. JAX-WS

  4. What 3 IDEs have support for Java EE 6 ?

  5.  Name 4 HTTP methods that let you perform RESTful Web services.

  6. Sun Microsystems is now a division of Oracle.

    1. True

    2. False

  7. Name 3 “green” initiatives at IndicThreads Conference 09.

  8. When was IndicThreads.com created?

    1. 2004

    2. 2005

    3. 2006

    4. 2007

  9. The United Nations Climate Change Conference is happening in:

    1. Copenhagen

    2. Belgium

    3. Geneva

Lets see how many can you answer :-) Thanks Aaron Houston for sponsoring the Sunspot.

Watch Harshad Oak, first Java champion in India and founder of the conference, talks about how the conference, intended audience, message to sponsors, and other messages in this short video:

Here are some photographs from the conference:

And here is the complete set of pictures captured by me:

And here is the complete album captured by the conference:

Here are couple of additional reviews of the conference:

Looking forward to participate in this conference next year!

Technorati: conf indicthreads pune india glassfish javaee netbeans eclipse java

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091216 Wednesday December 16, 2009

Pictures from GlassFish v3 Launch Party @ Santa Clara, California - Dec 16, 2009

The GlassFish team celebrated the release of GlassFish v3 at Santa Clara earlier today. There was food, cake, beer, wine, tequila, tee-shirts, quiz contest, iPod shuffle raffles and above all the usual GlassFish spirit which made it extremely fun. See some of the pictures inlined:

And the complete album at:

See the complete set of GlassFish v3 Launch activities.

Did you conduct GlassFish launch party in your geo ? Please feel free to share pictures.

Technorati: glassfish v3 party santaclara

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091208 Tuesday December 08, 2009

TOTD #116: GlassFish v3 Administration using JavaFX front-end - JNLP available

As mentioned in TOTD #113, this Tip Of The Day (TOTD) provides a working version of the JavaFX front-end for GlassFish v3 administration.

Please click here to launch the JNLP or click here to a page that provides some introduction along with the link to JNLP. You may like to enable Java Console as explained in TOTD #114 for any log messages.

See a video of the tool in action:

Many thanks to Rajeshwar for providing feedback and helping me understand the RESTful interface better. TOTD #96 explains how the REST interface can be used.

Here is a TODO list in no particular order:

  • Show a splash screen after the startup to indicate server status
  • Allow the administration host/port to be changed
  • Tie the "server stats" with the server uptime instead of fetching once and then binding it locally
  • Provide dynamic updates of the monitoring data, currently its a snapshot
  • Convert the monitoring levels text boxes to radio buttons
  • Provide complete hints on setting monitoring level based upon the engines
  • Enable/Disable the buttons based upon the status of server running (or not)
  • Introduce charts to track dynamic shrink/expand of threads/pools/etc.
  • Probably something else that I'm forgetting :-)

How are you using JavaFX with GlassFish ?

How will you use GlassFish v3 REST interface in your tools ?

Technorati: totd javafx glassfish v3 rest web jruby rubyonrails rest administration monitoring management

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091207 Monday December 07, 2009

Java EE 6 Training & Certifications - Register Early!

Java EE 6 is now an approved specification, the Reference Implementation (GlassFish v3) and TCK will be released soon!

The associated training curriculum and certifications are being worked upon by Sun Learning Services. The curriculum has gone through a complete overhaul for Java EE 6 & GlassFish v3 and will be available in Q1 2010. If you are interested in getting notified when these new courses are released and also receive special introductory promotions, then please register here.

There are technology specific "deep-dive" training courses and tied to new technology specific certifications. You just need to specify your interest in the particular technology and will be contacted once the courses & certifications are available.

In the meanwhile, you can follow any of the existing Learning Paths to brush up your skills.

Technorati: javaee glassfish v3 training certification

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20091204 Friday December 04, 2009

TOTD #115: GlassFish in Eclipse - Integrated Bundle, Install Stand-alone or Update Existing plugin

There are three options for Eclipse users interested in exploring GlassFish. They can either use an integrated bundle, install the GlassFish plug-in in an existing Eclipse version, or update an older GlassFish plugin in a stand-alone Eclipse to the latest version. These options are explained below.

GlassFish Tools Bundle for Eclipse 1.1 is an integrated bundle based on Eclipse 3.4.2 and includes GlassFish v2 and v3 Prelude pre-registered and configured and optionally JDK 1.6 U12. The work towards version 1.2 can be tracked by following the 1.1.x releases (1.1.7 is the latest). This new version is based on Eclipse 3.5.1, includes GlassFish v3 build 74 pre-registered and configured, several plugins (JSF Facelets, JAX-WS, Maven m2) and several Java EE 6 wizards to provide a seamless development and deployment experience with Java EE 6 & GlassFish v3. There are several other niceties in the newer release like pre-registered MySQL JDBC driver, updated Java EE 5 and Java EE 6 javadoc and code completion.

However what to do if you are already using an Eclipse version in your environment ?

The basic requirement is Eclipse 3.4+. A GlassFish plugin can be easily installed in any Eclipse 3.4+ and provides all the GlassFish-related functionality. The screencast #28 shows how to get started with Eclipse 3.4.2 and configure GlassFish as a standard server adapter.

If you are using Eclipse 3.5.0, then the standard technique described in the above screencast will not work because of the issue #280365. Fortunately, the bug report also has a workaround. Instead of using the "Download additional server adapter", install using the "Help", "Install New Software ..." and explicitly adding the GlassFish plugins update site. A screen snapshot looks like:

If you are using Eclipse 3.5.1, then the standard technique of "Download additional server adapter" works as described in the screencast #28. A screen snapshot looks like:

If you already have an existing version of GlassFish plugin installed, then it can be updated as described in TOTD #66. The process is much more simplified now and menu items have changed little bit in Eclipse 3.5.x - "Check for Updates" instead of "Software Updates ...". The screen snapshot looks like:

Now you can start developing your applications using Eclipse. Several blog entries have already been published:

  • TOTD #102 explains how to use Servlet 3.0 and EJB 3.1 wizards in Eclipse.
  • TOTD #99 explains how to create a JPA 2.0 compliant application.
  • TOTD #98 explains how to create a Metro JAX-WS Web service.
  • TOTD #54 shows how to create a JavaServer Faces application with Eclipse.

Future blogs will provide more details on the new features added recently. Until then, the GlassFish Plugin Release Notes provide a summary.

On a slightly different note, you can even run GlassFish with Eclipse Equinox OSGi runtime as explained in TOTD #103.

Technorati: totd eclipse glassfish v3 javaee

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
Main | Next page »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.