use of java.rmi.MarshalException in project jdk8u_jdk by JetBrains.
the class UnicastRef method newCall.
/**
* Create an appropriate call object for a new call on this object.
* Passing operation array and index, allows the stubs generator to
* assign the operation indexes and interpret them. The RemoteRef
* may need the operation to encode in for the call.
*/
public RemoteCall newCall(RemoteObject obj, Operation[] ops, int opnum, long hash) throws RemoteException {
clientRefLog.log(Log.BRIEF, "get connection");
Connection conn = ref.getChannel().newConnection();
try {
clientRefLog.log(Log.VERBOSE, "create call context");
/* log information about the outgoing call */
if (clientCallLog.isLoggable(Log.VERBOSE)) {
logClientCall(obj, ops[opnum]);
}
RemoteCall call = new StreamRemoteCall(conn, ref.getObjID(), opnum, hash);
try {
marshalCustomCallData(call.getOutputStream());
} catch (IOException e) {
throw new MarshalException("error marshaling " + "custom call data");
}
return call;
} catch (RemoteException e) {
ref.getChannel().free(conn, false);
throw e;
}
}
use of java.rmi.MarshalException 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.MarshalException in project jdk8u_jdk by JetBrains.
the class HandshakeFailure method main.
public static void main(String[] args) throws Exception {
/*
* Listen on port...
*/
ServerSocket serverSocket = new ServerSocket(PORT);
/*
* (Attempt RMI call to port in separate thread.)
*/
Registry registry = LocateRegistry.getRegistry(PORT);
Connector connector = new Connector(registry);
Thread t = new Thread(connector);
t.setDaemon(true);
t.start();
/*
* ...accept one connection from port and send non-JRMP data.
*/
Socket socket = serverSocket.accept();
socket.getOutputStream().write("Wrong way".getBytes());
socket.close();
/*
* Wait for call attempt to finish, and analyze result.
*/
t.join(TIMEOUT);
synchronized (connector) {
if (connector.success) {
throw new RuntimeException("TEST FAILED: remote call succeeded??");
}
if (connector.exception == null) {
throw new RuntimeException("TEST FAILED: remote call did not time out");
} else {
System.err.println("remote call failed with exception:");
connector.exception.printStackTrace();
System.err.println();
if (connector.exception instanceof MarshalException) {
System.err.println("TEST FAILED: MarshalException thrown, expecting " + "java.rmi.ConnectException or ConnectIOException");
} else if (connector.exception instanceof ConnectException || connector.exception instanceof ConnectIOException) {
System.err.println("TEST PASSED: java.rmi.ConnectException or " + "ConnectIOException thrown");
} else {
throw new RuntimeException("TEST FAILED: unexpected Exception thrown", connector.exception);
}
}
}
}
use of java.rmi.MarshalException in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testAddThrowsAdviceWithoutAdvisor.
@Test
public void testAddThrowsAdviceWithoutAdvisor() throws Throwable {
// Reacts to ServletException and RemoteException
MyThrowsHandler th = new MyThrowsHandler();
Echo target = new Echo();
target.setA(16);
ProxyFactory pf = new ProxyFactory(target);
pf.addAdvice(new NopInterceptor());
pf.addAdvice(th);
IEcho proxied = (IEcho) createProxy(pf);
assertThat(th.getCalls()).isEqualTo(0);
assertThat(proxied.getA()).isEqualTo(target.getA());
assertThat(th.getCalls()).isEqualTo(0);
Exception ex = new Exception();
// Will be advised but doesn't match
assertThatExceptionOfType(Exception.class).isThrownBy(() -> proxied.echoException(1, ex)).matches(ex::equals);
// Subclass of RemoteException
MarshalException mex = new MarshalException("");
assertThatExceptionOfType(MarshalException.class).isThrownBy(() -> proxied.echoException(1, mex)).matches(mex::equals);
assertThat(th.getCalls("remoteException")).isEqualTo(1);
}
Aggregations