JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle GlassFish Server 3.1 Application Development Guide
search filter icon
search icon

Document Information

Preface

Part I Development Tasks and Tools

1.  Setting Up a Development Environment

2.  Class Loaders

3.  Debugging Applications

Part II Developing Applications and Application Components

4.  Securing Applications

5.  Developing Web Services

6.  Using the Java Persistence API

7.  Developing Web Applications

8.  Using Enterprise JavaBeans Technology

9.  Using Container-Managed Persistence

10.  Developing Java Clients

Introducing the Application Client Container

ACC Security

ACC Naming

Application Client Annotation

Java Web Start

Application Client JAR File

Developing Clients Using the ACC

To Access an EJB Component From an Application Client

To Access a JMS Resource From an Application Client

Using Java Web Start

Enabling and Disabling Java Web Start

Downloading and Launching an Application Client

The Application Client URL

Signing JAR Files Used in Java Web Start

Error Handling

Vendor Icon, Splash Screen, and Text

Creating a Custom JNLP File

Using the Embeddable ACC

Running an Application Client Using the appclient Script

Using the package-appclient Script

The client.policy File

Using RMI/IIOP Over SSL

Connecting to a Remote EJB Module Through a Firewall

Specifying a Splash Screen

Setting Login Retries

Using Libraries with Application Clients

Developing Clients Without the ACC

To access an EJB component from a stand-alone client

To access an EJB component from a server-side module

To access a JMS resource from a stand-alone client

11.  Developing Connectors

12.  Developing Lifecycle Listeners

13.  Developing OSGi-enabled Java EE Applications

Part III Using Services and APIs

14.  Using the JDBC API for Database Access

15.  Using the Transaction Service

16.  Using the Java Naming and Directory Interface

17.  Using the Java Message Service

18.  Using the JavaMail API

Index

Developing Clients Without the ACC

This section describes the procedure to create, assemble, and deploy a Java-based client that is not packaged using the Application Client Container (ACC).

The following topics are addressed here:

For information about using the ACC, see Developing Clients Using the ACC. For general information about EJB components and clients, see EJB FAQ.

To access an EJB component from a stand-alone client

  1. In your client code, instantiate the InitialContext:
    InitialContext ctx = new InitialContext();

    It is not necessary to explicitly instantiate a naming context that points to the CosNaming service.

  2. In the client code, look up the home object by specifying the JNDI name of the home object.

    Here is an EJB 2.x example:

    Object ref = ctx.lookup("jndi-name");
    BeanAHome = (BeanAHome)PortableRemoteObject.narrow(ref,BeanAHome.class);

    Here is an EJB 3.x example:

    BeanRemoteBusiness bean =(BeanRemoteBusiness) ctx.lookup("com.acme.BeanRemoteBusiness");

    If load balancing is enabled as in Step 6 and the EJB components being accessed are in a different cluster, the endpoint list must be included in the lookup, as follows:

    corbaname:host1:port1,host2:port2,.../NameService#ejb/jndi-name

    For more information about naming and lookups, see Accessing the Naming Context.

  3. Deploy the EJB component to be accessed.

    For more information on deployment, see About Deployment Tools in Oracle GlassFish Server 3.1 Application Deployment Guide.

  4. Copy the as-install/lib/gf-client.jar file to the client machine and include it in the classpath on the client side.

    The gf-client.jar file references GlassFish Server JAR files in its MANIFEST.MF file. If there is no GlassFish Server installation on the client machine, you must also copy the as-install/modules directory to the client machine and maintain its directory structure relative to the as-install/lib/gf-client.jar file. Or you can use the package-appclient script; see Using the package-appclient Script.

  5. To access EJB components that are residing in a remote system, set the following system properties for the Java Virtual Machine startup options:
    -Dorg.omg.CORBA.ORBInitialHost=${ORBhost}
    -Dorg.omg.CORBA.ORBInitialPort=${ORBport}

    Here ORBhost is the Application Server hostname and ORBport is the ORB port number (default is 3700 for the default server instance, named server).

    You can use the asadmin get command to get the IIOP port numbers. For example:

    asadmin get "configs.config.server-config.iiop-service.iiop-listener.orb-listener-1.*"
  6. To set up load balancing and remote EJB reference failover, define the endpoints property as follows:
    -Dcom.sun.appserv.iiop.endpoints=host1:port1,host2:port2,...

    The endpoints property specifies a comma-separated list of one or more IIOP endpoints used for load balancing. An IIOP endpoint is in the form host:port, where the host is an IPv4 address or host name, and the port specifies the port number.

    If the endpoints list is changed dynamically in the code, the new list is used only if a new InitialContext is created.

  7. Run the stand-alone client.

    As long as the client environment is set appropriately and the JVM is compatible, you merely need to run the main class.

