Search in sources :

Example 1 with RemoteTransportProvider

use of org.jboss.ejb.protocol.remote.RemoteTransportProvider in project wildfly by wildfly.

the class ClientClusterNodeSelectorTestCase method test.

/**
 * Instructs the ClusterNodeSelector on which node to call before each request and that checks that the response
 * comes from that very node;
 */
@Test
public void test(@ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1) throws Exception {
    EJBClientContext BKP = null;
    try {
        final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
        ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
        final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
        connBuilder.setDestination(URI.create(String.format("remote+%s", baseURL1)));
        ejbClientBuilder.addClientConnection(connBuilder.build());
        // ====================================================================================
        // set the custom ClusterNodeSelector
        // ====================================================================================
        ejbClientBuilder.setClusterNodeSelector(new CustomClusterNodeSelector());
        BKP = EJBClientContext.getContextManager().getThreadDefault();
        final EJBClientContext ejbCtx = ejbClientBuilder.build();
        EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
        InitialContext ctx = new InitialContext(props);
        String lookupName = "ejb:/" + MODULE_NAME + "/" + HeartbeatBean.class.getSimpleName() + "!" + Heartbeat.class.getName();
        Heartbeat bean = (Heartbeat) ctx.lookup(lookupName);
        // ====================================================================================
        // first call goes to connected node regardless of CustomClusterNodeSelector
        // ====================================================================================
        Result<Date> res = bean.pulse();
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        // ====================================================================================
        // subsequent calls must be routed to the node selected by the CustomClusterNodeSelector
        // ====================================================================================
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_2);
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_1);
        callBeanOnNode(bean, NODE_3);
        ctx.close();
    } finally {
        EJBClientContext.getContextManager().setThreadDefault(BKP);
    }
}
Also used : WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) Date(java.util.Date) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) HeartbeatBean(org.jboss.as.test.clustering.cluster.ejb.remote.bean.HeartbeatBean) Heartbeat(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) Test(org.junit.Test)

Example 2 with RemoteTransportProvider

use of org.jboss.ejb.protocol.remote.RemoteTransportProvider in project wildfly by wildfly.

the class ClientInterceptorReturnDataRemoteTestCase method testInvokeWithClientInterceptorData.

@Test
public void testInvokeWithClientInterceptorData() throws Throwable {
    EJBClientContext context = new EJBClientContext.Builder().addInterceptor(new ClientInterceptor()).addTransportProvider(new RemoteTransportProvider()).addClientConnection(new EJBClientConnection.Builder().setForDiscovery(true).setDestination(new URI("remote+http", null, url.getHost(), url.getPort(), null, null, null)).build()).build();
    context.runExceptionAction(new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws Exception {
            Properties props = new Properties();
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
            InitialContext ic = new InitialContext(props);
            TestRemote bean = (TestRemote) ic.lookup("ejb:/" + ClientInterceptorReturnDataRemoteTestCase.class.getSimpleName() + "/" + TestSLSB.class.getSimpleName() + "!" + TestRemote.class.getName());
            Assert.assertEquals("DATA:client interceptor data(client data):bean context data", bean.invoke());
            return null;
        }
    });
}
Also used : EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) URI(java.net.URI) InitialContext(javax.naming.InitialContext) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) Test(org.junit.Test)

Example 3 with RemoteTransportProvider

use of org.jboss.ejb.protocol.remote.RemoteTransportProvider in project wildfly by wildfly.

the class EJBClientConfiguratorService method start.

public void start(final StartContext context) throws StartException {
    remoteTransportProvider = new RemoteTransportProvider();
    remoteHttpTransportProvider = new HttpClientProvider();
}
Also used : HttpClientProvider(org.wildfly.httpclient.ejb.HttpClientProvider) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider)

Example 4 with RemoteTransportProvider

use of org.jboss.ejb.protocol.remote.RemoteTransportProvider in project wildfly by wildfly.

the class EJBClientInvocationTimeoutTestCase method testEjbClientContextBuilder.

/**
 * Test setting the invocation timeout when initializing an EJB client context programmatically.
 */
