i want to know from how many ways i can call my EJb bean without Jax-rs web service.I setup an EJB 3 interface/implementation looking like this...
UserService (interface)
package business;
public interface UserService {
public String doSomething();
}
UserServiceBean (implementation)
@Stateless
@Local
public class UserServiceBean implements UserService{
public UserServiceBean() {
}
@Override
public String doSomething() {
return "Work done!";
}
}
What i know: I know by calling my web service i can get output : "Work done!"
like this.
RestService (Web Service)
package webservices;
@Path("/service")
public class RestService {
@Inject
private UserService userService;
public RestService() {
// TODO Auto-generated constructor stub
}
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/userService")
public String getUserServiceResponse(String json){
String response = userService.doSomething();
return response;
}
}
What I Want: I want a simple method/approach/shortcut etc you can say it. To call my EJB bean without any web service to get my expected output : "Work done!"
.
As like we uses public static void main method in java application.It is very clear question which i have asked.Hope you all got it.
If I understand your request properly you look for a way to call your EJB from outside the container from a java main class?
In that case you need to
Here's an example for the WildFly:
public static void main(String[] args) throws NamingException {
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxx");
Context ctx = new InitialContext(jndiProps);
MyBeanRemote myBean = (MyBeanRemote) ctx.lookup("/<appname>/<beanname>!<fullqualifiedremoteinterface>");
myBean.doSomething();
}
Note the following:
I included a full answer here for completeness, credits belong to user theisuru for my own question