To access an EJB component from a server-side module

A server-side module can be a servlet, another EJB component, or another type of module.

  1. In your module code, instantiate the InitialContext:
    InitialContext ctx = new InitialContext();

    It is not necessary to explicitly instantiate a naming context that points to the CosNaming service.

    To set up load balancing and remote EJB reference failover, define the endpoints property as follows:

    Hashtable env = new Hashtable();
    env.put("com.sun.appserv.iiop.endpoints","host1:port1,host2:port2,...");
    InitialContext ctx = new InitialConext(env);

    The endpoints property specifies a comma-separated list of one or more IIOP endpoints used for load balancing. An IIOP endpoint is in the form host:port, where the host is an IPv4 address or host name, and the port specifies the port number.

    You can use the asadmin get command to get the IIOP port numbers. For example:

    asadmin get "configs.config.server-config.iiop-service.iiop-listener.orb-listener-1.*"

    If the endpoints list is changed dynamically in the code, the new list is used only if a new InitialContext is created.

  2. In the module code, look up the home object by specifying the JNDI name of the home object.

    Here is an EJB 2.x example:

    Object ref = ctx.lookup("jndi-name");
    BeanAHome = (BeanAHome)PortableRemoteObject.narrow(ref,BeanAHome.class);

    Here is an EJB 3.x example:

    BeanRemoteBusiness bean =(BeanRemoteBusiness) ctx.lookup("com.acme.BeanRemoteBusiness");

    If load balancing is enabled as in Step 1 and the EJB components being accessed are in a different cluster, the endpoint list must be included in the lookup, as follows:

    corbaname:host1:port1,host2:port2,.../NameService#ejb/jndi-name

    For more information about naming and lookups, see Accessing the Naming Context.

  3. Deploy the EJB component to be accessed.

    For more information on deployment, see About Deployment Tools in Oracle GlassFish Server 3.1 Application Deployment Guide.

  4. To access EJB components that are residing in a remote system, set the following system properties for the Java Virtual Machine startup options:
    -Dorg.omg.CORBA.ORBInitialHost=${ORBhost}
    -Dorg.omg.CORBA.ORBInitialPort=${ORBport}

    Here ORBhost is the Application Server hostname and ORBport is the ORB port number (default is 3700 for the default server instance, named server).

  5. Deploy the module.

    For more information on deployment, see About Deployment Tools in Oracle GlassFish Server 3.1 Application Deployment Guide.

To access a JMS resource from a stand-alone client

  1. Create a JMS client.

    For detailed instructions on developing a JMS client, see Chapter 48, Java Message Service Examples, in The Java EE 6 Tutorial.

  2. Configure a JMS resource on GlassFish Server.

    For information on configuring JMS resources, see Administering JMS Connection Factories and Destinations in Oracle GlassFish Server 3.1 Administration Guide.

  3. Copy the following JAR files to the client machine and include them in the classpath on the client side:
    • gf-client.jar - available at as-install/lib

    • imqjmsra.jar - available at as-install/lib/install/aplications/jmsra

    The gf-client.jar file references GlassFish Server JAR files in its MANIFEST.MF file. If there is no GlassFish Server installation on the client machine, you must also copy the as-install/modules directory to the client machine and maintain its directory structure relative to the as-install/lib/gf-client.jar file. Or you can use the package-appclient script; see Using the package-appclient Script.

  4. To access EJB components that are residing in a remote system, set the following system properties for the Java Virtual Machine startup options:
    -Dorg.omg.CORBA.ORBInitialHost=${ORBhost}
    -Dorg.omg.CORBA.ORBInitialPort=${ORBport}

    Here ORBhost is the Application Server hostname and ORBport is the ORB port number (default is 3700 for the default server instance, named server).

    You can use the asadmin get command to get the IIOP port numbers. For example:

    asadmin get "configs.config.server-config.iiop-service.iiop-listener.orb-listener-1.*"
  5. Run the stand-alone client.

    As long as the client environment is set appropriately and the JVM is compatible, you merely need to run the main class.