rest - java ee lookup ejbs from from different app -


java ee tutorial not helpful @ all. internet search underwhelming.

i have ejb module deployed glassfish itself. has @local , @remote annotated iterfaces both implemented concrete class.

then have rest resource needs reference ejb module , invoke methods.

can give me barebones, simple example of how done? mean, can't inject sessioncontext rest app, crashes... please, keep simple.

the ejb should have a:

public string getmsg(){      return "ohai"; } 

the rest service:

@get @produces("text/plain") public string asd(){     return <the myterious ejb injected somehow>.getmsg(); } 

thanks.

alright, figured out. using netbeans, applicable eclipse. server - glassfish

create webapp, ejb -> call ejb webapp. these run inside same server separate modules.

first: create ejb module, deployed on own:

remote interface:

package main;  import javax.ejb.remote;  @remote public interface yourremoteinterface{      public string tellmesomething();      public void othermethod(); //etc... } 

then create ejb implementation class:

concrete implementation

package main;  import javax.ejb.remote; import javax.ejb.stateless; import javax.ejb.ejb; //crucial jndi lookup  @remote(remoteinterface.class) @stateless @ejb(name="java:global:/mystuff", beaninterface=yourremoteinterface.class) public class yourconcreteclass implements yourremoteinterface{       @override      public string tellmesomething(){//...} //and other methods } 

@ejb name attribute names bean, use up. can name. ex: "some-name", or "java:global/yourconcreteclass"

part 2 - webapp: web app used rest service, surely can ejb or se client app. se client you'd need set connection info, life.

@path("/somepath") public class service{       @get      @produces("text/plain")      public string qwe(){          try{            javax.naming.initialcontext ic = new javax.naming.initialcontext();             yourremoteinterface rb = (yourremoteinterface)ic.lookup("java:global:/mystuff");            return rb.tellmesomething();           } catch (exception ex) {               return "f*uck life";          }      } } 

now, project properties of webapp, need to:

1) add ejb jar file libraries shows in compile tab. used "add project" button

2) build -> packaging: add ejb jar file war content. used "add file/folder", navigated netbeans projects / ejb module / build / dist

note: may experience error when trying deploy ejb, or redeploy it. error name is: java.lang.runtimeexception: error while binding jndi name main.remoteinterface#main.remoteinterface ejb remotebean . skipping vague explanation, cure it, need execute command in glassfish:

asadmin set server.ejb-container.property.disable-nonportable-jndi-names="true"

now, can compile webapp , deploy it. should work.

at end it's simple. swear i've eaten whole ejb section in glassfish tutorial , tell stuff. it's annoying.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -