I have two applications running on my local glassfish server. One to rent bicylces and one to buy train tickets. I now wanted to call a remote ejb from the train application
We've made the same example work in two servers: Glassfish 4.1.1 and Websphere Traditional 8.5.5.5
In both cases we deployed two independent packages:
The servlet injects the EJB via the remote interface with @EJB without any parameter for the injection point. This worked in Glassfish. However, to make it work in Websphere we had to include the following explicit lookup in the injection point @EJB(lookup="java:global/ejbBasico/NewSessionBean")
Glassfish Servlet snippet:
/*imports omitted */
@WebServlet(name = "MiServlet", urlPatterns = {"/MiServlet"})
public class Servlet extends HttpServlet {
@EJB
private Interfaz miEjb;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("Result: " + miEjb.businessMethod());
}
finally {
out.close();
}
/*Additional servlet code not included*/
}
Glassfish EJB snippet:
/*imports omitted */
@Stateless
public class NewSessionBean implements Interfaz {
@Override
public String businessMethod() {
return("You've called the EJB");
}
}
Interface:
/*imports omitted */
@Remote
public interface Interfaz {
String businessMethod();
}