4

I am building an application with java enterprise and glassfish. The information between client and server will usually be small amounts of data, but from time to time the client will need to get a larger resource (1-20 MB would be typical). I am still planning the architecture of the system, and I need some advice about how to expose resources on the server to multiple clients.

Originally I was only going to have a desktop client app running in the ACC provided by javaws and glassfish. I put the remote interfaces in a separate jar, and planned to do all client server interfacing by calling EJB methods exposed through those interfaces. This is all fine and well for a java desktop client. It should even be pretty easy for an android client. But I don't think its going to be as easy for ios.

Is there any way I can call my EJBs from the objective-c running in an iphone or ipad? I surely hope so.

Im anticipating that the solution is a RESTful web service. From what I understand this is a way to loosely couple client and server applications by passing the data in a generic XML or JSON form.

Sorry if I am missing something very obvious, but it seems like there are two routes from here:

  1. keep my EJB business interface and implement a duplicate restful interface for generic clients (iOS and whatever else might come up later).

  2. create one restful interface for all clients.

number 2 seems like a much cleaner design, but it means I have to scrap work ive already done and learn about rest. Can someone with more experience offer some suggestions? I would appreciate it so much.

b3bop
  • 3,373
  • 2
  • 17
  • 17

2 Answers2

7

In EJB 3.1 you can expose you business logic as a RESTful service in a very simple way, e.g.:

@Path("name")
@Stateless
public class NameService {
    @EJB
    private NameBean nameBean;

    @GET
    @Produces("text/html")
    public String getHtml() {
        return "<h2>Hello "+nameBean.getName()+"</h2>";
    }

    @PUT
    @Consumes("text/plain")
    public void put(String content) {
        nameBean.setName(content);
    }
}

No need for servlets or any other delegate. It's absolutely fine to have various access methods for one logic so that some java clients use EJB (RMI) and others use REST. In the future you may even add some new ones if needed, e.g. XML web service, through asynchronous messaging and so on.

Wacław Borowiec
  • 700
  • 1
  • 6
  • 12
0

I would suggest Option 2 with one modification, dont even bother to create a web service. Use a plain servlet which returns JSON to be consumed by Android and iOS

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22