Quantcast
Channel: GlassFish Related Items on Java.net
Viewing all articles
Browse latest Browse all 1091

How can I access an ejb in another Glassfish server?

$
0
0

For test purpose I have created two projects.

1. Project: HelloServer with the following files

1. File: HelloService.java

		package org.testejb;

import javax.ejb.Remote;

@Remote
public interface HelloService {
String sayHello(String name);
}

2. File: HelloServiceImpl.java
		package org.testejb;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;

@Stateless
@Named
@LocalBean
public class HelloServiceImpl implements HelloService{

@Override
public String sayHello(String name) {
return "Hello " + name;
}

}

2. Project: HelloClient

1. File: HelloService.java

		package org.testejb;

import javax.ejb.Remote;

@Remote
public interface HelloService {
String sayHello(String name);
}

2. File: TestHelloService.java
		package org.testejb.client;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;

import org.testejb.HelloService;

@ManagedBean
public class TestHelloService {

@EJB
HelloService service;

public String sayHello() {
return service.sayHello("Test User");
}
}

3. File: sayHello.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">

<h:body>
<h1>Output: #{testHelloService.sayHello()}</h1>
</h:body>
</html>

If both projects are running in the same glassfish instance then it works fine. The output of sayHello.xhtml is "Hello Test User".
And now my question:

I have two glassfish instances I1 & I2. I1 running on my localhost:8080 and I2 in a vm with the url 192.168.100.199:8080.
In I1 is deployed HelloClient.war and in I2 is deployed HelloServer.war.

What is the configuration of the @EJB annotaion in the TestHelloService class, if i want the call HelloServiceImpl.sayHello() method in glassfish instance I2?

I tried something but nothing did work.


Viewing all articles
Browse latest Browse all 1091

Trending Articles