ClassCastException trying to invoke EJB from Undertow Handler in JBoss EAP 7
Issue
- We have an Undertow Handler which tries to invoke an EJB when the handler is handling a web request.
java.lang.ClassCastException: com.sun.proxy.$Proxy49 cannot be cast to com.jboss.examples.ejb.Hello
at com.jboss.examples.client.HelloClient.callEJB(HelloClient.java:52)
at com.redhat.eap7.undertow.ExampleHandler.handleRequest(ExampleHandler.java:25)
at io.undertow.server.handlers.SetHeaderHandler.handleRequest(SetHeaderHandler.java:90)
at io.undertow.server.handlers.SetHeaderHandler.handleRequest(SetHeaderHandler.java:90)
The Handler looks like:
public class ExampleHandler implements HttpHandler {
...
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
log.info("requestPath: " + exchange.getRequestPath());
try {
log.info("Using HelloClient to lookup and invoke an EJB");
HelloClient helloClient = new HelloClient();
String response = helloClient.callEJB();
log.info("helloClient ejb response: " + response);
} catch(Throwable t) {
t.printStackTrace();
}
next.handleRequest(exchange);
}
...
Environment
Red Hat JBoss Enterprise Application Platform (EAP) 7.0.0
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
