LibraryLink ToToggle FramesPrintFeedback

Writing Your Application

The FUSE Services Framework JCA Connector connection management API is packaged in org.apache.cxf.jca.outbound and consists of two interfaces:

The API is packaged in InstallDir/modules/integration/cxf-integration-jca-Version-fuse.jar.

The CXFConnectionFactory interface provides the methods to create a CXFConnection object that represents a Web service defined by the supplied parameters. It is the type returned from an environment naming context lookup of the FUSE Services Framework JCA Connector by a J2EE component and is the entry point to gaining access to a Web service.

The CXFConnection interface provides a handle to a connection managed by the J2EE application server. It is the super interface of the Web service proxy returned by the CXFConnectionFactory interface.

To use the CXFConnectionFactory your application needs to:

  1. Look up a CXFConnectionFactory object in the application server's JNDI registry.

  2. Use the CXFConnectionFactory.getConnection() method to get a CXFConnection object.

    The CXFConnectionFactory.getConnection() method takes one parameter, a CXFConnectionSpec object, which the has following fields:

  3. Use the CXFConnection.getService() method to obtain a Web service client.

  4. Close the CXFConnection object.

  5. Invoke on the service.

    The Web service client can still be used after the CXFConnection object is closed.

The code shown in Example 3.1 shows how to use the FUSE Services Framework JCA Connector connection management API.

Example 3.1. HelloWorldServlet—Outbound Connections

1Context ctx = new InitialContext();
CXFConnectionFactory factory = (CXFConnectionFactory)ctx.lookup(EIS_JNDI_NAME);

2CXFConnectionSpec spec = new CXFConnectionSpec();
    spec.setServiceClass(Greeter.class);
    spec.setServiceName(new QName("http://apache.org/hello_world_soap_http", "SOAPService"));
    spec.setEndpointName(new QName("http://apache.org/hello_world_soap_http", "SoapPort"));
    spec.setWsdlURL(getClass().getResource("/wsdl/hello_world.wsdl"));
    CXFConnection connection = null;
    try {
          connection = getConnection(spec);
           
          3Greeter greeter = connection.getService(Greeter.class);
          
          4connection.close();
          
          5greeter.sayHi();
...      
         }

The code shown in Example 3.1 does the following:

1

Retrieves the connection factory from JNDI.

2

Creates the connection and uses a CXFConnectionSpec object to specify:

  • The service class.

  • A QName that identifies which service in the WSDL file to use.

  • A QName that identifies which port in the WSDL file to use

  • The WSDL file URL.

3

Obtains a Web service client.

4

Closes the connection to the service and return to the application server connection pool.

Remember you can close the connection and continue using the client.

5

Invokes methods on the service.

The outbound samples show how you can use message contexts.

For more information on message contexts, see Working with Contexts in Developing Applications Using JAX-WS.