@Test
public void testEjbClientContextBuilder() {
    final EJBClientContext.Builder builder = new EJBClientContext.Builder();
    builder.setInvocationTimeout(1);
    builder.addTransportProvider(new RemoteTransportProvider());
    builder.addClientConnection(new EJBClientConnection.Builder().setDestination(URI.create(INVOCATION_URL)).build());
    builder.build().run(() -> {
        final Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
        InitialContext ejbCtx = null;
        try {
            ejbCtx = new InitialContext(properties);
            LongRunningBeanRemote bean = lookup(ejbCtx);
            try {
                bean.longRunningOperation();
                Assert.fail("Call shouldn't be allowed to finish without throwing an exception");
            } catch (EJBException e) {
                Assert.assertEquals("Call should fail with a TimeoutException", TimeoutException.class, e.getCausedByException().getClass());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (ejbCtx != null) {
                try {
                    ejbCtx.close();
                } catch (NamingException e) {
                }
            }
        }
    });
}
Also used : WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) TimeoutException(java.util.concurrent.TimeoutException) NamingException(javax.naming.NamingException) EJBException(javax.ejb.EJBException) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) NamingException(javax.naming.NamingException) EJBException(javax.ejb.EJBException) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 5 with RemoteTransportProvider

use of org.jboss.ejb.protocol.remote.RemoteTransportProvider in project wildfly by wildfly.

the class ElytronRemoteOutboundConnectionTestCase method callIntermediateWhoAmI.

private String callIntermediateWhoAmI(boolean useRestrictedMethod) {
    AuthenticationConfiguration common = AuthenticationConfiguration.empty().useProviders(() -> new Provider[] { new WildFlyElytronProvider() }).setSaslMechanismSelector(SaslMechanismSelector.ALL);
    AuthenticationContext authCtxEmpty = AuthenticationContext.empty();
    final AuthenticationContext authCtx = authCtxEmpty.with(MatchRule.ALL, common);
    final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
    ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
    final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
    connBuilder.setDestination(URI.create("remote+http://" + TestSuiteEnvironment.getServerAddressNode1() + ":8180"));
    ejbClientBuilder.addClientConnection(connBuilder.build());
    final EJBClientContext ejbCtx = ejbClientBuilder.build();
    AuthenticationContext.getContextManager().setThreadDefault(authCtx);
    EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
    String result;
    try {
        InitialContext ctx = new InitialContext(props);
        String lookupName = "ejb:/outbound-module/IntermediateWhoAmI!org.jboss.as.test.manualmode.ejb.client.outbound.connection.security.WhoAmI";
        WhoAmI intermediate = (WhoAmI) ctx.lookup(lookupName);
        if (useRestrictedMethod) {
            result = intermediate.whoAmIRestricted();
        } else {
            result = intermediate.whoAmI();
        }
        ctx.close();
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) OperationBuilder(org.jboss.as.controller.client.OperationBuilder) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) InitialContext(org.jboss.as.naming.InitialContext) WildFlyElytronProvider(org.wildfly.security.WildFlyElytronProvider) Provider(java.security.Provider) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) NamingException(javax.naming.NamingException) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider)

Aggregations

RemoteTransportProvider (org.jboss.ejb.protocol.remote.RemoteTransportProvider)6 EJBClientConnection (org.jboss.ejb.client.EJBClientConnection)5 EJBClientContext (org.jboss.ejb.client.EJBClientContext)5 Properties (java.util.Properties)4 InitialContext (javax.naming.InitialContext)3 Test (org.junit.Test)3 WildFlyInitialContextFactory (org.wildfly.naming.client.WildFlyInitialContextFactory)3 NamingException (javax.naming.NamingException)2 URI (java.net.URI)1 Provider (java.security.Provider)1 Date (java.util.Date)1 TimeoutException (java.util.concurrent.TimeoutException)1 EJBException (javax.ejb.EJBException)1 OperationBuilder (org.jboss.as.controller.client.OperationBuilder)1 InitialContext (org.jboss.as.naming.InitialContext)1 Heartbeat (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat)1 HeartbeatBean (org.jboss.as.test.clustering.cluster.ejb.remote.bean.HeartbeatBean)1 HttpClientProvider (org.wildfly.httpclient.ejb.HttpClientProvider)1 WildFlyElytronProvider (org.wildfly.security.WildFlyElytronProvider)1 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)1