Write the Java source file  Deploy Java components

Chapter 11: Creating CORBA Java Components

Advanced techniques

After the basic component implementation is in place, you can add code to perform the following advanced tasks:


Issue intercomponent calls

You must use a proxy to issue intercomponent calls. If you call methods in another Java component directly, no server features are available to the called component, such as transaction control, instance lifecycle management, and security.

Using the CORBA ORB to instantiate proxies

To invoke other components, instantiate a proxy (stub) object for the second component, then use the stub to invoke methods on the component.

To invoke methods in other components, create an ORB instance to obtain proxy objects for other components, then invoke methods on the object references. You obtain object references for other components on the same server by invoking string_to_object with the IOR string specified as Package/Component. For example, the fragment below obtains a proxy object for a component SessionInfo that is installed in the CtsSecurity package.

    java.util.Properties props = new java.util.Properties();
    props.put("org.omg.CORBA.ORBClass",
                    "com.sybase.CORBA.ORB");
    ORB orb = ORB.init((java.lang.String[])null, props);
    SessionInfo sessInfo = 
        SessionInfoHelper.narrow
            (orb.string_to_object(
                "CtsSecurity/SessionInfo")); 

When making intercomponent calls using string_to_object, the user name of the client that executed the component is automatically used for authorization checking. The exception is when instantiating the system components in the Jaguar package: the ORB automatically switches to the system user priveleges when you specify a component in the Jaguar package. To specify a user name, use this syntax:

orb.string_to_object("iiop://0:0:user_name:password/Package/Component"));

You can retrieve the system user name and password with these methods in class com.sybase.CORBA.ORB, which both return strings:

When called from components, string_to_object returns an instance running on the same server if the component is locally installed; otherwise, it attempts to resolve a remote instance using the naming server.

Connecting to third-party CORBA servers

Your component may need to invoke methods on a component hosted by another vendor’s CORBA server-side ORB. Sybase recommends that Java components use the EAServer client-side ORB for all IIOP connections made from EAServer components. See “Connecting to third-party ORBs using the EAServer client ORB” for more information.


Manage database connections

If your Java methods connect to remote data servers, you should use EAServer’s connection caching feature to improve performance. See Chapter 26, “Using Connection Management” for more information.

NoteEAServer’s transactional model works only with connections obtained from the EAServer Connection Manager. Connections that you open yourself will not be able to participate in EAServer transactions.


Return result sets

Using the JDBC API, a Java component can retrieve result sets from a database. Using classes in the com.sybase.jaguar.sql package, Java components can also send these result sets to the caller. A Java component can combine the data from several result sets retrieved from databases and send that data as a single result set to a Java client. A Java component can also forward the original result set retrieved from a database.

To learn how to return result sets, see “Sending result sets with Java”.


Access SSL client certificates

Clients can connect to a secure IIOP port using an SSL client certificate. You can issue intercomponent calls to the built-in CtsSecurity/SessionInfo component to retrieve the client certificate data, including:

This component implements CtsSecurity::SessionInfo IDL interface. HTML documentation is available for the interface in the html/ir subdirectory of your EAServer installation. You can view it by loading the main EAServer HTML page, then clicking the “Interface Repository” link.

NoteThe CtsSecurity::UserCredentials interface is deprecated The CtsSecurity::UserCredentials interface, which is implemented by the CtsSecurity/UserCredentials component, has been replaced by the CtsSecurity::SessionInfo interface, which provides additional functionality such as certificate parsing. EAServer supports the CtsSecurity::UserCredentials interface for backwards compatibility. Please use the interface CtsSecurity::SessionInfo if developing new components.


Set transactional state

The transactional state of a component instance determines whether a transactional component’s database updates are committed or rolled back.

In components that use the CtsComponents::ObjectControl control interface, each instance receives a CtsComponents::ObjectContext object each time that EAServer calls the setObjectContext method. The object reference is valid until unsetObjectContext is called. For more information on these methods, see the generated HTML documentation in the html/ir directory of your EAServer installation.

In classes that do not implement a control interface, call Jaguar.getInstanceContext() in each method that sets transactional state (do not save the object across method invocations, because it will not be valid if the component instance has been deactivated and reactivated). See the EAServer API Reference Manual for information on this method.

To set transaction state, choose the method that reflects the state of the work that the component is contributing to the transaction, as follows:

NoteTransaction control with the ServerBean control interface If you use the deprecated control interface JaguarEJB::ServerBean and Auto demarcation/deactivation option is disabled in the Transactions tab in the Transactions properties for your component, the transaction state specified in the method determines whether the instance is deactivated or remains bound to the client.


Retrieve user-defined component properties

You can add user defined properties for your components using the Advanced tab in the EAServer Manager Component Properties Dialog box. To access these properties at run time, use the Jaguar::Repository API as shown in the example below. For details on this API, see the generated reference documentation in the html/ir subdirectory of your installation. The function below returns an array of Jaguar::Property instances that contain the properties defined for the currently executing component:

public static Property[] getMyComponentProps() { 
    Repository theRep; 
    Property[] myProps; 
    try { 
        java.util.Properties orbProps = new java.util.Properties(); 
        orbProps.put("org.omg.CORBA.ORBClass", 
                 "com.sybase.CORBA.ORB"); 
        ORB theOrb = ORB.init((java.lang.String[])null, orbProps); 
        theRep = RepositoryHelper.narrow 
           (theOrb.string_to_object("Jaguar/Repository")); 
    } catch (Exception e) { 
        System.out.println("Exception instantiating Repository component:" 
                           + "\n" + e); 
        return null; 
    } 
    try { 
        String myPackage = JContext.getPackageName(); 
        String myComponent = myPackage + "/" + JContext.getComponentName(); 
        myProps = theRep.lookup("Component", myComponent); 
    } catch (Exception e) { 
        System.out.println("Exception getting component properties:" 
                           + "\n" + e); 
        return null; 
    }   
    return myProps;       
}

You can also retrieve user-defined properties with the CtsComponents::ObjectContext interface. To obtain a class instance, call the Orb.string_to_object method, passing the string “CtsComponents/ObjectContext”. For details on the interface methods, see the generated reference documentation in the html/ir subdirectory of your installation.





Copyright © 2005. Sybase Inc. All rights reserved. Deploy Java components