Search in sources :

Example 6 with Remote

use of java.rmi.Remote in project wildfly by wildfly.

the class EJBComponentDescription method setupRemoteViewInterceptors.

private void setupRemoteViewInterceptors(final EJBViewDescription view) {
    if (view.getMethodIntf() == MethodIntf.REMOTE || view.getMethodIntf() == MethodIntf.HOME) {
        view.getConfigurators().add(new ViewConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                    configuration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.REMOTE_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
                }
            }
        });
        if (view.getMethodIntf() == MethodIntf.HOME) {
            view.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                        final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
                        configuration.setViewInstanceFactory(new RemoteHomeViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
                    }
                }
            });
        }
        // add the remote tx propagating interceptor
        view.getConfigurators().add(new EJBRemoteTransactionsViewConfigurator());
    }
}
Also used : NamespaceViewConfigurator(org.jboss.as.ee.component.NamespaceViewConfigurator) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) EJBSecurityViewConfigurator(org.jboss.as.ejb3.security.EJBSecurityViewConfigurator) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) ViewDescription(org.jboss.as.ee.component.ViewDescription) Remote(java.rmi.Remote) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Example 7 with Remote

use of java.rmi.Remote in project spring-framework by spring-projects.

the class RmiClientInterceptor method refreshAndRetry.

/**
	 * Refresh the RMI stub and retry the given invocation.
	 * Called by invoke on connect failure.
	 * @param invocation the AOP method invocation
	 * @return the invocation result, if any
	 * @throws Throwable in case of invocation failure
	 * @see #invoke
	 */
protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable {
    Remote freshStub = null;
    synchronized (this.stubMonitor) {
        this.cachedStub = null;
        freshStub = lookupStub();
        if (this.cacheStub) {
            this.cachedStub = freshStub;
        }
    }
    return doInvoke(invocation, freshStub);
}
Also used : Remote(java.rmi.Remote)

Example 8 with Remote

use of java.rmi.Remote in project felix by apache.

the class RMIResolver method encodeStub.

protected String encodeStub(RMIServerImpl rmiServer, Map environment) throws IOException {
    Remote stub = rmiServer.toStub();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    try {
        oos = new ObjectOutputStream(baos);
        oos.writeObject(stub);
    } finally {
        if (oos != null)
            oos.close();
    }
    byte[] bytes = baos.toByteArray();
    byte[] encoded = Base64Codec.encodeBase64(bytes);
    // Since the bytes are base 64 bytes, the encoding in creating the string is not important: any will work
    return STUB_CONTEXT + new String(encoded);
}
Also used : Remote(java.rmi.Remote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 9 with Remote

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

the class ActivationGroupImpl method newInstance.

/**
     * Creates a new instance of an activatable remote object. The
     * <code>Activator</code> calls this method to create an activatable
     * object in this group. This method should be idempotent; a call to
     * activate an already active object should return the previously
     * activated object.
     *
     * Note: this method assumes that the Activator will only invoke
     * newInstance for the same object in a serial fashion (i.e.,
     * the activator will not allow the group to see concurrent requests
     * to activate the same object.
     *
     * @param id the object's activation identifier
     * @param desc the object's activation descriptor
     * @return a marshalled object containing the activated object's stub
     */
public MarshalledObject<? extends Remote> newInstance(final ActivationID id, final ActivationDesc desc) throws ActivationException, RemoteException {
    RegistryImpl.checkAccess("ActivationInstantiator.newInstance");
    if (!groupID.equals(desc.getGroupID()))
        throw new ActivationException("newInstance in wrong group");
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new InactiveGroupException("group is inactive");
        }
        ActiveEntry entry = active.get(id);
        if (entry != null)
            return entry.mobj;
        String className = desc.getClassName();
        final Class<? extends Remote> cl = RMIClassLoader.loadClass(desc.getLocation(), className).asSubclass(Remote.class);
        Remote impl = null;
        final Thread t = Thread.currentThread();
        final ClassLoader savedCcl = t.getContextClassLoader();
        ClassLoader objcl = cl.getClassLoader();
        final ClassLoader ccl = covers(objcl, savedCcl) ? objcl : savedCcl;
        /*
             * Fix for 4164971: allow non-public activatable class
             * and/or constructor, create the activatable object in a
             * privileged block
             */
        try {
            /*
                 * The code below is in a doPrivileged block to
                 * protect against user code which code might have set
                 * a global socket factory (in which case application
                 * code would be on the stack).
                 */
            impl = AccessController.doPrivileged(new PrivilegedExceptionAction<Remote>() {

                public Remote run() throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                    Constructor<? extends Remote> constructor = cl.getDeclaredConstructor(ActivationID.class, MarshalledObject.class);
                    constructor.setAccessible(true);
                    try {
                        /*
                               * Fix for 4289544: make sure to set the
                               * context class loader to be the class
                               * loader of the impl class before
                               * constructing that class.
                               */
                        t.setContextClassLoader(ccl);
                        return constructor.newInstance(id, desc.getData());
                    } finally {
                        t.setContextClassLoader(savedCcl);
                    }
                }
            });
        } catch (PrivilegedActionException pae) {
            Throwable e = pae.getException();
            // narrow the exception's type and rethrow it
            if (e instanceof InstantiationException) {
                throw (InstantiationException) e;
            } else if (e instanceof NoSuchMethodException) {
                throw (NoSuchMethodException) e;
            } else if (e instanceof IllegalAccessException) {
                throw (IllegalAccessException) e;
            } else if (e instanceof InvocationTargetException) {
                throw (InvocationTargetException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            }
        }
        entry = new ActiveEntry(impl);
        active.put(id, entry);
        return entry.mobj;
    } catch (NoSuchMethodException | NoSuchMethodError e) {
        /* user forgot to provide activatable constructor?
             * or code recompiled and user forgot to provide
             *  activatable constructor?
             */
        throw new ActivationException("Activatable object must provide an activation" + " constructor", e);
    } catch (InvocationTargetException e) {
        throw new ActivationException("exception in object constructor", e.getTargetException());
    } catch (Exception e) {
        throw new ActivationException("unable to activate object", e);
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
}
Also used : ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) Remote(java.rmi.Remote) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchObjectException(java.rmi.NoSuchObjectException) ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) UnknownObjectException(java.rmi.activation.UnknownObjectException) RMIClassLoader(java.rmi.server.RMIClassLoader)

