Search in sources :

Example 6 with MarshalException

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;
    }
}
Also used : MarshalException(java.rmi.MarshalException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) Connection(sun.rmi.transport.Connection) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) StreamRemoteCall(sun.rmi.transport.StreamRemoteCall) RemoteCall(java.rmi.server.RemoteCall)

Example 7 with MarshalException

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;
}
Also used : MarshalException(java.rmi.MarshalException) ObjectOutput(java.io.ObjectOutput) Remote(java.rmi.Remote) IOException(java.io.IOException) IOException(java.io.IOException) Dispatcher(sun.rmi.server.Dispatcher) ServerNotActiveException(java.rmi.server.ServerNotActiveException) AccessControlContext(java.security.AccessControlContext) ObjID(java.rmi.server.ObjID) NoSuchObjectException(java.rmi.NoSuchObjectException) RemoteException(java.rmi.RemoteException)

Example 8 with MarshalException

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);
            }
        }
    }
}
Also used : MarshalException(java.rmi.MarshalException) ConnectIOException(java.rmi.ConnectIOException) ServerSocket(java.net.ServerSocket) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ConnectException(java.rmi.ConnectException)

Example 9 with MarshalException

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);
}
Also used : NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor) MarshalException(java.rmi.MarshalException) MyThrowsHandler(org.springframework.aop.testfixture.advice.MyThrowsHandler) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) MarshalException(java.rmi.MarshalException) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) LockedException(test.mixin.LockedException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Aggregations

MarshalException (java.rmi.MarshalException)9 IOException (java.io.IOException)6 RemoteException (java.rmi.RemoteException)4 ObjectOutput (java.io.ObjectOutput)3 ObjectInput (java.io.ObjectInput)2 ServerSocket (java.net.ServerSocket)2 ConnectException (java.rmi.ConnectException)2 ConnectIOException (java.rmi.ConnectIOException)2 UnmarshalException (java.rmi.UnmarshalException)2 LocateRegistry (java.rmi.registry.LocateRegistry)2 Registry (java.rmi.registry.Registry)2 ObjID (java.rmi.server.ObjID)2 RemoteCall (java.rmi.server.RemoteCall)2 ServerNotActiveException (java.rmi.server.ServerNotActiveException)2 Connection (sun.rmi.transport.Connection)2 StreamRemoteCall (sun.rmi.transport.StreamRemoteCall)2 FileNotFoundException (java.io.FileNotFoundException)1 NotSerializableException (java.io.NotSerializableException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1