I'm doing an application in WebLogic 11g (WebLogic 10.3.6), this server uses JDK6, I want to access a Remote EJB from an EAR different from the one that contains the EJB, I'm working in Eclipse Oxygen with the OEPE tools, my code is this:
Regards.java ( is contained in TestingRemotionEAR / TestingRemotionEJB
)package com.beans;
import javax.ejb.Stateless;
/**
* Session Bean implementation class Saludos
*/
@Stateless
public class Saludos implements SaludosRemote {
/**
* Default constructor.
*/
public Saludos() {
// TODO Auto-generated constructor stub
}
@Override
public String Saludo(String nombre) {
// TODO Auto-generated method stub
return "Hola " + nombre;
}
}
GreetingsRemote.java ( is contained in TestingRemotionEAR / TestingRemotionEJBClient
)package com.beans;
import javax.ejb.Remote;
@Remote
public interface SaludosRemote {
public String Saludo(String nombre);
}
The following is an Servlet of the EAR that I want to access the previous EJB, I understand that basically here is where the problem is, in the way to access the JNDI of the WebLogic:
Hola.java ( is contained in TryingRemoteWEBEAR / TryingRemote )
import javax.naming.Context;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.beans.Saludos;
/**
* Servlet implementation class Hola
*/
public class Hola extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Hola() {
super();
// TODO Auto-generated constructor stub
}
Context contexto;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
out.println("<html><body>");
Saludos saludos = null;
try {
saludos = (Saludos) contexto.lookup("SaludosRemote");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println("<h1>" + saludos.Saludo("Gabriel") + "</h1>");
out.println("</body></html>");
}
}
What I am doing so that Hola.java recognizes the EJBs is generating a jar of Saludos.java and placing that jar as a Hello library. java , but in the end it always gives me an error 500 on the server, it is not the first code I have of this, I have tried several but they all give me the same error 500:
Error 500--Internal Server Error
java.lang.NullPointerException