FileDocCategorySizeDatePackage
J2EEInitializer.javaAPI DocGlassfish v2 API10933Tue Jun 12 11:02:38 BST 2007com.sun.enterprise.iiop

J2EEInitializer

public class J2EEInitializer extends LocalObject implements ORBInitializer
This file implements an initializer class for all portable interceptors used in the J2EE RI (currently security and transactions). It registers the IOR, client and server request interceptors.
author
Vivek Nagar

Fields Summary
private static Logger
_logger
private static final String
SEC_INTEROP_CLIENTINT_PROP
private static final String
SEC_INTEROP_SERVERINT_PROP
Constructors Summary
public J2EEInitializer()


      
	try {
	    System.setProperty(
			com.sun.jts.pi.InterceptorImpl.CLIENT_POLICY_CHECKING, 
			String.valueOf(false));
	} catch ( Exception ex ) {
		_logger.log(Level.WARNING,"iiop.readproperty_exception",ex);
	}
    
Methods Summary
public voidpost_init(org.omg.PortableInterceptor.ORBInitInfo info)
This method is called during ORB initialization.

param
the info object that provides initialization attributes and operations by which interceptors are registered.

        Codec codec = null;

	if(_logger.isLoggable(Level.FINE)){
		_logger.log(Level.FINE,"J2EE Initializer post_init");
		// Create a Codec that can be passed to interceptors.
		_logger.log(Level.FINE,"Creating Codec for CDR encoding");
	}

        CodecFactory cf = info.codec_factory();
  
        byte major_version = 1;
        byte minor_version = 2;
        Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value, 
                                         major_version, minor_version);
        try {
            codec = cf.create_codec(encoding);

	    // register CSIv2 interceptors.
 	    ClientConnectionInterceptor cci =
                 new ClientConnectionInterceptor("ClientConnInterceptor",1);
            info.add_client_request_interceptor(cci);

            String clientSecInterceptor = System.getProperty(SEC_INTEROP_CLIENTINT_PROP);
            String serverSecInterceptor = System.getProperty(SEC_INTEROP_SERVERINT_PROP);

            ClientRequestInterceptor creq;
            ServerRequestInterceptor sreq;

            if( clientSecInterceptor == null ) {
                creq = new SecClientRequestInterceptor(
                    "SecClientRequestInterceptor", codec);
            }
            else {
                try {
                    Class cInterceptorClass = 
                        Class.forName( clientSecInterceptor );

                    // Find two-parameter constructor:
                    Class[] paramTypes = new Class[2];
                    paramTypes[0] = java.lang.String.class;
                    paramTypes[1] = org.omg.IOP.Codec.class;

                    Object[] params = new Object[2];
                    params[0] = "SecClientRequestInterceptor";
                    params[1] = codec;

                    Constructor constructor = cInterceptorClass.getConstructor( 
                        paramTypes );

                    creq = (ClientRequestInterceptor)
                        constructor.newInstance( params );
                }
                catch( Exception e ) {
		    if (_logger.isLoggable(Level.FINE)) {
			_logger.log(Level.FINE,"Exception registering security client request receptor",e);
			_logger.log(Level.FINE,"Going to register default security client request interceptor");
		    }
                    creq = new SecClientRequestInterceptor(
                        "SecClientRequestInterceptor", codec);
                }
            }

            if( serverSecInterceptor == null ) {
                sreq = new SecServerRequestInterceptor(
                    "SecServerRequestInterceptor", codec);
            }
            else {
                try {
                    Class sInterceptorClass = 
                        Class.forName( serverSecInterceptor );

                    // Try two-parameter form of constructor:
                    Class[] paramTypes = new Class[2];
                    paramTypes[0] = java.lang.String.class;
                    paramTypes[1] = org.omg.IOP.Codec.class;

                    Object[] params = new Object[2];
                    params[0] = "SecServerRequestInterceptor";
                    params[1] = codec;

                    Constructor constructor = sInterceptorClass.getConstructor( 
                        paramTypes );

                    sreq = (ServerRequestInterceptor)
                        constructor.newInstance( params );
                }
                catch( Exception e ) {
		    if (_logger.isLoggable(Level.FINE)) {
			_logger.log(Level.FINE,"Exception registering security server request receptor",e);
			_logger.log(Level.FINE,"Going to register default security server request interceptor");
		    }
                    sreq = new SecServerRequestInterceptor(
                        "SecServerRequestInterceptor", codec);
                }
            }

            info.add_client_request_interceptor(creq);

            ServerConnectionInterceptor sci =
                new ServerConnectionInterceptor(2);
            info.add_server_request_interceptor(sci);
            info.add_server_request_interceptor(sreq);

	    SecurityService ss = new SecurityServiceImpl();
	    Csiv2Manager.setSecurityService(ss);


	    // register JTS interceptors
	    // first get hold of PICurrent to allocate a slot for JTS service.
	    Current pic = (Current)info.resolve_initial_references("PICurrent");

	    // allocate a PICurrent slotId for the transaction service.
	    int[] slotIds = new int[2];
	    slotIds[0] = info.allocate_slot_id();
	    slotIds[1] = info.allocate_slot_id();

	    InterceptorImpl interceptor =
                new InterceptorImpl(pic, codec, slotIds, null);
            info.add_client_request_interceptor(interceptor);
            info.add_server_request_interceptor(interceptor);

        boolean addSFSBInterceptors = false;
        if (Switch.getSwitch().getContainerType() != Switch.APPCLIENT_CONTAINER) {
            addSFSBInterceptors = EJBServerConfigLookup.needToAddSFSBVersionInterceptors();
        }
           
        _logger.log(Level.FINE, "J2EEInitializer: Checking if interceptors need to "
                + " be added");
        if (addSFSBInterceptors) {
            SFSBClientRequestInterceptor sfsbClientInterceptor =
                new SFSBClientRequestInterceptor(codec);
            SFSBServerRequestInterceptor sfsbServerInterceptor =
                new SFSBServerRequestInterceptor(codec);
            info.add_client_request_interceptor(sfsbClientInterceptor);
            info.add_server_request_interceptor(sfsbServerInterceptor);
            _logger.log(Level.FINE, "J2EEInitializer: Added SFSBInterceptors");
        }
        
	    // Get the ORB instance on which this interceptor is being
	    // initialized
	    com.sun.corba.ee.spi.orb.ORB thisORB = ((ORBInitInfoExt)info).getORB();

	    PEORBConfigurator.setJTSInterceptor(interceptor, thisORB);

	    // add IOR Interceptor for CSIv2 and OTS tagged components
	    TxSecIORInterceptor iorInterceptor = new TxSecIORInterceptor(codec);
	    info.add_ior_interceptor(iorInterceptor);

        if (addSFSBInterceptors) {
            info.add_ior_interceptor(new SFSBVersionIORInterceptor(codec));
        }
        
        } catch (Exception e) {
	    if(_logger.isLoggable(Level.FINE)){
		_logger.log(Level.FINE,"Exception registering JTS interceptors",e);
	    }
	    throw new RuntimeException(e.getMessage());
        }
        
    
public voidpre_init(org.omg.PortableInterceptor.ORBInitInfo info)
This method is called during ORB initialization.

param
the info object that provides initialization attributes and operations by which interceptors are registered.