-
1. Re: Handling EJB authentication failures
jaikiran Apr 10, 2013 8:18 PM (in response to raylite3)You'll have to use the jboss-remoting API to establish/create a connection yourself. A failing connection creation will throw the exception and you can then handle it. A successful connection can be passed on to the EJBClientContext to register it as a receiver.
-
2. Re: Handling EJB authentication failures
jaikiran Apr 10, 2013 8:20 PM (in response to raylite3)By the way, those failures aren't really EJB authentication failures. They are connection failures to the server from a remote client. EJB doesn't really play a role at that point.
-
3. Re: Handling EJB authentication failures
raylite3 Apr 11, 2013 5:29 PM (in response to jaikiran)Thanks, in this case, the connection failures are because of authentication failure (incorrect password). But the exception I get back is still a IllegalStateException (though I see a SaslException logged, I cannot get access to that exception).
Any pointers/test cases that I can take a look at for using the jboss-remoting API to create connection and then use it for the EJBClientContext.
-
4. Re: Handling EJB authentication failures
jaikiran Apr 11, 2013 11:14 PM (in response to raylite3)1 of 1 people found this helpfulKiran Anantha wrote:
Thanks, in this case, the connection failures are because of authentication failure (incorrect password). But the exception I get back is still a IllegalStateException (though I see a SaslException logged, I cannot get access to that exception).
One of the jobs of the EJB client API is to try and auto connect to the configured destination(s). If it can't then it logs the problem and continues since failing of a connection creation shouldn't stop the EJB client API for functioning. Now at a later point during the EJB invocation, if the EJB client API finds that it has no receivers (whatever the reason is), it throws that IllegalStateException because *at that point* the receiver is necessary for it to function.
Kiran Anantha wrote:
Any pointers/test cases that I can take a look at for using the jboss-remoting API to create connection and then use it for the EJBClientContext.
See this testcase for example https://github.com/jbossas/jboss-ejb-client/blob/master/src/test/java/org/jboss/ejb/client/test/client/EJBClientAPIUsageTestCase.java#L85. Once you get the remoting connection on that line, you can just do a EJBClientContext#register(connection).
-
5. Re: Handling EJB authentication failures
raylite3 Apr 12, 2013 1:31 AM (in response to jaikiran)OK, I got this working but how do I tear down/close the connections? In my Eclipse environment, I see 2 threads running even after I close the context.
final Endpoint endpoint = Remoting.createEndpoint("endpoint", OptionMap.EMPTY);
endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));
URI uri = new URI("remote://localhost:4547");
EJBClientContext ejbClientContext = null;
Connection connection = null;
try {
// open a connection
OptionMap connectionOptionMap = OptionMap
.create(
Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE,
Options.SASL_POLICY_NOPLAINTEXT, Boolean.FALSE);
final IoFuture<Connection> futureConnection = endpoint.connect(uri, connectionOptionMap, new SampleClientCallbackHandler());
connection = IoFutureHelper.get(futureConnection, 5, TimeUnit.SECONDS);
ejbClientContext = EJBClientContext.create();
ejbClientContext.registerConnection(connection);
String appName = "";
String moduleName = "testtx";
String beanName = RemoteSample.class.getName();
String distinctName = "";
final StatelessEJBLocator<RemoteSample> statelessEJBLocator = new StatelessEJBLocator<RemoteSample>(RemoteSample.class, appName, moduleName, beanName, distinctName);
final RemoteSample proxy = EJBClient.createProxy(statelessEJBLocator);
proxy.method1();//invocation
} catch (RuntimeException ex) {
// check if RuntimeException wraps a SaslException
System.err.println("Could not connect to " + uri);
} finally {
ejbClientContext.close();
connection.close();
}
-
6. Re: Handling EJB authentication failures
jaikiran Apr 12, 2013 1:37 AM (in response to raylite3)You have to close the endpoint too.