|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
NetBeans, GlassFish, EJB and external java client.Hi, I am evaluating Java EE as my new tool and I tried to create two tiered application: EJB on GlassFish server and remote plain Java client connecting to it.
I am using NetBeans 1.7.1 and GlassFish 2.1 on WinXP. I did it by the books. I created Enterprise Application with EJB module and Application Client module using a GUI wizard. I added stateless bean to the EJB module with remote interface and single business method: Code: @Stateless public class NewSessionBean implements NewSessionRemote { public int businessMethod() { return 42; } } Method simply returns integer so I can be sure it works. In the client application I add remote bean call (using Insert Code/Call Enterprise Bean from editor menu): Code: public class Main { @EJB private static NewSessionRemote newSessionBean; public static void main(String[] args) { // TODO code application logic here System.out.println("Start..."); if (newSessionBean != null) System.out.println( String.valueOf(newSessionBean.businessMethod())); System.out.println("Stop..."); } } Again, the code is very simple just to see if it works. All is well when I debug client application. Unfortunately when I use Run command it seems newSessionBean is always null. What am I doing wrong? Is there any additional step required to connect client application to bean on server? |
|
|
NetBeans, GlassFish, EJB and external java client.you need to initialize the bean first, because it uses remote interface you have to use the context. it should look firly like this:
Context jndiContext = new InitialContext(); Object obj = jndiContext.lookup("java:comp/env/ejb/NewSessionRemote"); the correct path may difer of course. Unfortunately I'm not an expert as well and can't help you more. I have couple of similar unresolved problems and looking for help here but it seems to be wrong place, nobody ever respond. |
|
|
NetBeans, GlassFish, EJB and external java client.Thank you for your reply smoczyna (are you Polish by any chance?).
smoczyna wrote: > you need to initialize the bean first, because it uses remote interface you have to use the context. it should look fairly like this: When I do as you say I get correct results but only in IDE. When I try to run jar file from command line I get an error: Code: C:\>java -jar ApplicationClient2.jar Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial I am pretty sure that it's the way to go with plain java clients. But in case of Application Client Modules I think annotations should be enough. > I have couple of similar unresolved problems and looking for help here but it seems to be wrong place, nobody ever respond. I agree, NetBeans lacks documentation. And there are no good tutorials for non-web client applications. Information is scattered across different forums. Back in the days of Usenet it was much easier to find answers. > As a matter of fact if you client works within the same enterprise application it would be easier for you use local interface instead. I have to use remote interface because my client will work outside GlassFish, on different computer than EJB module. |
|
|
NetBeans, GlassFish, EJB and external java client.If I'm not mistaken for RMI clients you also have to distribute the classes that are referenced remotely (stub).
However, if you use java web start this will be taken care automatically. For example, after you deploy you application to glassfish, go to Admin Console and look under Applications->Enterprise Application; Click on you project and it will show your modules. You should have a "launch" link for the client module. That link will download the jnpl file and start Java Web Start and it will download all the necessary classes. Eventually you can make a shortcut on the client's desktop smth like this: javaws http://<link to the jnpl file on server> This will download, if needed the latest version of the client with all the required classes, and it will launch the program. Hope it helps ;) |
|
|
NetBeans, GlassFish, EJB and external java client.bftanase wrote: > If I'm not mistaken for RMI clients you also have to distribute the classes that are referenced remotely (stub). > > However, if you use java web start this will be taken care automatically. > OK. I am stupid. It was my fault. I was trying to run ApplicationClient project instead of EnterpriseApplication project in NetBeans. Also client stubs downloaded from GlassFish are not always teh same. The working ones reside in Enterprise Applications subtree. Those in Application Client Modules subtree have no EJB jars embedded. So now I have working application client. At least inside an IDE. I tried to use Web Start as suggested by you but it only works on the same machine and only when I download JNLP file and run it from disk. If I try to let WebStart to open it in browser (Firefox) I get an error window: "Splash: recv failed" with title "Java(TM) Web Start 1.6.0_13. On remote machine (local network, Vista+IE+Firefox, Ubuntu+Firefox) WebStart downloads and runs application but it never show up as a window. I can see new java process in process list for my each attempt to run WebStart link but that's all. I have found some information about WebStart not working correctly in Vista but that does not explain why it's not working in Ubuntu. |
|
|
NetBeans, GlassFish, EJB and external java client.Maybe it's smth wrong with deployment.
Try the following: - undeploy your application from Admin Console in glassfish - clean and deploy the project again from NB In ubuntu, have you tried executing webstart from the command line? "javaws http://<servername>/<application>" I have tested webstart on several WinXP machines and it works fine, although the start is pretty slow (after the splash screen there's a long pause till the application starts) Also, take into consideration that RMI works on a different port (1099?) therefore you need to check your firewall settings both on the server and the client. I'll make tonight a test on Windows 7 and let you know if there are any issues |
|
|
NetBeans, GlassFish, EJB and external java client.I'm using NB 6.7.1, JavaEE5, Glassfish 2.1, EJB 3.0.
I've tried all those ideas listed under this topic that are relevant to a standalone client but I'm still unable to get a successful lookup via InitialContext. I had to go the route of a standalone client as I need to use a NetBeans Platform Project. I haven't found any built-in way to make a NetBeans Platform module also be a JavaEE module. Suggestions on some Sun forums were to make it depend on the following jars, which I did. - appserv-rt.jar - javaee.jar - appserv-deployment-client.jar - appserv-ext.jar - jmxremote_optional.jar - toplink-essentials.jar additionally I've included the following lines in the NB Suite's project.properties files. Code: appserver.home=c:\\Sun\\AppServer run.args.extra=-J-da -J-Dorg.omg.CORBA.ORBInitialHost=testServer \ -J-Dorg.omg.CORBA.ORBInitialPort=3700 \ -cp:a ;"${appserver.home}\\lib\\appserv-rt.jar";\ "${appserver.home}\\lib\\appserv-ext.jar";\ "${appserver.home}\\lib\\appserv-deployment-client.jar";\ "${appserver.home}\\lib\\javaee.jar";\ "${appserver.home}\\lib\\jmxremote_optional.jar";\ "${appserver.home}\\lib\\toplink-essentials.jar";\ "..\\test-ejb\\release\\modules\\ext\\test-ejb.jar" My code is simple but I'm unable to do a successful lookup. Code: Context myCtx = new InitialContext(); // [line 1] TestRemote trb = (TestRemote) myCtx.lookup("com.company.test.TestRemote#com.company.test.TestRemote"); // [line 2] Line 1 is working fine. I've verified with Wireshark that a connection is made with my ORB IIOP listener at port 3700. But Line 2 is failing with the message WARNING [javax.enterprise.resource.corba.ee._CORBA_.util]: "IOP01211405: (BAD_OPERATION) Exception in loadStub" java.lang.ClassNotFoundException: com.sun.ejb.codegen.GenericEJBHome_Generated The error above was reported as a NetBeans issue (http://www.netbeans.org/issues/show_bug.cgi?id=125107). I've implemented everything that was suggested by under the issue but still not successful. sun-ejb-jar.xml is below. Code: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.1.1 EJB 3.0//EN" " http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-1.dtd"> <sun-ejb-jar> <enterprise-beans> <unique-id>0</unique-id> <ejb> <ejb-name> TestRemote</ejb-name> <jndi-name>com.company.test.TestRemote</jndi-name> <pass-by-reference>false</pass-by-reference> <is-read-only-bean>false</is-read-only-bean> <refresh-period-in-seconds>-1</refresh-period-in-seconds> <cmt-timeout-in-seconds>0</cmt-timeout-in-seconds> <gen-classes/> </ejb> </enterprise-beans> </sun-ejb-jar> Another post suggested generating RMI stubs (asadmin deploy --generatermistubs =true). I've tried that but it didn't help. I couldn't find client.jar anywhere under glassfish/domains/domain1/ or under glassfish/ But I changed Line 2 (above reference) to the following Code: TestRemote trb = (TestRemote) myCtx.lookup("java:comp/env/ejb/com.company.test.TestRemote"); // [line 2] and got a different error, No object bound for java:comp/env/ejb/com.company.test.TestRemote I'll appreciate any help someone can provide here. I've spent days on this...learned a lot...fixed a lot...but not there yet :?. Thanks, Kevin |
|
|
NetBeans, GlassFish, EJB and external java client.Kevin wrote: > I'm using NB 6.7.1, JavaEE5, Glassfish 2.1, EJB 3.0. > > I've tried all those ideas listed under this topic that are relevant to a standalone client but I'm still unable to get a successful lookup via InitialContext. First of all check your network. GlassFish configuration is sensitive to name resolving. Make sure names resolved on the client machine are the same as on the server machine. If you use Wireshark you can see in IIOP packets what network addresses are advertised by server for use by clients. |
|
|
Re: NetBeans, GlassFish, EJB and external java client.if you download the netbeans 4.1 j2ee tutorial -- there were standalone java
clients that accessed ejb components via jndi; they used corba/rmi-iiop to talk to the server; i have played with some of those in the last month or so; i have had to fix some examples in various tutorials(dont remember which versions) to get to work -- but they eventually all worked when the ejb gets deployed part of the DD results in the ejb being accessable via jndi. i still have those tutorials on a system of mine -- in orig zip format -- but Sun wants you to dnload them from Sun. it might be easiest if you went thru those tutorials for nb41 -- i think they work with nb671 also. i just looked -- my zip is j2eetutorial14NB4_1.zip, its a bit more than 4MByte -- if you cant find at Sun -- if you send me a email -- i can email it to you directly -- not thru this list. the tutorial also includes a pdf of the book for the tutorial. the code in the tutorial is oriented towards j2ee1.4, sun app server 8.1 and pointbase -- but its still very usefull in my view. gary ----- Original Message ----- From: "Kevin" <ksingh.us@...> To: <nbj2ee@...> Sent: Wednesday, October 28, 2009 2:43 PM Subject: [nbj2ee] NetBeans, GlassFish, EJB and external java client. > I'm using NB 6.7.1, JavaEE5, Glassfish 2.1, EJB 3.0. > > > > I've tried all those ideas listed under this topic that are relevant to a > standalone client but I'm still unable to get a successful lookup via > InitialContext. > > > > I had to go the route of a standalone client as I need to use a NetBeans > Platform Project. I haven't found any built-in way to make a NetBeans > Platform module also be a JavaEE module. Suggestions on some Sun forums > were to make it depend on the following jars, which I did. > > - appserv-rt.jar > > - javaee.jar > > - appserv-deployment-client.jar > > - appserv-ext.jar > > - jmxremote_optional.jar > > - toplink-essentials.jar > > > > > > additionally I've included the following lines in the NB Suite's > project.properties files. > > > > > Code: > appserver.home=c:\\Sun\\AppServer > > run.args.extra=-J-da -J-Dorg.omg.CORBA.ORBInitialHost=testServer \ > > -J-Dorg.omg.CORBA.ORBInitialPort=3700 \ > > -cp:a ;"${appserver.home}\\lib\\appserv-rt.jar";\ > > "${appserver.home}\\lib\\appserv-ext.jar";\ > > > "${appserver.home}\\lib\\appserv-deployment-client.jar";\ > > "${appserver.home}\\lib\\javaee.jar";\ > > > "${appserver.home}\\lib\\jmxremote_optional.jar";\ > > > "${appserver.home}\\lib\\toplink-essentials.jar";\ > > > "..\\test-ejb\\release\\modules\\ext\\test-ejb.jar" > > > > > > > > My code is simple but I'm unable to do a successful lookup. > > > > > Code: > Context myCtx = new InitialContext(); // [line 1] > > TestRemote trb = (TestRemote) > myCtx.lookup("com.company.test.TestRemote#com.company.test.TestRemote"); > // [line 2] > > > > > > > > Line 1 is working fine. I've verified with Wireshark that a connection is > made with my ORB IIOP listener at port 3700. But Line 2 is failing with > the message > > > > WARNING [javax.enterprise.resource.corba.ee._CORBA_.util]: "IOP01211405: > (BAD_OPERATION) Exception in loadStub" > > java.lang.ClassNotFoundException: > com.sun.ejb.codegen.GenericEJBHome_Generated > > > > The error above was reported as a NetBeans issue > (http://www.netbeans.org/issues/show_bug.cgi?id=125107). I've implemented > everything that was suggested by under the issue but still not successful. > > > > sun-ejb-jar.xml is below. > > > > > Code: > > > <?xml version="1.0" encoding="UTF-8" standalone="no"?> > > <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application > Server 9.1.1 EJB 3.0//EN" " > > http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-1.dtd"> > > <sun-ejb-jar> > > <enterprise-beans> > > <unique-id>0</unique-id> > > <ejb> > > <ejb-name> TestRemote</ejb-name> > > <jndi-name>com.company.test.TestRemote</jndi-name> > > <pass-by-reference>false</pass-by-reference> > > <is-read-only-bean>false</is-read-only-bean> > > <refresh-period-in-seconds>-1</refresh-period-in-seconds> > > <cmt-timeout-in-seconds>0</cmt-timeout-in-seconds> > > <gen-classes/> > > </ejb> > > </enterprise-beans> > > </sun-ejb-jar> > > > > > > > > Another post suggested generating RMI stubs (asadmin > deploy --generatermistubs =true). I've tried that but it didn't help. I > couldn't find client.jar anywhere under glassfish/domains/domain1/ or > under glassfish/ > > > > But I changed Line 2 (above reference) to the following > > > Code: > TestRemote trb = (TestRemote) > myCtx.lookup("java:comp/env/ejb/com.company.test.TestRemote"); // [line > 2] > > > > > > and got a different error, > > > > No object bound for java:comp/env/ejb/com.company.test.TestRemote > > > > I'll appreciate any help someone can provide here. I've spent days on > this...learned a lot...fixed a lot...but not there yet :?. > > > > Thanks, > > > > Kevin > > > > |
|
|
NetBeans, GlassFish, EJB and external java client.Thanks for the responses.
I've verified, the DNS name wasn't an issue. I've looked at the JavaEE5 Tutorials and got some pointers from there but I was looking at the server log and found an entry with an exception that matched my request. So its seems like the server got my request correctly. Now on to the server side. Someone else on the team configured the server so I'll need to check that end. Here is what I've looked up so far. Shouldn't the sun-ejb-jar.xml have a <resource-ref> entry associating it with the JNDI name I'm looking for? I added the following code in the EJB bean code, compiled, deployed but still no <resource-ref> entry in the sun-ejb-jar.xml. Not sure what I'm missing. @Resource(name="com.company.test.TestRemote") If these two xml files don't give any clue is there some place else I can look? I'm reading through Chapter 17 of the Developer's Guide (Sun Java System Application Server Platform Edition 9). Hopefully something there will give me a clue. ./domain1/generated/xml/j2ee-apps/myapp/myapp-ejb_jar/META-INF/sun-ejb-jar.xml Code: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD ApplicationServer 9.1.1 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-1.dtd"> <sun-ejb-jar> <enterprise-beans> <unique-id>0</unique-id> <ejb> <ejb-name>TestBean</ejb-name> <jndi-name>com.company.test.TestRemote</jndi-name> <pass-by-reference>false</pass-by-reference> <is-read-only-bean>false</is-read-only-bean> <refresh-period-in-seconds>-1</refresh-period-in-seconds> <cmt-timeout-in-seconds>0</cmt-timeout-in-seconds> <gen-classes/> </ejb> </enterprise-beans> </sun-ejb-jar> ./domain1/generated/xml/j2ee-apps/myapp/myapp-ejb_jar/META-INF/ejb-jar.xml Code: <session> <display-name>TestBean</display-name> <ejb-name>TestBean</ejb-name> <business-local>com.company.test.TestLocal</business-local> <business-remote>com.company.test.TestRemote</business-remote> <ejb-class>com.company.test.TestBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> <ejb-local-ref> <ejb-ref-name>com.company.test.TestBean/testCaseBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>com.company.testUnit.TestCaseLocal</local> <ejb-link>TestCaseBean</ejb-link> <injection-target> <injection-target-class>com.company.test.TestBean</injection-target-class> <injection-target-name>testCaseBean</injection-target-name> </injection-target> </ejb-local-ref> <persistence-context-ref> <persistence-context-ref-name>com.company.test.TestBean/em</persistence-context-ref-name> <persistence-context-type>Transaction</persistence-context-type> <injection-target> <injection-target-class>com.company.test.TestBean</injection-target-class> <injection-target-name>em</injection-target-name> </injection-target> </persistence-context-ref> ... </session> [/code] |
| Free embeddable forum powered by Nabble | Forum Help |