Search in sources :

Example 1 with ServerError

use of java.rmi.ServerError in project jdk8u_jdk by JetBrains.

the class UnicastServerRef method oldDispatch.

/**
     * Handle server-side dispatch using the RMI 1.1 stub/skeleton
     * protocol, given a non-negative operation number that has
     * already been read from the call stream.
     *
     * @param obj the target remote object for the call
     * @param call the "remote call" from which operation and
     * method arguments can be obtained.
     * @param op the operation number
     * @exception IOException if unable to marshal return result or
     * release input or output streams
     */
public void oldDispatch(Remote obj, RemoteCall call, int op) throws IOException {
    // hash for matching stub with skeleton
    long hash;
    try {
        // read remote call header
        ObjectInput in;
        try {
            in = call.getInputStream();
            try {
                Class<?> clazz = Class.forName("sun.rmi.transport.DGCImpl_Skel");
                if (clazz.isAssignableFrom(skel.getClass())) {
                    ((MarshalInputStream) in).useCodebaseOnly();
                }
            } catch (ClassNotFoundException ignore) {
            }
            hash = in.readLong();
        } catch (Exception readEx) {
            throw new UnmarshalException("error unmarshalling call header", readEx);
        }
        // if calls are being logged, write out object id and operation
        logCall(obj, skel.getOperations()[op]);
        unmarshalCustomCallData(in);
        // dispatch to skeleton for remote object
        skel.dispatch(obj, call, op, hash);
    } catch (Throwable e) {
        logCallException(e);
        ObjectOutput out = call.getResultStream(false);
        if (e instanceof Error) {
            e = new ServerError("Error occurred in server thread", (Error) e);
        } else if (e instanceof RemoteException) {
            e = new ServerException("RemoteException occurred in server thread", (Exception) e);
        }
        if (suppressStackTraces) {
            clearStackTraces(e);
        }
        out.writeObject(e);
    } finally {
        // in case skeleton doesn't
        call.releaseInputStream();
        call.releaseOutputStream();
    }
}
Also used : ServerException(java.rmi.ServerException) ObjectOutput(java.io.ObjectOutput) ServerError(java.rmi.ServerError) ServerError(java.rmi.ServerError) UnmarshalException(java.rmi.UnmarshalException) ServerException(java.rmi.ServerException) ExportException(java.rmi.server.ExportException) SkeletonNotFoundException(java.rmi.server.SkeletonNotFoundException) ServerNotActiveException(java.rmi.server.ServerNotActiveException) MarshalException(java.rmi.MarshalException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) UnmarshalException(java.rmi.UnmarshalException) ObjectInput(java.io.ObjectInput) RemoteException(java.rmi.RemoteException)

Example 2 with ServerError

use of java.rmi.ServerError in project jdk8u_jdk by JetBrains.

the class UnicastServerRef method dispatch.

/**
     * Call to dispatch to the remote object (on the server side).
     * The up-call to the server and the marshalling of return result
     * (or exception) should be handled before returning from this
     * method.
     * @param obj the target remote object for the call
     * @param call the "remote call" from which operation and
     * method arguments can be obtained.
     * @exception IOException If unable to marshal return result or
     * release input or output streams
     */
public void dispatch(Remote obj, RemoteCall call) throws IOException {
    // positive operation number in 1.1 stubs;
    // negative version number in 1.2 stubs and beyond...
    int num;
    long op;
    try {
        // read remote call header
        ObjectInput in;
        try {
            in = call.getInputStream();
            num = in.readInt();
            if (num >= 0) {
                if (skel != null) {
                    oldDispatch(obj, call, num);
                    return;
                } else {
                    throw new UnmarshalException("skeleton class not found but required " + "for client version");
                }
            }
            op = in.readLong();
        } catch (Exception readEx) {
            throw new UnmarshalException("error unmarshalling call header", readEx);
        }
        /*
             * Since only system classes (with null class loaders) will be on
             * the execution stack during parameter unmarshalling for the 1.2
             * stub protocol, tell the MarshalInputStream not to bother trying
             * to resolve classes using its superclasses's default method of
             * consulting the first non-null class loader on the stack.
             */
        MarshalInputStream marshalStream = (MarshalInputStream) in;
        marshalStream.skipDefaultResolveClass();
        Method method = hashToMethod_Map.get(op);
        if (method == null) {
            throw new UnmarshalException("unrecognized method hash: " + "method not supported by remote object");
        }
        // if calls are being logged, write out object id and operation
        logCall(obj, method);
        // unmarshal parameters
        Object[] params = null;
        try {
            unmarshalCustomCallData(in);
            params = unmarshalParameters(obj, method, marshalStream);
        } catch (java.io.IOException e) {
            throw new UnmarshalException("error unmarshalling arguments", e);
        } catch (ClassNotFoundException e) {
            throw new UnmarshalException("error unmarshalling arguments", e);
        } finally {
            call.releaseInputStream();
        }
        // make upcall on remote object
        Object result;
        try {
            result = method.invoke(obj, params);
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
        // marshal return value
        try {
            ObjectOutput out = call.getResultStream(true);
            Class<?> rtype = method.getReturnType();
            if (rtype != void.class) {
                marshalValue(rtype, result, out);
            }
        } catch (IOException ex) {
            throw new MarshalException("error marshalling return", ex);
        /*
                 * This throw is problematic because when it is caught below,
                 * we attempt to marshal it back to the client, but at this
                 * point, a "normal return" has already been indicated,
                 * so marshalling an exception will corrupt the stream.
                 * This was the case with skeletons as well; there is no
                 * immediately obvious solution without a protocol change.
                 */
        }
    } catch (Throwable e) {
        logCallException(e);
        ObjectOutput out = call.getResultStream(false);
        if (e instanceof Error) {
            e = new ServerError("Error occurred in server thread", (Error) e);
        } else if (e instanceof RemoteException) {
            e = new ServerException("RemoteException occurred in server thread", (Exception) e);
        }
        if (suppressStackTraces) {
            clearStackTraces(e);
        }
        out.writeObject(e);
    } finally {
        // in case skeleton doesn't
        call.releaseInputStream();
        call.releaseOutputStream();
    }
}
Also used : MarshalException(java.rmi.MarshalException) ServerException(java.rmi.ServerException) ObjectOutput(java.io.ObjectOutput) ServerError(java.rmi.ServerError) ServerError(java.rmi.ServerError) IOException(java.io.IOException) Method(java.lang.reflect.Method) IOException(java.io.IOException) UnmarshalException(java.rmi.UnmarshalException) ServerException(java.rmi.ServerException) ExportException(java.rmi.server.ExportException) SkeletonNotFoundException(java.rmi.server.SkeletonNotFoundException) ServerNotActiveException(java.rmi.server.ServerNotActiveException) MarshalException(java.rmi.MarshalException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnmarshalException(java.rmi.UnmarshalException) ObjectInput(java.io.ObjectInput) RemoteException(java.rmi.RemoteException)

Aggregations

IOException (java.io.IOException)2 ObjectInput (java.io.ObjectInput)2 ObjectOutput (java.io.ObjectOutput)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MarshalException (java.rmi.MarshalException)2 RemoteException (java.rmi.RemoteException)2 ServerError (java.rmi.ServerError)2 ServerException (java.rmi.ServerException)2 UnmarshalException (java.rmi.UnmarshalException)2 ExportException (java.rmi.server.ExportException)2 ServerNotActiveException (java.rmi.server.ServerNotActiveException)2 SkeletonNotFoundException (java.rmi.server.SkeletonNotFoundException)2 Method (java.lang.reflect.Method)1