User: reverbel
Date: 01/10/30 13:56:13
Modified: iiop/src/main/org/jboss/ejb/plugins/iiop/server
IIOPContainerInvoker.java
Added: iiop/src/main/org/jboss/ejb/plugins/iiop/server
CodebaseInterceptor.java
CodebaseInterceptorInitializer.java
CodebasePolicy.java CodebasePolicyFactory.java
Log:
Added support for embedding a codebase component into EJBHome/EJBObject IORs.
Revision Changes Path
1.6 +70 -23
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java
Index: IIOPContainerInvoker.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IIOPContainerInvoker.java 2001/08/28 22:07:53 1.5
+++ IIOPContainerInvoker.java 2001/10/30 21:56:13 1.6
@@ -12,12 +12,14 @@
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
+import java.net.URL;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
@@ -29,18 +31,24 @@
import javax.naming.Name;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+import javax.naming.StringRefAddr;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
import javax.rmi.PortableRemoteObject;
-import org.omg.CORBA.ORB;
+import org.omg.CORBA.Any;
import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.ORB;
import org.omg.CORBA.Policy;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.ResponseHandler;
import org.omg.CORBA.portable.UnknownException;
+import org.omg.CORBA.SetOverrideType;
import org.omg.PortableServer.Current;
-//import org.omg.PortableServer.CurrentHelper; // not available in jdk1.4
+import org.omg.PortableServer.CurrentHelper; // not available in jdk1.4
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAPackage.WrongPolicy;
@@ -73,6 +81,7 @@
import org.jboss.iiop.rmi.AttributeAnalysis;
import org.jboss.iiop.rmi.OperationAnalysis;
import org.jboss.iiop.rmi.InterfaceAnalysis;
+import org.jboss.web.WebClassLoader;
/**
* A <code>ContainerInvoker</code> for invoking enterprise beans
@@ -104,11 +113,11 @@
* CORBA reference for the corresponding <code>EJBObject</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class IIOPContainerInvoker
extends Servant
- implements InvokeHandler, ContainerInvoker
+ implements InvokeHandler, ContainerInvoker
{
// Constants --------------------------------------------------------------
@@ -176,9 +185,18 @@
private Current poaCurrent;
/**
+ * The container's <code>CodebasePolicy</code>.
+ */
+ private Policy codebasePolicy;
+
+ /**
* Servant for the container's <code>EJBHome</code>.
*/
private HomeServant ejbHomeServant;
+
+ /**
+ * The container's <code>EJBHome</code>.
+ */
private EJBHome ejbHome;
// Implementation of the interface ContainerPlugin -------------------------
@@ -283,12 +301,42 @@
// The jndi name will be embedded into the EJBHome CORBA reference
jndiName = container.getBeanMetaData().getJndiName();
+ // Create codebasePolicy containing the container's codebase string
+ System.err.println("container classloader: "
+ + container.getClassLoader());
+ System.err.println("container parent classloader: "
+ + container.getClassLoader().getParent());
+ URL[] codebaseURLs = // TODO: get rid of this ugly hack!!!
+ ((WebClassLoader)container.getClassLoader().getParent()).getURLs();
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < codebaseURLs.length; i++) {
+ sb.append(codebaseURLs[i].toString());
+ if (i < codebaseURLs.length - 1) {
+ sb.append(" ");
+ }
+ }
+ Any codebase = orb.create_any();
+ codebase.insert_string(sb.toString());
+ codebasePolicy = orb.create_policy(CodebasePolicy.TYPE, codebase);
+ System.err.println("codebasePolicy: " + codebasePolicy);
+
// Activate ejbHome and get a CORBA reference to it
ejbHomeServant = new HomeServant();
homePOA.activate_object_with_id(jndiName.getBytes(), ejbHomeServant);
- ejbHome = (EJBHome)PortableRemoteObject.narrow(
- homePOA.id_to_reference(jndiName.getBytes()), EJBHome.class);
+ org.omg.CORBA.Object corbaRef =
+ homePOA.id_to_reference(jndiName.getBytes());
+
+ // Add to the ejbHome IOR a component with JAVA_CODEBASE_TAG
+ corbaRef = corbaRef._set_policy_override(
+ new Policy[] { codebasePolicy },
+ SetOverrideType.ADD_OVERRIDE);
+
+ // Just for testing
+ System.err.println("EJBHome reference for " + jndiName + ":");
+ System.err.println(orb.object_to_string(corbaRef));
+ ejbHome = (EJBHome)PortableRemoteObject.narrow(corbaRef, EJBHome.class);
+
// Get a reference for the root POA
POA rootPOA = null;
try {
@@ -300,7 +348,7 @@
// Initialize policies for bean POA
// (policies[0] will be set later on, depending on the kind of bean)
- Policy[] policies = new Policy[5];
+ Policy[] policies = new Policy[6];
policies[1] = rootPOA.create_id_assignment_policy(
IdAssignmentPolicyValue.USER_ID);
policies[2] = rootPOA.create_servant_retention_policy(
@@ -309,6 +357,7 @@
RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
policies[4] = rootPOA.create_id_uniqueness_policy(
IdUniquenessPolicyValue.MULTIPLE_ID);
+ policies[5] = codebasePolicy.copy();
// Set policies[0] and create metadata depending on the kind of bean
if (container.getBeanMetaData() instanceof EntityMetaData) {
@@ -384,12 +433,8 @@
poa.set_servant(this);
// Get the POACurrent object
- // TODO: make this code CORBA-compliant
- // (jdk1.4 still does not have a CurrentHelper class,
- // so I am doing it the unofficial way)
- //poaCurrent = CurrentHelper.narrow(
- // orb.resolve_initial_references("POACurrent"));
- poaCurrent = (Current)orb.resolve_initial_references("POACurrent");
+ poaCurrent = CurrentHelper.narrow(
+ orb.resolve_initial_references("POACurrent"));
}
public void start() throws Exception
@@ -405,14 +450,18 @@
try {
// Bind the bean home in the JNDI initial context
initialContext = new InitialContext();
- rebind(initialContext, jndiName, ejbHome);
+ rebind(initialContext, jndiName, new Reference(
+ "javax.ejb.EJBHome",
+ new StringRefAddr("IOR",
+ orb.object_to_string(
+ (org.omg.CORBA.Object)ejbHome))));
System.err.println("Bound " + container.getBeanMetaData().getEjbName()
+ " to " + jndiName);
}
catch (NamingException e) {
throw new ServerException("Could not bind EJBHome in JNDI", e);
}
-
+
NamingContextExt corbaContext = null;
try {
// Obtain local (in-VM) CORBA naming context
@@ -468,7 +517,7 @@
false /* wait_for_completion */ );
}
catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace(System.err);
}
}
@@ -478,9 +527,6 @@
// Implementation of the interface ContainerInvoker ------------------------
- // TODO: put into the IORs a TAG_JAVA_CODEBASE (25) with
- // container.getClassLoader().getURLs()
-
public EJBMetaData getEJBMetaData()
{
return ejbMetaData;
@@ -591,7 +637,7 @@
id = toObject(poaCurrent.get_object_id());
}
catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace(System.err);
throw new UnknownException(e);
}
@@ -614,6 +660,7 @@
}
}
catch (Exception e) {
+ e.printStackTrace(System.err);
out = (org.omg.CORBA_2_3.portable.OutputStream)
handler.createExceptionReply();
op.writeException(out, e);
@@ -770,9 +817,9 @@
/**
* Receives a byte array previously returned by a call to
- * <code>toByteArray</code> and retrieves an object from it. Used to extract
- * a JBoss oid from the "reference data" (object id) field of a CORBA
- * reference.
+ * <code>toByteArray</code> and retrieves an object from it. Used to
+ * extract a JBoss oid from the "reference data" (object id) field of a
+ * CORBA reference.
*/
protected static Object toObject(byte[] a)
throws IOException, ClassNotFoundException
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CodebaseInterceptor.java
Index: CodebaseInterceptor.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
import org.omg.IOP.TAG_JAVA_CODEBASE;
//import org.omg.CORBA.LocalObject; // JacORB does not have it yet
import org.jacorb.orb.LocalityConstrainedObject; // using this one instead
import org.omg.IOP.TaggedComponent;
import org.omg.PortableInterceptor.IORInfo;
import org.omg.PortableInterceptor.IORInterceptor;
import org.jacorb.orb.CDROutputStream;
/**
* Implements an <code>org.omg.PortableInterceptor.IORInterceptor</code>
* that adds a Java codebase component to an IOR.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
public class CodebaseInterceptor
extends /*LocalObject*/ LocalityConstrainedObject
implements IORInterceptor
{
// org.omg.PortableInterceptor.IORInterceptor operations -------------------
public String name()
{
return CodebaseInterceptor.class.getName();
}
public void destroy()
{
}
public void establish_components(IORInfo info)
{
// Get CodebasePolicy object
CodebasePolicy codebasePolicy=
(CodebasePolicy)info.get_effective_policy(CodebasePolicy.TYPE);
if (codebasePolicy != null) {
// Get codebase string from CodebasePolicy
String codebase = codebasePolicy.getCodebase();
// Encapsulate codebase string into TaggedComponent
CDROutputStream os = new CDROutputStream();
os.write_string(codebase);
info.add_ior_component(new TaggedComponent(TAG_JAVA_CODEBASE.value,
os.getBufferCopy()));
os.close();
}
}
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CodebaseInterceptorInitializer.java
Index: CodebaseInterceptorInitializer.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
//import org.omg.CORBA.LocalObject; // JacORB does not have it yet
import org.jacorb.orb.LocalityConstrainedObject; // using this one instead
import org.omg.PortableInterceptor.ORBInitializer;
import org.omg.PortableInterceptor.ORBInitInfo;
/**
* Implements an <code>org.omg.PortableInterceptor.ORBinitializer</code> that
* installs a <code>CodebaseInterceptor</code> and a
* <code>CodebasePolicyFactory</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
public class CodebaseInterceptorInitializer
extends /*LocalObject*/ LocalityConstrainedObject
implements ORBInitializer
{
public CodebaseInterceptorInitializer()
{
// do nothing
}
// org.omg.PortableInterceptor.ORBInitializer operations -------------------
public void pre_init(ORBInitInfo info)
{
try {
info.add_ior_interceptor(new CodebaseInterceptor());
info.register_policy_factory(CodebasePolicy.TYPE,
new CodebasePolicyFactory());
}
catch (Exception e) {
throw new RuntimeException("Unexpected " + e);
}
}
public void post_init(ORBInitInfo info)
{
// do nothing
}
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CodebasePolicy.java
Index: CodebasePolicy.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
//import org.omg.CORBA.LocalObject; // JacORB does not have it yet
import org.jacorb.orb.LocalityConstrainedObject; // using this one instead
import org.omg.CORBA.Policy;
/**
* Implements <code>org.omg.CORBA.Policy</code> objects containing codebase
* strings.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
class CodebasePolicy
extends /*LocalObject*/ LocalityConstrainedObject
implements Policy
{
// Private -----------------------------------------------------------------
private final String codebase;
// Static -----------------------------------------------------------------
public static final int TYPE = 0x12345678;
// Constructor -------------------------------------------------------------
public CodebasePolicy(String codebase)
{
this.codebase = codebase;
}
/**
* Returns the codebase string contained in this Policy.
*/
public String getCodebase()
{
return codebase;
}
// org.omg.CORBA.Policy operations -----------------------------------------
/**
* Returns a copy of the Policy object.
*/
public Policy copy()
{
return new CodebasePolicy(codebase);
}
/**
* Destroys the Policy object.
*/
public void destroy()
{
}
/**
* Returns the constant value that corresponds to the type of the policy
* object.
*/
public int policy_type()
{
return TYPE;
}
public String toString()
{
return "CodebasePolicy[" + codebase + "]";
}
}
1.1
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/CodebasePolicyFactory.java
Index: CodebasePolicyFactory.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb.plugins.iiop.server;
import org.omg.CORBA.Any;
//import org.omg.CORBA.LocalObject; // JacORB does not have it yet
import org.jacorb.orb.LocalityConstrainedObject; // using this one instead
import org.omg.CORBA.Policy;
import org.omg.CORBA.PolicyError;
import org.omg.PortableInterceptor.PolicyFactory;
/**
* Factory of <code>org.omg.CORBA.Policy</code> objects containing codebase
* strings.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Francisco Reverbel</a>
* @version $Revision: 1.1 $
*/
class CodebasePolicyFactory
extends /*LocalObject*/ LocalityConstrainedObject
implements PolicyFactory
{
public CodebasePolicyFactory()
{
}
// org.omg.PortableInterceptor.PolicyFactory operations --------------------
public Policy create_policy(int type, Any value)
throws PolicyError
{
if (type != CodebasePolicy.TYPE) {
throw new PolicyError();
}
String codebase = value.extract_string();
return new CodebasePolicy(codebase);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development