use of java.rmi.NoSuchObjectException in project wildfly by wildfly.
the class IIOPNamingTestCase method testStatefulIIOPNamingIIOPInvocation.
@Test
@Ignore("Cosnaming does not support iiop:// in OpenJDK")
public void testStatefulIIOPNamingIIOPInvocation() throws NamingException, RemoteException, RemoveException {
final Properties prope = new Properties();
prope.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
prope.put(Context.PROVIDER_URL, "iiop://" + managementClient.getMgmtAddress() + ":3528");
final InitialContext context = new InitialContext(prope);
final Object iiopObj = context.lookup("IIOPStatefulNamingBean");
final IIOPStatefulNamingHome object = (IIOPStatefulNamingHome) PortableRemoteObject.narrow(iiopObj, IIOPStatefulNamingHome.class);
final IIOPStatefulRemote result = object.create(10);
Assert.assertEquals(11, result.increment());
Assert.assertEquals(12, result.increment());
result.remove();
try {
result.increment();
Assert.fail("Expected NoSuchObjectException");
} catch (NoSuchObjectException expected) {
}
}
use of java.rmi.NoSuchObjectException in project jdk8u_jdk by JetBrains.
the class RMIConnector method close.
// allows to do close after setting the flag "terminated" to true.
// It is necessary to avoid a deadlock, see 6296324
private synchronized void close(boolean intern) throws IOException {
final boolean tracing = logger.traceOn();
final boolean debug = logger.debugOn();
final String idstr = (tracing ? "[" + this.toString() + "]" : null);
if (!intern) {
//
if (terminated) {
if (closeException == null) {
if (tracing)
logger.trace("close", idstr + " already closed.");
return;
}
} else {
terminated = true;
}
}
if (closeException != null && tracing) {
//
if (tracing) {
logger.trace("close", idstr + " had failed: " + closeException);
logger.trace("close", idstr + " attempting to close again.");
}
}
String savedConnectionId = null;
if (connected) {
savedConnectionId = connectionId;
}
closeException = null;
if (tracing)
logger.trace("close", idstr + " closing.");
if (communicatorAdmin != null) {
communicatorAdmin.terminate();
}
if (rmiNotifClient != null) {
try {
rmiNotifClient.terminate();
if (tracing)
logger.trace("close", idstr + " RMI Notification client terminated.");
} catch (RuntimeException x) {
closeException = x;
if (tracing)
logger.trace("close", idstr + " Failed to terminate RMI Notification client: " + x);
if (debug)
logger.debug("close", x);
}
}
if (connection != null) {
try {
connection.close();
if (tracing)
logger.trace("close", idstr + " closed.");
} catch (NoSuchObjectException nse) {
// OK, the server maybe closed itself.
} catch (IOException e) {
closeException = e;
if (tracing)
logger.trace("close", idstr + " Failed to close RMIServer: " + e);
if (debug)
logger.debug("close", e);
}
}
// Clean up MBeanServerConnection table
//
rmbscMap.clear();
if (savedConnectionId != null) {
Notification closedNotif = new JMXConnectionNotification(JMXConnectionNotification.CLOSED, this, savedConnectionId, clientNotifSeqNo++, "Client has been closed", null);
sendNotification(closedNotif);
}
//
if (closeException != null) {
if (tracing)
logger.trace("close", idstr + " failed to close: " + closeException);
if (closeException instanceof IOException)
throw (IOException) closeException;
if (closeException instanceof RuntimeException)
throw (RuntimeException) closeException;
final IOException x = new IOException("Failed to close: " + closeException);
throw EnvHelp.initCause(x, closeException);
}
}
use of java.rmi.NoSuchObjectException in project jdk8u_jdk by JetBrains.
the class IdempotentActiveGroup method main.
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4720528\n");
TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
RMID rmid = null;
ActivationInstantiator inst1 = null;
ActivationInstantiator inst2 = null;
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid.start();
System.err.println("Create group descriptor");
ActivationGroupDesc groupDesc = new ActivationGroupDesc(null, null);
ActivationSystem system = ActivationGroup.getSystem();
System.err.println("Register group descriptor");
ActivationGroupID groupID = system.registerGroup(groupDesc);
inst1 = new FakeInstantiator();
inst2 = new FakeInstantiator();
System.err.println("Invoke activeGroup with inst1");
system.activeGroup(groupID, inst1, 0);
try {
System.err.println("Invoke activeGroup with inst2");
system.activeGroup(groupID, inst2, 0);
throw new RuntimeException("TEST FAILED: activeGroup with unequal groups succeeded!");
} catch (ActivationException expected) {
System.err.println("Caught expected ActivationException");
System.err.println("Test 1 (of 2) passed");
}
try {
System.err.println("Invoke activeGroup with inst1");
system.activeGroup(groupID, inst1, 0);
System.err.println("activeGroup call succeeded");
System.err.println("Test 2 (of 2) passed");
} catch (ActivationException unexpected) {
throw new RuntimeException("TEST FAILED: activeGroup with equal groups failed!", unexpected);
}
} catch (Exception e) {
TestLibrary.bomb("test failed", e);
} finally {
try {
if (inst1 != null) {
UnicastRemoteObject.unexportObject(inst1, true);
}
if (inst2 != null) {
UnicastRemoteObject.unexportObject(inst2, true);
}
} catch (NoSuchObjectException unexpected) {
throw new AssertionError(unexpected);
}
ActivationLibrary.rmidCleanup(rmid);
}
}
use of java.rmi.NoSuchObjectException in project jdk8u_jdk by JetBrains.
the class Transport method serviceCall.
/**
* Service an incoming remote call. When a message arrives on the
* connection indicating the beginning of a remote call, the
* threads are required to call the <I>serviceCall</I> method of
* their transport. The default implementation of this method
* locates and calls the dispatcher object. Ordinarily a
* transport implementation will not need to override this method.
* At the entry to <I>tr.serviceCall(conn)</I>, the connection's
* input stream is positioned at the start of the incoming
* message. The <I>serviceCall</I> method processes the incoming
* remote invocation and sends the result on the connection's
* output stream. If it returns "true", then the remote
* invocation was processed without error and the transport can
* cache the connection. If it returns "false", a protocol error
* occurred during the call, and the transport should destroy the
* connection.
*/
public boolean serviceCall(final RemoteCall call) {
try {
/* read object id */
final Remote impl;
ObjID id;
try {
id = ObjID.read(call.getInputStream());
} catch (java.io.IOException e) {
throw new MarshalException("unable to read objID", e);
}
/* get the remote object */
Transport transport = id.equals(dgcID) ? null : this;
Target target = ObjectTable.getTarget(new ObjectEndpoint(id, transport));
if (target == null || (impl = target.getImpl()) == null) {
throw new NoSuchObjectException("no such object in table");
}
final Dispatcher disp = target.getDispatcher();
target.incrementCallCount();
try {
/* call the dispatcher */
transportLog.log(Log.VERBOSE, "call dispatcher");
final AccessControlContext acc = target.getAccessControlContext();
ClassLoader ccl = target.getContextClassLoader();
ClassLoader savedCcl = Thread.currentThread().getContextClassLoader();
try {
setContextClassLoader(ccl);
currentTransport.set(this);
try {
java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
checkAcceptPermission(acc);
disp.dispatch(impl, call);
return null;
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
} finally {
setContextClassLoader(savedCcl);
currentTransport.set(null);
}
} catch (IOException ex) {
transportLog.log(Log.BRIEF, "exception thrown by dispatcher: ", ex);
return false;
} finally {
target.decrementCallCount();
}
} catch (RemoteException e) {
// if calls are being logged, write out exception
if (UnicastServerRef.callLog.isLoggable(Log.BRIEF)) {
// include client host name if possible
String clientHost = "";
try {
clientHost = "[" + RemoteServer.getClientHost() + "] ";
} catch (ServerNotActiveException ex) {
}
String message = clientHost + "exception: ";
UnicastServerRef.callLog.log(Log.BRIEF, message, e);
}
/* We will get a RemoteException if either a) the objID is
* not readable, b) the target is not in the object table, or
* c) the object is in the midst of being unexported (note:
* NoSuchObjectException is thrown by the incrementCallCount
* method if the object is being unexported). Here it is
* relatively safe to marshal an exception to the client
* since the client will not have seen a return value yet.
*/
try {
ObjectOutput out = call.getResultStream(false);
UnicastServerRef.clearStackTraces(e);
out.writeObject(e);
call.releaseOutputStream();
} catch (IOException ie) {
transportLog.log(Log.BRIEF, "exception thrown marshalling exception: ", ie);
return false;
}
}
return true;
}
use of java.rmi.NoSuchObjectException in project tomee by apache.
the class EntityContainer method ejbLoad_If_No_Transaction.
public void ejbLoad_If_No_Transaction(final ThreadContext callContext, final EntityBean bean) throws Exception {
final Operation orginalOperation = callContext.getCurrentOperation();
if (orginalOperation == Operation.BUSINESS || orginalOperation == Operation.REMOVE) {
final TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
return;
}
final BeanContext beanContext = callContext.getBeanContext();
final TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
try {
// double check we don't have an active transaction
if (!txPolicy.isTransactionActive()) {
callContext.setCurrentOperation(Operation.LOAD);
bean.ejbLoad();
}
} catch (final NoSuchEntityException e) {
instanceManager.discardInstance(callContext, bean);
throw new ApplicationException(new NoSuchObjectException("Entity not found: " + callContext.getPrimaryKey()));
} catch (final Exception e) {
instanceManager.discardInstance(callContext, bean);
throw e;
} finally {
callContext.setCurrentOperation(orginalOperation);
txPolicy.commit();
}
}
}
Aggregations