FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

NetBeans, GlassFish, EJB and external java client.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Wed Oct 07, 2009 8:23 pm    Post subject: NetBeans, GlassFish, EJB and external java client. Reply with quote

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?
Back to top
View user's profile Send private message Send e-mail
smoczyna



Joined: 08 Jan 2009
Posts: 21

PostPosted: Fri Oct 09, 2009 3:19 pm    Post subject: Reply with quote

you need to initialize the bean first, because it uses remote interface you have to use the context. it should look fairly like this:

Context jndiContext = new InitialContext();
Object obj = jndiContext.lookup("java:comp/env/ejb/NewSessionRemote");

the correct path may differ 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.

As a matter of fact if you client works within the same enterprise application it would be easier for you use local interface instead.
Back to top
View user's profile Send private message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Mon Oct 12, 2009 10:58 am    Post subject: Reply with quote

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.

Quote:
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.

Quote:
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.
Back to top
View user's profile Send private message Send e-mail
bftanase



Joined: 12 Oct 2009
Posts: 9

PostPosted: Mon Oct 12, 2009 12:26 pm    Post subject: Reply with quote

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 your application to glassfish, go to Admin Console and look under Applications->Enterprise Application;
Click on your 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 Wink
Back to top
View user's profile Send private message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Fri Oct 16, 2009 9:12 am    Post subject: Reply with quote

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.


Thank you for your answer.

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.

Do you have any ideas why it's not working?
Back to top
View user's profile Send private message Send e-mail
bftanase



Joined: 12 Oct 2009
Posts: 9

PostPosted: Fri Oct 16, 2009 10:05 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Mon Oct 19, 2009 11:05 am    Post subject: Reply with quote

bftanase wrote:
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


I did it several times (from IDE and from GlassFish web interface) to be sure.

Quote:
In ubuntu, have you tried executing webstart from the command line?

"javaws http://<servername>/<application>"


Works the same. It starts javaw process and keeps it in sleep state on "futex_wait" channel. Is there any error log for WebStart?

Quote:
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.


It works on 3700 here. I see connection on this port when I use netstat. Also there are some IIOP commands sent throught it (I use Wireshark to watch ethernet traffic).

Quote:
I'll make tonight a test on Windows 7 and let you know if there are any issues


How did it work?
Back to top
View user's profile Send private message Send e-mail
bftanase



Joined: 12 Oct 2009
Posts: 9

PostPosted: Mon Oct 19, 2009 2:22 pm    Post subject: Reply with quote

I've just run it in a Win 7 virtual machine and it worked perfectly.

Actually the start-up time was almost instantaneously (after the download) which in xp takes about 15 sec...
Back to top
View user's profile Send private message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Thu Oct 22, 2009 9:28 am    Post subject: Reply with quote

bftanase wrote:
I've just run it in a Win 7 virtual machine and it worked perfectly.

Actually the start-up time was almost instantaneously (after the download) which in xp takes about 15 sec...


Finally I solved this puzzle. The problem lies in network interface binding of CORBA transport. By defaults it's setup as 0.0.0.0 which means binding to all available network interfaces (including loopback). My machine has several interfaces and apparently remote client application (after aquiring the list of interfaces from server) tries to connect to 127.0.0.1 (first one on the list) which resolves to local machine. Solution is to change binding in GlassFish: Configuration> ORB> IIOP Listeners> orb-listener-1 to my main interface 192.168.0.1. After server restart all works flawlessly.

Thanks everyone for help.

PS. Well it's not perfect. If I set it to 192.168.0.1 I can't run it locally from NetBeans. So I can't develop locally and deploy remotely at the same time.
Back to top
View user's profile Send private message Send e-mail
bftanase



Joined: 12 Oct 2009
Posts: 9

PostPosted: Thu Oct 22, 2009 1:14 pm    Post subject: Reply with quote

Thank you very much for this info!

After setting orb-listener-1 to my server IP, the start-up time on the client machines has greatly improved!
Back to top
View user's profile Send private message
Kevin



Joined: 28 Oct 2009
Posts: 3

PostPosted: Wed Oct 28, 2009 9:43 pm    Post subject: A standalone client is still not working Reply with quote

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 Confused.

Thanks,

Kevin
Back to top
View user's profile Send private message
pacinpm



Joined: 07 Oct 2009
Posts: 6

PostPosted: Thu Oct 29, 2009 12:39 pm    Post subject: Re: A standalone client is still not working Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
emiddio



Joined: 07 Sep 2009
Posts: 35

PostPosted: Thu Oct 29, 2009 7:09 pm    Post subject: NetBeans, GlassFish, EJB and external java client. Reply with quote

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" <address-removed>
To: <address-removed>
Sent: Wednesday, October 28, 2009 2:43 PM
Subject: [nbj2ee] NetBeans, GlassFish, EJB and external java client.


Quote:
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 Confused.



Thanks,



Kevin



Back to top
View user's profile Send private message
Kevin



Joined: 28 Oct 2009
Posts: 3

PostPosted: Fri Oct 30, 2009 9:49 pm    Post subject: DNS name ok; Server log shows correct request...hits exception Reply with quote

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]
Back to top
View user's profile Send private message
Kevin



Joined: 28 Oct 2009
Posts: 3

PostPosted: Thu Nov 05, 2009 7:42 pm    Post subject: It works now...but not with NetBeans 6.7.1 RCP project Reply with quote

I switched to a regular Java project created in NetBeans 6.7.1, included the jars mentioned earlier in this post. For some reason the

Code:
run.args.extra=-J-da -J-Dorg.omg.CORBA.ORBInitialHost=testServer \
                     -J-Dorg.omg.CORBA.ORBInitialPort=3700

in the project properties didn't work so I created a jndi.properties file in the project root dir and used the InitialContext(env) call. I'm able to connect to my EJB and get info from it. Success at last!!!

So it seems that there may be a problem between NetBeans 6.7.1 RCP (NetBeans Platform Project) and Glassfish (2.1 and 2.1.1).

I found this Glassfish issue (https://glassfish.dev.java.net/issues/show_bug.cgi?id=6655) and confirmed in the source code that the patch has not been applied in Glassfish 2.1.1 release.

I tried to build Glassfish from sources but encountered other Maven issues so I gave up on it. My intent was to get a new appserv-rt.jar built that would have the patch and try with it.

The original issue has not been resolved for NetBeans RCP. Since a regular Java project is working for me, I'm not blocked anymore. Thanks to all those who helped.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB