Search in sources :

Example 1 with StatelessEJBLocator

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

the class SimpleApplicationClientTestCase method descriptorBasedAppClientTest.

/**
     * Tests an app client with a deployment descriptor, that injects an env-entry and an EJB.
     *
     * @throws Exception
     */
@Test
public void descriptorBasedAppClientTest() throws Exception {
    final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class, APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
    final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
    remote.reset();
    final AppClientWrapper wrapper = new AppClientWrapper(archive, "--host=" + managementClient.getRemoteEjbURL(), "client-dd.jar", "");
    try {
        final String result = remote.awaitAppClientCall();
        assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
        assertEquals("EnvEntry", result);
    } finally {
        wrapper.quit();
    }
}
Also used : AppClientWrapper(org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) Test(org.junit.Test)

Example 2 with StatelessEJBLocator

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

the class SimpleApplicationClientTestCase method testAppClientJBossDescriptor.

/**
     * Tests an app client with a deployment descriptor, that injects an env-entry and an EJB.
     *
     * @throws Exception
     */
@Test
public void testAppClientJBossDescriptor() throws Exception {
    final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class, APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
    final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
    remote.reset();
    URL props = getClass().getClassLoader().getResource("jboss-ejb-client.properties");
    final AppClientWrapper wrapper = new AppClientWrapper(archive, " -Dnode0=" + managementClient.getMgmtAddress() + " --ejb-client-properties=" + props, "client-override.jar", "");
    try {
        final String result = remote.awaitAppClientCall();
        assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
        assertEquals("OverridenEnvEntry", result);
    } finally {
        wrapper.quit();
    }
}
Also used : AppClientWrapper(org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) URL(java.net.URL) Test(org.junit.Test)

Example 3 with StatelessEJBLocator

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

the class EJBClientAPIUsageTestCase method testNonSerializableResponse.

/**
     * AS7-3402
     *
     * Tests that a NonSerializableException does not break the channel
     *
     */
@Test
public void testNonSerializableResponse() throws InterruptedException, ExecutionException {
    final StatelessEJBLocator<NonSerialiazableResponseRemote> locator = new StatelessEJBLocator(NonSerialiazableResponseRemote.class, APP_NAME, MODULE_NAME, NonSerializableResponseEjb.class.getSimpleName(), "");
    final NonSerialiazableResponseRemote proxy = EJBClient.createProxy(locator);
    Callable<Object> task = new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                proxy.nonSerializable();
                Assert.fail();
            } catch (Exception e) {
                logger.trace("expected " + e);
            }
            Thread.sleep(1000);
            Assert.assertEquals("hello", proxy.serializable());
            return null;
        }
    };
    final ExecutorService executor = Executors.newFixedThreadPool(10);
    try {
        final List<Future> tasks = new ArrayList<Future>();
        for (int i = 0; i < 100; ++i) {
            tasks.add(executor.submit(task));
        }
        for (Future result : tasks) {
            result.get();
        }
    } finally {
        executor.shutdown();
    }
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) NoSuchEJBException(javax.ejb.NoSuchEJBException) ExecutionException(java.util.concurrent.ExecutionException) EJBException(javax.ejb.EJBException) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 4 with StatelessEJBLocator

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

the class HTTPEJBClientUserTransactionTestCase method testMandatoryTxOnSLSB.

/**
     * Tests a call to a bean method with a Mandatory tx attribute, by initiating a UserTransaction on the
     * remote client side. This test ensures that the tx is propagated to the server during the bean invocation
     *
     * @throws Exception
     */
@Test
public void testMandatoryTxOnSLSB() throws Exception {
    final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
    final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
    final UserTransaction userTransaction = getUserTransaction();
    userTransaction.begin();
    cmtRemoteBean.mandatoryTxOp();
    userTransaction.commit();
}
Also used : UserTransaction(javax.transaction.UserTransaction) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) Test(org.junit.Test)

Example 5 with StatelessEJBLocator

use of org.jboss.ejb.client.StatelessEJBLocator 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) {
                final Marshaller marshaller = factory.createMarshaller(configuration);
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                marshaller.start(new OutputStreamByteOutput(stream));
                marshaller.writeObject(((StatefulEJBLocator<?>) locator).getSessionId());
                marshaller.finish();
                return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
            } else if (locator instanceof EntityEJBLocator) {
                final Marshaller marshaller = factory.createMarshaller(configuration);
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                marshaller.start(new OutputStreamByteOutput(stream));
                marshaller.writeObject(((EntityEJBLocator<?>) locator).getPrimaryKey());
                marshaller.finish();
                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) StartException(org.jboss.msc.service.StartException)

Aggregations

StatelessEJBLocator (org.jboss.ejb.client.StatelessEJBLocator)12 Test (org.junit.Test)11 UserTransaction (javax.transaction.UserTransaction)5 AppClientWrapper (org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper)3 ModelNode (org.jboss.dmr.ModelNode)3 URISyntaxException (java.net.URISyntaxException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 EJBException (javax.ejb.EJBException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 EJBHomeLocator (org.jboss.ejb.client.EJBHomeLocator)1 EntityEJBLocator (org.jboss.ejb.client.EntityEJBLocator)1 StatefulEJBLocator (org.jboss.ejb.client.StatefulEJBLocator)1