Example 10 with Remote

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

the class Util method createProxy.

/**
     * Returns a proxy for the specified implClass.
     *
     * If both of the following criteria is satisfied, a dynamic proxy for
     * the specified implClass is returned (otherwise a RemoteStub instance
     * for the specified implClass is returned):
     *
     *    a) either the property java.rmi.server.ignoreStubClasses is true or
     *       a pregenerated stub class does not exist for the impl class, and
     *    b) forceStubUse is false.
     *
     * If the above criteria are satisfied, this method constructs a
     * dynamic proxy instance (that implements the remote interfaces of
     * implClass) constructed with a RemoteObjectInvocationHandler instance
     * constructed with the clientRef.
     *
     * Otherwise, this method loads the pregenerated stub class (which
     * extends RemoteStub and implements the remote interfaces of
     * implClass) and constructs an instance of the pregenerated stub
     * class with the clientRef.
     *
     * @param implClass the class to obtain remote interfaces from
     * @param clientRef the remote ref to use in the invocation handler
     * @param forceStubUse if true, forces creation of a RemoteStub
     * @throws IllegalArgumentException if implClass implements illegal
     * remote interfaces
     * @throws StubNotFoundException if problem locating/creating stub or
     * creating the dynamic proxy instance
     **/
public static Remote createProxy(Class<?> implClass, RemoteRef clientRef, boolean forceStubUse) throws StubNotFoundException {
    Class<?> remoteClass;
    try {
        remoteClass = getRemoteClass(implClass);
    } catch (ClassNotFoundException ex) {
        throw new StubNotFoundException("object does not implement a remote interface: " + implClass.getName());
    }
    if (forceStubUse || !(ignoreStubClasses || !stubClassExists(remoteClass))) {
        return createStub(remoteClass, clientRef);
    }
    final ClassLoader loader = implClass.getClassLoader();
    final Class<?>[] interfaces = getRemoteInterfaces(implClass);
    final InvocationHandler handler = new RemoteObjectInvocationHandler(clientRef);
    try {
        return AccessController.doPrivileged(new PrivilegedAction<Remote>() {

            public Remote run() {
                return (Remote) Proxy.newProxyInstance(loader, interfaces, handler);
            }
        });
    } catch (IllegalArgumentException e) {
        throw new StubNotFoundException("unable to create proxy", e);
    }
}
Also used : RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) Remote(java.rmi.Remote) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) StubNotFoundException(java.rmi.StubNotFoundException)

Aggregations

Remote (java.rmi.Remote)56 LocateRegistry (java.rmi.registry.LocateRegistry)17 Registry (java.rmi.registry.Registry)17 RemoteException (java.rmi.RemoteException)15 IOException (java.io.IOException)6 AlreadyBoundException (java.rmi.AlreadyBoundException)4 NoSuchObjectException (java.rmi.NoSuchObjectException)4 InitialContext (javax.naming.InitialContext)4 WeakReference (java.lang.ref.WeakReference)3 InvocationHandler (java.lang.reflect.InvocationHandler)3 UnknownHostException (java.net.UnknownHostException)3 MarshalledObject (java.rmi.MarshalledObject)3 ExportException (java.rmi.server.ExportException)3 RemoteObject (java.rmi.server.RemoteObject)3 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)3 ServiceException (javax.xml.rpc.ServiceException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InetAddress (java.net.InetAddress)2 NotBoundException (java.rmi.NotBoundException)2 ObjID (java.rmi.server.ObjID)2