Topic
  • No replies
SystemAdmin
SystemAdmin
4447 Posts

Pinned topic Misterious problem calling remote EJB3 on Websphere 7

‏2012-01-05T14:14:19Z |
Hi, i have two ears deployed in the same server, Websphere 7. One EAR contain my EJBs3 and the other EAR contain a web application, and i want to try to call remote EJBs through annontation and JNDI lookup.

In the web application EAR, i have the following Servlet:




package org.icabanas.pruebaconcepto.web.servlet;   

import java.io.IOException;   

import javax.ejb.EJB; 

import javax.naming.Context; 

import javax.naming.InitialContext; 

import javax.naming.NamingException; 

import javax.servlet.ServletException; 

import javax.servlet.http.HttpServlet; 

import javax.servlet.http.HttpServletRequest; 

import javax.servlet.http.HttpServletResponse;   

import org.icabanas.pruebaconcepto.dominio.Producto; 

import org.icabanas.pruebaconcepto.facade.ProductoSessionFacade;   @SuppressWarnings(
"serial") 

public 

class ProductoServlet 

extends HttpServlet 
{   @EJB(name=
"EJB/ProductoSessionFacade") 

private ProductoSessionFacade productoSessionFacade; 

private ProductoSessionFacade productoSessionFacadeJndi; @Override 

protected 

void doGet(HttpServletRequest req, HttpServletResponse resp) 

throws ServletException, IOException 
{ String path = req.getRequestURI(); 

if(path.indexOf(
"/producto/index") != -1)
{ req.getRequestDispatcher(
"/WEB-INF/jsp/producto/index.jsp").forward(req, resp); 
} 

else 

if(path.indexOf(
"/producto/alta") != -1)
{ req.getRequestDispatcher(
"/WEB-INF/jsp/producto/alta.jsp").forward(req, resp); 
} 
}   @Override 

protected 

void doPost(HttpServletRequest req, HttpServletResponse resp) 

throws ServletException, IOException 
{ Producto producto = obtenerProductoDeRequest(req); 

try
{ System.out.println(
"INYECCIÓN"); productoSessionFacade.alta(producto); 
} 

catch (Exception e) 
{ System.out.println(
"Error en INYECCIÓN"); System.out.println(e.getMessage()); 
} 

try
{ System.out.println(
"JNDI"); 
//productoSessionFacadeJndi = (ProductoSessionFacade) buscarJndi("ejb/prueba-concepto-ejbs-ear/prueba-concepto-ejbs.jar/ProductoSessionFacadeEjb#org.icabanas.pruebaconcepto.facade.ProductoSessionFacade"); 
//productoSessionFacadeJndi = (ProductoSessionFacade) buscarJndi("ejb/prueba-concepto-ejbs-ear/prueba-concepto-ejbs.jar/ProductoSessionFacadeEjb#org.icabanas.pruebaconcepto.facade.ProductoSessionFacade"); productoSessionFacadeJndi = (ProductoSessionFacade) buscarJndi(
"java:comp/env/EJB/ProductoSessionFacade"); productoSessionFacadeJndi.alta(producto); 
} 

catch (Exception e) 
{ System.out.println(
"Error en JNDI"); System.out.println(e.getMessage()); e.printStackTrace(); 
} 
}   

private Producto obtenerProductoDeRequest(HttpServletRequest request)
{ Producto producto; String nombre = request.getParameter(
"nombre"); String descripcion = request.getParameter(
"descripcion"); producto = 

new Producto(nombre, descripcion); 

return producto; 
} 

private Object buscarJndi(String jndiName)
{ 

try
{ Context ctx = 

new InitialContext(); 

return ctx.lookup(jndiName); 
} 

catch (NamingException e) 
{ e.printStackTrace(); System.out.println(e.getMessage()); 
} 

return 

null; 
} 
}


And, in the EAR containing EJBs i have the following Session Stateless bean and his remote interface:




package org.icabanas.pruebaconcepto.facade.impl.ejb;   

import javax.ejb.Stateless;   

import org.icabanas.pruebaconcepto.dominio.Producto; 

import org.icabanas.pruebaconcepto.facade.ProductoSessionFacade; 

import org.slf4j.Logger; 

import org.slf4j.LoggerFactory;   @Stateless 

public 

class ProductoSessionFacadeEjb 

implements ProductoSessionFacade
{   

private 

static 

final Logger logger = LoggerFactory.getLogger(ProductoSessionFacadeEjb.class); @Override 

public 

void alta(Producto producto) 
{ logger.info(
"Dar de alta el producto."); 
}   
}   

package org.icabanas.pruebaconcepto.facade;   

import javax.ejb.Remote;   

import org.icabanas.pruebaconcepto.dominio.Producto;   @Remote 

public 

interface ProductoSessionFacade 
{ 

void alta(Producto producto); 
}


Ok, if i deploy the two ears in the server and execute the servlet, it works well, i get the EJBs by the two ways (annontation and JNDI lookup), and i get the expected trace (a simple text in the console):


00000019 servlet       I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [prueba-concepto-ejbs-web-ear] [/prueba-concepto-ejbs-web] [Producto Servlet]: Inicialización satisfactoria. 00000019 SystemOut     O INYECCIÓN 00000019 SystemOut     O JNDI 00000019 SystemErr     R 156 [WebContainer : 0] INFO org.icabanas.pruebaconcepto.facade.impl.ejb.ProductoSessionFacadeEjb - Dar de alta el producto. 00000019 SystemErr     R 156 [WebContainer : 0] INFO org.icabanas.pruebaconcepto.facade.impl.ejb.ProductoSessionFacadeEjb - Dar de alta el producto.


But now, if i restart the EAR containing de web application, it doesn't work fine, i get the EJB annotated but i can't get the EJB through JNDI lookup and get the following trace:


[5/01/12 15:00:38:961 CET] 0000001a servlet       I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [prueba-concepto-ejbs-web-ear] [/prueba-concepto-ejbs-web] [Producto Servlet]: Inicialización satisfactoria. [5/01/12 15:00:38:961 CET] 0000001a SystemOut     O INYECCIÓN [5/01/12 15:00:38:977 CET] 0000001a SystemOut     O JNDI [5/01/12 15:00:38:977 CET] 0000001a SystemOut     O Error en JNDI [5/01/12 15:00:38:977 CET] 0000001a SystemOut     O org.icabanas.pruebaconcepto.facade._ProductoSessionFacade_Stub incompatible with org.icabanas.pruebaconcepto.facade.ProductoSessionFacade [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R 197753 [WebContainer : 1] INFO org.icabanas.pruebaconcepto.facade.impl.ejb.ProductoSessionFacadeEjb - Dar de alta el producto. [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R java.lang.ClassCastException: org.icabanas.pruebaconcepto.facade._ProductoSessionFacade_Stub incompatible with org.icabanas.pruebaconcepto.facade.ProductoSessionFacade [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R       at org.icabanas.pruebaconcepto.web.servlet.ProductoServlet.doPost(ProductoServlet.java:56) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R  at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3933) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R        at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R   at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:445) [5/01/12 15:00:38:977 CET] 0000001a SystemErr R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:504) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:301) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:275) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R         at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R        at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R   at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R  at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) [5/01/12 15:00:38:977 CET] 0000001a SystemErr     R     at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)


What's wrong?, any idea?

Thanks in advanced!