/** * @param object * @throws ClassNotFoundException * @throws IOException */ private void open(Object object) throws IOException, ClassNotFoundException { if (MarshalledObject.class.isAssignableFrom(object.getClass())) { MarshalledObject marshalledObj = (MarshalledObject) object; this.open(marshalledObj.get()); // recursive call } else if (I_EncodeBusinessProcess.class.isAssignableFrom(object.getClass())) { I_EncodeBusinessProcess process = (I_EncodeBusinessProcess) object; try { ProcessPanel panel = new ProcessPanel(process, null, doubleClickHandler); new FrameWithOpenFramesListener( "Attached Process: " + process.getName(), "Attachment", new JScrollPane(panel)); } catch (Exception e) { e.printStackTrace(); } } else { JEditorPane textPane = new JEditorPane(); textPane.setText(object.toString()); textPane.setEditable(false); try { new FrameWithOpenFramesListener( "Attached Object: " + process.getName(), "Attachment", new JScrollPane(textPane)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
/** * Activate the object for this id. * * @param force if true, forces the activator to contact the group when activating the object * (instead of returning a cached reference); if false, returning a cached value is * acceptable. * @return the reference to the active remote object * @exception ActivationException if activation fails * @exception UnknownObjectException if the object is unknown * @exception RemoteException if remote call fails * @since 1.2 */ public Remote activate(boolean force) throws ActivationException, UnknownObjectException, RemoteException { try { MarshalledObject<? extends Remote> mobj = activator.activate(this, force); return mobj.get(); } catch (RemoteException e) { throw e; } catch (IOException e) { throw new UnmarshalException("activation failed", e); } catch (ClassNotFoundException e) { throw new UnmarshalException("activation failed", e); } }
public ServiceBeanInstantiator[] getServiceBeanInstantiators() throws IOException { Collection<ServiceBeanInstantiator> serviceBeanInstantiators = new ArrayList<ServiceBeanInstantiator>(); try { for (MarshalledObject<ServiceBeanInstantiator> marshalledObject : getWrappedServiceBeanInstantiators()) { serviceBeanInstantiators.add(marshalledObject.get()); } } catch (ClassNotFoundException e) { throw new IOException("Unwrapping a Cybernode", e); } return serviceBeanInstantiators.toArray( new ServiceBeanInstantiator[serviceBeanInstantiators.size()]); }
/** * Return the Remote reference. Deserialize the object if we don't already have an actual * reference in hand. * * @exception java.rmi.RemoteException Problems re-establishing connection with remote object */ public Object get() throws RemoteException { try { if (obj == null) obj = bytes.get(); return obj; } catch (RemoteException e) { if (DEBUG) System.out.println("*****StorableObject:get:" + e.getMessage()); throw e; } catch (IOException e) { fatalError("can't decode object", e); } catch (ClassNotFoundException e) { fatalError("can't decode object", e); } fatalError("how did we get here?", null); return null; // not reached, but compiler doesn't know }
public RestartCrashedService(ActivationID id, MarshalledObject mobj) throws ActivationException, RemoteException { this.id = id; Activatable.exportObject(this, id, 0); ActivateMe obj; String responder; try { Object[] stuff = (Object[]) mobj.get(); responder = (String) stuff[0]; System.err.println(responder + " service started"); obj = (ActivateMe) stuff[1]; } catch (Exception e) { System.err.println("unable to obtain stub from marshalled object"); return; } obj.ping(responder); }
public void testEntityBeanCMP() throws Exception { Context ctx = new InitialContext(); getLog().debug("testEntityBeanCMP"); getLog().debug(++test + "- " + "Looking up the home nextgen.EnterpriseEntity...ok"); EnterpriseEntityHome enterpriseEntityHome = (EnterpriseEntityHome) ctx.lookup("nextgen.EnterpriseEntity"); getLog().debug(++test + "- " + "Calling find on EnterpriseEntityHome with name Marc..."); EnterpriseEntity enterpriseEntity = null; try { enterpriseEntity = enterpriseEntityHome.findByPrimaryKey("Marc"); } catch (Exception e) { getLog().debug("findByPrimaryKey(Marc) failed", e); } if (enterpriseEntity == null) { getLog().debug("not found OK"); getLog().debug(++test + "- " + "Calling create on EnterpriseEntityHome with name Marc..."); enterpriseEntity = enterpriseEntityHome.create("Marc"); } if (enterpriseEntity != null) getLog() .debug( "ok, enterpriseEntity" + enterpriseEntity + ", hashCode=" + enterpriseEntity.hashCode()); getLog().debug(++test + "- " + "Calling for duplicate create and DuplicateKeyException..."); try { Object e = enterpriseEntityHome.create("Marc"); getLog().debug("I Really should not make it here, e=" + e + ", hashCode=" + e.hashCode()); throw new Exception("DuplicateKey not seen"); } catch (DuplicateKeyException dke) { getLog().debug("DuplicateKeyException ok"); } getLog().debug(++test + "- " + "Calling getEJBHome() on EntityCMP..."); assertTrue("enterpriseEntity.getEJBHome() != null", enterpriseEntity.getEJBHome() != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Getting a new reference with findByPK..."); EnterpriseEntity enterpriseEntity2 = null; try { enterpriseEntity2 = enterpriseEntityHome.findByPrimaryKey("Marc"); } catch (Exception re) { getLog().debug("Exception: ", re); } assertTrue("enterpriseEntity2 != null", enterpriseEntity2 != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling Business Method A on enterpriseEntity... "); getLog().debug(enterpriseEntity.callBusinessMethodA()); getLog() .debug( ++test + "- " + "Calling Business Method A (again to ejbLoad if TypeC) on enterpriseEntity... "); getLog().debug(enterpriseEntity.callBusinessMethodA()); getLog() .debug( ++test + "- " + "Calling Business Method B (EJBObject from entity) on enterpriseEntity..."); getLog().debug(enterpriseEntity.callBusinessMethodB()); getLog().debug(++test + "- " + "Calling Business Method B(String) on EnterpriseEntity... "); getLog().debug(enterpriseEntity.callBusinessMethodB("of wisdom")); getLog().debug(++test + "- " + "Calling getOtherField (non pk) on enterpriseEntity..."); getLog().debug("value: " + enterpriseEntity.getOtherField()); getLog().debug(++test + "- " + "Calling setOtherField(4) on enterpriseEntity..."); enterpriseEntity.setOtherField(4); getLog().debug("OK"); getLog().debug(++test + "- " + "Calling getOtherField() on enterpriseEntity (should be 4)..."); int value = enterpriseEntity.getOtherField(); assertTrue("enterpriseEntity.getOtherField() == 4", value == 4); getLog().debug("value is " + value + ", OK"); getLog().debug("***Testing the various local Object class calls"); getLog().debug(++test + "- " + "toString ... " + enterpriseEntity); getLog().debug(++test + "- " + "hashCode ... " + enterpriseEntity.hashCode()); getLog() .debug( ++test + "- " + "equals (same object) ... " + enterpriseEntity.equals(enterpriseEntity)); getLog() .debug( ++test + "- " + "equals (another object) (true for this case)... " + enterpriseEntity.equals(enterpriseEntity2)); getLog().debug("***Testing the various local EJBObject class calls"); getLog().debug(++test + "- " + "Get Primary Key ... " + enterpriseEntity.getPrimaryKey()); getLog().debug(++test + "- " + "Get Handle ... "); Handle entityHandle = enterpriseEntity.getHandle(); assertTrue("entityHandle != null", entityHandle != null); getLog().debug("OK"); getLog().debug(++test + "- " + "Serialize handle and deserialize...."); MarshalledObject mo3 = new MarshalledObject(entityHandle); Handle entityHandle3 = (Handle) mo3.get(); EnterpriseEntity enterpriseEntity3 = (EnterpriseEntity) entityHandle3.getEJBObject(); if (enterpriseEntity3 != null) getLog().debug("OK"); getLog().debug(++test + "- " + "Calling businessMethodA on it..."); getLog().debug(enterpriseEntity3.callBusinessMethodB()); getLog() .debug( ++test + "- " + "They should be identical..." + enterpriseEntity.isIdentical(enterpriseEntity3)); getLog().debug(++test + "- " + "Calling entityHome.remove(Handle)..."); enterpriseEntityHome.remove(enterpriseEntity3.getHandle()); getLog().debug("OK"); getLog().debug(++test + "- " + "Calling enterpriseEntity.remove() (should fail)..."); try { enterpriseEntity.remove(); fail("enterpriseEntity.remove() did not fail"); } catch (Exception e) { getLog().debug("OK"); } getLog().debug(++test + "- " + "Calling EnterpriseEntity.create() for marc6..."); EnterpriseEntity marc6 = enterpriseEntityHome.create("marc6"); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling method createEntity on enterpriseEntity... "); EnterpriseEntity marc2 = marc6.createEntity("marc2"); getLog().debug("OK"); getLog().debug(++test + "- " + "removing by PK on home (marc2)..."); enterpriseEntityHome.remove(marc2.getPrimaryKey()); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling enterpriseEntity.remove() (marc6)..."); marc6.remove(); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling EnterpriseEntity.create<METHOD>() for marc7..."); EnterpriseEntity marc7 = enterpriseEntityHome.createMETHOD("marc7"); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling enterpriseEntity.remove() (marc7)..."); marc7.remove(); getLog().debug("ok"); getLog().debug(""); getLog().debug(""); getLog().debug(""); }
public void testStatefulBean() throws Exception { Context ctx = new InitialContext(); getLog().debug(""); getLog().debug("Test Stateful Bean"); getLog().debug("=================="); getLog().debug(""); getLog().debug(++test + "- " + "Looking up the home nextgen.StatefulSession..."); StatefulSessionHome statefulSessionHome = (StatefulSessionHome) ctx.lookup("nextgen.StatefulSession"); assertTrue("statefulSessionHome!= null", statefulSessionHome != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling create on StatefulSessionHome with name Marc..."); StatefulSession statefulSession = statefulSessionHome.create("Marc"); assertTrue("statefulSession != null", statefulSession != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling getEJBHome() on StatefulSession..."); assertTrue("statefulSession.getEJBHome() != null", statefulSession.getEJBHome() != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling Business Method A on StatefulSession... "); getLog().debug(statefulSession.callBusinessMethodA()); getLog().debug(++test + "- " + "Calling Business Method A (state) on StatefulSession... "); getLog().debug(statefulSession.callBusinessMethodA()); getLog().debug(++test + "- " + "Calling Business Method B (EJBObject) on StatefulSession... "); getLog().debug(statefulSession.callBusinessMethodB()); getLog().debug(++test + "- " + "Calling Business Method B(String) on StatefulSession... "); getLog().debug(statefulSession.callBusinessMethodB("of wisdom")); getLog().debug("***Testing the various local Object class calls"); getLog().debug(++test + "- " + "toString ... "); getLog().debug(statefulSession.toString()); getLog().debug(++test + "- " + "hashCode ... " + statefulSession.hashCode()); getLog() .debug( ++test + "- " + "equals (same object) ... " + statefulSession.equals(statefulSession)); getLog() .debug( ++test + "- " + "equals (another object) (false under same home)... " + statefulSession.equals(statefulSessionHome.create("marc4"))); getLog().debug("***Testing the various local EJBObject class calls"); getLog().debug(++test + "- " + "Get Handle ... "); Handle statefulHandle = statefulSession.getHandle(); assertTrue("statefulHandle != null", statefulHandle != null); getLog().debug("OK"); getLog().debug(++test + "- " + "Serialize handle and deserialize...."); MarshalledObject mo2 = new MarshalledObject(statefulHandle); Handle statefulHandle2 = (Handle) mo2.get(); StatefulSession statefulSession2 = (StatefulSession) statefulHandle2.getEJBObject(); assertTrue("statefulSession2 != null", statefulSession2 != null); getLog().debug("OK"); getLog() .debug( ++test + "- " + "Calling businessMethodB on it..." + statefulSession2.callBusinessMethodB()); getLog() .debug( ++test + "- " + "They should be identical..." + statefulSession.isIdentical(statefulSession2)); getLog().debug(++test + "- " + "Calling StatefulSession.remove()..."); statefulSession.remove(); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling StatefulHome.remove(Handle) (this should fail)..."); try { statefulSessionHome.remove(statefulSession2.getHandle()); fail("statefulSessionHome.remove did not fail"); } catch (Exception e) { getLog().debug("not found OK"); } getLog().debug(++test + "- " + "Creating a 3rd bean and calling it..."); StatefulSession ss3 = statefulSessionHome.create("marc3"); getLog().debug(ss3.callBusinessMethodA()); getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a third bean..."); Handle statefulHandle3 = ss3.getHandle(); statefulSessionHome.remove(statefulHandle3); getLog().debug("OK"); getLog().debug(++test + "- " + "I should not be able to remove it directly..."); try { ss3.remove(); fail("ss3.remove() did not fail"); } catch (Exception e) { getLog().debug("OK"); } getLog().debug(++test + "- " + "Creating a 4th bean using create<METHOD> and calling it..."); StatefulSession ss4 = statefulSessionHome.createMETHOD("marc4", "address"); getLog().debug(ss4.callBusinessMethodA()); getLog().debug(++test + "- " + "Calling StatefulSession.remove(Handle) on a fourth bean..."); Handle statefulHandle4 = ss4.getHandle(); statefulSessionHome.remove(statefulHandle4); }
public void testStatelessBean() throws Exception { getLog().debug(++test + "- " + "Trying the context..."); Context ctx = new InitialContext(); getLog().debug("OK"); /// * getLog().debug(""); getLog().debug("Test Stateless Bean"); getLog().debug("==================="); getLog().debug(""); getLog().debug(++test + "- " + "Looking up the home nextgen.StatelessSession..."); StatelessSessionHome statelessSessionHome = (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession"); if (statelessSessionHome != null) getLog().debug("ok"); getLog().debug(++test + "- " + "Calling create on StatelessSessionHome..."); StatelessSession statelessSession = statelessSessionHome.create(); assertTrue("statelessSessionHome.create() != null", statelessSession != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling getEJBHome() on StatelessSession..."); assertTrue("statelessSession.getEJBHome() != null", statelessSession.getEJBHome() != null); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling Business Method A on StatelessSession... "); statelessSession.callBusinessMethodA(); getLog().debug("ok"); getLog().debug(++test + "- " + "Calling Business Method B on StatelessSession... "); getLog().debug(statelessSession.callBusinessMethodB()); getLog().debug(++test + "- " + "Calling Business Method B(String) on StatelessSession... "); getLog().debug(statelessSession.callBusinessMethodB("of wisdom")); getLog().debug(++test + "- " + "Calling Business Method C on StatelessSession... "); getLog().debug(statelessSession.callBusinessMethodC()); getLog().debug(++test + "- " + "Calling Business Method D on StatelessSession... "); try { statelessSession.callBusinessMethodD(); fail("callBusinessMethodD, no exception was thrown"); } catch (BusinessMethodException e) { getLog().debug("Caught BusinessMethodException OK"); } getLog() .debug(++test + "- " + "Calling Business Method E (getEJBObject) on StatelessSession... "); getLog().debug(statelessSession.callBusinessMethodE()); getLog().debug(++test + "- " + "Calling testClassLoading on StatelessSession... "); statelessSession.testClassLoading(); getLog().debug("OK"); getLog().debug("***Testing the various local Object class calls"); getLog().debug(++test + "- " + "toString ... " + statelessSession.toString()); getLog().debug(++test + "- " + "hashCode ... " + statelessSession.hashCode()); getLog() .debug( ++test + "- " + "equals (same object) ... " + statelessSession.equals(statelessSession)); getLog() .debug( ++test + "- " + "equals (another object) (true under same home)... " + statelessSession.equals(statelessSessionHome.create())); getLog().debug("***Testing the various local EJBObject class calls"); getLog().debug(++test + "- " + "Get Handle ... "); Handle statelessHandle = statelessSession.getHandle(); assertTrue("statelessHandle != null", statelessHandle != null); getLog().debug("OK"); getLog().debug(++test + "- " + "Serialize handle and deserialize.."); MarshalledObject mo = new MarshalledObject(statelessHandle); Handle handle2 = (Handle) mo.get(); StatelessSession statelessSession2 = (StatelessSession) handle2.getEJBObject(); assertTrue("statelessSession2 != null", statelessSession2 != null); getLog().debug("OK"); getLog().debug(++test + "- " + "Calling businessMethodB on it..."); getLog().debug(statelessSession2.callBusinessMethodB()); getLog() .debug( ++test + "- " + "They should be identical..." + statelessSession.isIdentical(statelessSession2)); getLog().debug("***Testing the various local EJBHome class calls"); getLog().debug(++test + "- " + "Getting the metaData..."); EJBMetaData statelessMetaData = statelessSessionHome.getEJBMetaData(); assertTrue("statelessMetaData != null", statelessMetaData != null); getLog().debug("OK"); getLog() .debug(++test + "- " + "Is stateless Session? " + statelessMetaData.isStatelessSession()); getLog() .debug( ++test + "- " + "The remote class is " + statelessMetaData.getRemoteInterfaceClass()); getLog().debug(""); getLog().debug(++test + "- " + "Calling StatelessSession.remove()..."); statelessSession.remove(); getLog().debug("ok"); }
/** * Activatable constructor. This constructor: * * <UL> * <LI>Retrieves an <code>ActivateDesc</code> from the provided <code>data</code> parameter. * <LI>creates a {@link ServiceClassLoader} using the import and export codebases obtained from * the provided <code>ActivateDesc</code>, * <LI>checks the import codebase(s) for the required <code>SharedActivationPolicyPermission * </code> * <LI>associates the newly created {@link ServiceClassLoader} and the corresponding policy file * obtained from the <code>ActivateDesc</code> with the <code>AggregatePolicyProvider</code> * <LI>loads the "wrapped" activatable object's class and calls its activation constructor with * the context classloader set to the newly created {@link ServiceClassLoader}. * <LI>resets the context class loader to the original context classloader * </UL> * * The first instance of this class will also replace the VM's existing <code>Policy</code> * object, if any, with a <code>AggregatePolicyProvider</code>. * * @param id The <code>ActivationID</code> of this object * @param data The activation data for this object * @throws Exception of any errors occur * @see ServiceClassLoader * @see com.sun.jini.start.AggregatePolicyProvider * @see com.sun.jini.start.SharedActivationPolicyPermission * @see java.security.Policy */ public ActivateWrapper(ActivationID id, MarshalledObject data) throws Exception { logger.entering(ActivateWrapper.class.getName(), "ActivateWrapper", new Object[] {id, data}); ActivateDesc desc = (ActivateDesc) data.get(); logger.log(Level.FINEST, "ActivateDesc: {0}", desc); CommonClassLoader commonCL = CommonClassLoader.getInstance(); commonCL.addCommonJARs(desc.commonJARs); if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, "Created CommonClassLoader: {0}", commonCL); ServiceClassLoader cl; try { cl = new ServiceClassLoader( ServiceClassLoader.getURIs(desc.importLocation), new ClassAnnotator(desc.exportLocation), commonCL); if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, "Created ServiceClassLoader: {0}", cl); } catch (Exception e) { logger.throwing(ActivateWrapper.class.getName(), "ActivateWrapper", e); throw e; } checkPolicyPermission(desc.policy, desc.importLocation); synchronized (ActivateWrapper.class) { // supplant global policy 1st time through if (globalPolicy == null) { initialGlobalPolicy = Policy.getPolicy(); globalPolicy = new AggregatePolicyProvider(initialGlobalPolicy); Policy.setPolicy(globalPolicy); logger.log(Level.FINEST, "Global policy set: {0}", globalPolicy); } DynamicPolicyProvider service_policy = new DynamicPolicyProvider(new PolicyFileProvider(desc.policy)); LoaderSplitPolicyProvider split_service_policy = new LoaderSplitPolicyProvider( cl, service_policy, new DynamicPolicyProvider(initialGlobalPolicy)); split_service_policy.grant( this.getClass(), null, /* Principal[] */ new Permission[] {new AllPermission()}); globalPolicy.setPolicy(cl, split_service_policy); logger.log(Level.FINEST, "Added policy to set: {0}", desc.policy); } Thread t = Thread.currentThread(); ClassLoader ccl = t.getContextClassLoader(); logger.log(Level.FINEST, "Saved current context class loader: {0}", ccl); t.setContextClassLoader(cl); logger.log(Level.FINEST, "Set new context class loader: {0}", cl); try { boolean initialize = false; Class ac = Class.forName(desc.className, initialize, cl); logger.log(Level.FINEST, "Obtained implementation class: {0}", ac); Constructor constructor = ac.getDeclaredConstructor(actTypes); logger.log(Level.FINEST, "Obtained implementation constructor: {0}", constructor); constructor.setAccessible(true); impl = constructor.newInstance(id, desc.data); logger.log(Level.FINEST, "Obtained implementation instance: {0}", impl); } finally { t.setContextClassLoader(ccl); logger.log(Level.FINEST, "Context class loader reset to: {0}", ccl); } logger.exiting(ActivateWrapper.class.getName(), "ActivateWrapper"); }