Sunday, March 4, 2007

Standalone EJB 3.0 client for remote EJB server

In order for a client to connect to your remote GlassFish server you need to add a second IIOP listener with the hostname listening at a different port (ex: 3701). You can do this via the GlassFish admin console.

Create a Java project in Eclipse that will be a standalone EJB 3.0 client application.

When deploying the previously created EJB jar on glassfish using the admin console check the option that creates the client .jar file. Then locate the *Client.jar file on the server and make your project depend on this jar.

Your client app should have code similar to below:

public class Client {

@SuppressWarnings("unchecked")
public void runTest() throws Exception {
Properties props = new Properties();

props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "");
// NOTE: IIOP is set on port 3701 but this works on port 3700
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

InitialContext ctx = new InitialContext(props);

OrderBean bean = (OrderBean) ctx.lookup("ejb/OrderBean");

Order result = bean.findByOrderNum(9);
System.out.println(result.getDescript());
}

public static void main(String[] args) {
Client cli = new Client();
try {
cli.runTest();
} catch (Exception e) {
e.printStackTrace();
}
}
}

204 comments:

«Oldest   ‹Older   201 – 204 of 204
Anonymous said...

Appreciating the time and energy you put into your site and in depth
information you offer. It's nice to come across a blog every once in a while that isn't the
same unwanted rehashed material. Fantastic read! I've saved your site and I'm adding your RSS feeds to
my Google account.

My webpage - candy crush saga hack

Anonymous said...

http://sunchasersportfishingcharters.com in the forefront studying your market,in the future he has use beloved after
[url=http://sunchasersportfishingcharters.com]sunchasersportfishingcharters.com[/url] disassemble xbox 360 slim ebba zingmark chest impeach tv links prypiat psychoanalystic theory cooker misfire system mayfly days molehill boots commonplace reciprocate synonym self-discovery and authority in afro-american narrative gluten free bread glassware made in usa redesigned cars for 2013 fallacys geneva college telemarketing companies preferred auto intense tactical theory slap cheek rugged maniac unavailable calls reunited synonym exaggerated lumbar curve hoggish pledge fabric sweeper

Anonymous said...

Hello There. I found your blog using msn. This is an extremely
well written article. I'll be sure to bookmark it and return to read more of your useful information. Thanks for the post. I will definitely comeback.

Look into my web-site: dragon city hack

Anonymous said...

When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get four e-mails with the same comment.
Is there any way you can remove me from that service? Many thanks!



Check out my webpage :: Psn Code Generator

«Oldest ‹Older   201 – 204 of 204   Newer› Newest»