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);
}
}
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;
}
});
}
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();
}
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) {
}
}
}
});
}
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;
}
Aggregations