Search in sources :

Example 1 with StatefulEJBLocator

use of org.jboss.ejb.client.StatefulEJBLocator in project wildfly by wildfly.

the class EjbIIOPService method referenceForLocator.

/**
 * Returns a corba reference for the given locator
 *
 * @param locator The locator
 * @return The corba reference
 */
public org.omg.CORBA.Object referenceForLocator(final EJBLocator<?> locator) {
    final EJBComponent ejbComponent = ejbComponentInjectedValue.getValue();
    try {
        final String earApplicationName = ejbComponent.getEarApplicationName() == null ? "" : ejbComponent.getEarApplicationName();
        if (locator.getBeanName().equals(ejbComponent.getComponentName()) && locator.getAppName().equals(earApplicationName) && locator.getModuleName().equals(ejbComponent.getModuleName()) && locator.getDistinctName().equals(ejbComponent.getDistinctName())) {
            if (locator instanceof EJBHomeLocator) {
                return (org.omg.CORBA.Object) ejbHome;
            } else if (locator instanceof StatelessEJBLocator) {
                return beanReferenceFactory.createReference(beanRepositoryIds[0]);
            } else if (locator instanceof StatefulEJBLocator) {
                try (final Marshaller marshaller = factory.createMarshaller(configuration)) {
                    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    marshaller.start(new OutputStreamByteOutput(stream));
                    marshaller.writeObject(((StatefulEJBLocator<?>) locator).getSessionId());
                    marshaller.flush();
                    return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
                }
            } else if (locator instanceof EntityEJBLocator) {
                try (final Marshaller marshaller = factory.createMarshaller(configuration)) {
                    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    marshaller.start(new OutputStreamByteOutput(stream));
                    marshaller.writeObject(((EntityEJBLocator<?>) locator).getPrimaryKey());
                    marshaller.flush();
                    return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
                }
            }
            throw EjbLogger.ROOT_LOGGER.unknownEJBLocatorType(locator);
        } else {
            throw EjbLogger.ROOT_LOGGER.incorrectEJBLocatorForBean(locator, ejbComponent.getComponentName());
        }
    } catch (Exception e) {
        throw EjbLogger.ROOT_LOGGER.couldNotCreateCorbaObject(e, locator);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) EJBHomeLocator(org.jboss.ejb.client.EJBHomeLocator) StatefulEJBLocator(org.jboss.ejb.client.StatefulEJBLocator) PortableRemoteObject(javax.rmi.PortableRemoteObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) EntityEJBLocator(org.jboss.ejb.client.EntityEJBLocator) InvalidClassException(java.io.InvalidClassException) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException)

Example 2 with StatefulEJBLocator

use of org.jboss.ejb.client.StatefulEJBLocator in project wildfly by wildfly.

the class StatefulSessionComponent method getEJBObject.

@SuppressWarnings("unchecked")
@Override
public EJBObject getEJBObject(final InterceptorContext ctx) throws IllegalStateException {
    if (getEjbObjectViewServiceName() == null) {
        throw EjbLogger.ROOT_LOGGER.beanComponentMissingEjbObject(getComponentName(), "EJBObject");
    }
    final ServiceController<?> serviceController = currentServiceContainer().getRequiredService(getEjbObjectViewServiceName());
    final ComponentView view = (ComponentView) serviceController.getValue();
    final String locatorAppName = getEarApplicationName() == null ? "" : getEarApplicationName();
    if (WildFlySecurityManager.isChecking()) {
        // need to use doPrivileged rather than doUnchecked, as this can run user code in the proxy constructor
        return AccessController.doPrivileged(new PrivilegedAction<EJBObject>() {

            @Override
            public EJBObject run() {
                return EJBClient.createProxy(new StatefulEJBLocator<EJBObject>((Class<EJBObject>) view.getViewClass(), locatorAppName, getModuleName(), getComponentName(), getDistinctName(), getSessionIdOf(ctx), getCache().getStrictAffinity()));
            }
        });
    } else {
        return EJBClient.createProxy(new StatefulEJBLocator<EJBObject>((Class<EJBObject>) view.getViewClass(), locatorAppName, getModuleName(), getComponentName(), getDistinctName(), getSessionIdOf(ctx), this.getCache().getStrictAffinity()));
    }
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) EJBObject(javax.ejb.EJBObject) StatefulEJBLocator(org.jboss.ejb.client.StatefulEJBLocator)

Aggregations

StatefulEJBLocator (org.jboss.ejb.client.StatefulEJBLocator)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1 EJBObject (javax.ejb.EJBObject)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 ComponentView (org.jboss.as.ee.component.ComponentView)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 EJBHomeLocator (org.jboss.ejb.client.EJBHomeLocator)1 EntityEJBLocator (org.jboss.ejb.client.EntityEJBLocator)1 StatelessEJBLocator (org.jboss.ejb.client.StatelessEJBLocator)1 Marshaller (org.jboss.marshalling.Marshaller)1 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)1 StartException (org.jboss.msc.service.StartException)1