Thursday Dec 03, 2009

Java EE Service Engine for GlassFish V3

GlassFish v3 provides the Sun Java EE Engine (Java EE Service Engine), a JSR 208-compliant Java Business Integration (JBI) runtime component that connects Java EE web services to JBI components. It acts as a bridge between the Java EE and JBI runtime environments for web service providers and web service consumers.

Here are the steps for using Java EE Service Engine with Fuji(OpenESB-v3)

- Download the latest GlassFish V3, promoted build from here. (http://download.java.net/glassfish/v3/promoted/). Download glassfish-v3-b\*-unix.sh or glassfish-v3-b\*-windows.exe file, so that the GlassFish update tool is also available.

- Install glassfish-v3, remember to check on "Install Updatetool" checkbox, during the installation. Let's call the GlassFish install directory as GF_HOME.

- Fuji-GlassFish container is available for installation with GlassFIsh-v3 at http://download.java.net/maven/open-esb/fuji/fuji-gf-container/

- Installing the fuji-glassfish-container :
    cd $GF_HOME/glassfish
    jar -xvf ~fuji-gf-container.jar

- Start the glassfish update tool : $GF_HOME/bin/updatetool. Select Java EE Service Engine from the list of available addons and install it.

updatetool

- Start domain :

     -- cd $GF_HOME/bin
     -- ./asadmin start-domain

- Deploying the Service Assembly:

     -- cp ~mySA.jar $GF_HOME/glassfish/domains/domain1/autodeploy/bundles or
     -- ./asadmin deploy ~mySA.jar

- Undeploying the Service Assembly:

     -- rm $GF_HOME/glassfish/domains/domain1/autodeploy/bundles/mySA.jar or
     -- ./asadmin undeploy mySA


Useful Links:

Java EE Service Engine Details: http://java.sun.com/developer/technicalArticles/J2EE/sunjavaee_engine/
List of available JBI components: http://download.java.net/maven/open-esb/fuji/components/installers/

Thursday Dec 25, 2008

Hello World - GlassFish-V3 Module

GlassFish v3 has a modular and extensible architecture. Hence, it provides a lot of opportunities to add more and more functionality to it. So, why not explore its modular architecture with a simple hello world module !!!
To start with we need to be familiar with the HK2 component services and OSGi module management subsystem.
In our example we will extend the asadmin command to add our own hello command to the admin command utility.

Method Decleration:

AdminCommand is exposed by glassfish through annotation @contract, this has to be implemented in order to make use of the asadmin command. Hello command will be implemented as a service using the annotation @Service, which helps in the runtime discovery of the command.The command name is specified with the @Service annotation.

@Service(name="hello")
public class HelloCommand implements AdminCommand{
    ......
}

Command Execution:
To enable an asadmin command to run, we need to implement the execute method of the AdminCommand interface. The execute method is declared as:

public void execute(AdminCommandContext context){
   ....
}
The ActionReport which is obtained from AdminCommandContext is used to return the command status or error message to the client, hence the complete hello world execute method will be:

public void execute(AdminCommandContext context){
        ActionReport report = context.getActionReport();
        report.setMessage("Hello World !!!");
        report.setActionExitCode(ExitCode.SUCCESS);
}

Writing pom.xml for the project:

Our project structure is:
    hello.command
        |---> pom.xml
        |---> hello-command
              |--->pom.xml
              |--->src/main/java/testcomponent/HelloCommand.java

The pom.xml under hello.command is the top level pom.xml with the packaging type pom. Which will be more useful is case there are multiple modules.

pom.xml under hello-command includes:


Identification of the module.
    ....   
    <artifactId>hello-command</artifactId>
      <packaging>hk2-jar</packaging>
      <version>${pom.parent.version}</version>
      <name>Hello Command Sample</name>
    ....

Required Plugins, maven-bundle-plugin and hk2-maven-plugin, are specified as:
    ....
    <build>
        <plugins>
        <plugin>
                   <groupId>org.apache.felix</groupId>
                   <artifactId>maven-bundle-plugin</artifactId>
                    ....
        </plugin>
        <plugin>
                   <groupId>com.sun.enterprise</groupId>
                   <artifactId>hk2-maven-plugin</artifactId>
                    ....
        </plugin>
        </plugins>
    </build>
    ....

The Dependencies are mentioned as follows:
    ....
    <dependencies>
          <dependency>
            <groupId>com.sun.enterprise</groupId>
            <artifactId>hk2</artifactId>
            <version>${hk2.version}</version>
          </dependency>
          <dependency>
            <groupId>org.glassfish.common</groupId>
            <artifactId>common-util</artifactId>
            <version>3.0-SNAPSHOT</version>
          </dependency>
      </dependencies>
    ....

Playing with the example:

1. The complete example can be downloaded here.
2. Unzip the module in your favourite directory.
3. cd hello.command
4. mvn clean install
5. copy hello-command/target/hello-command-1.0-SNAPSHOT.jar to Glassfish-v3-installation-dir/modules
6. Start the server.
7. Execute the command : asadmin hello
8. Output: Hello World !!!

I hope it will be useful for the beginners like me.
Cheers !!!

About

Mohit Gupta

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today