Thursday, December 6, 2012

How to switch EJB client to local or remote interface without changing code

purpose of this post is to show the design of EJB client that is allowed to switch to @Local or @Remote easily without changing codes.

Steps:
1. Create a java interface with all the method signatures. eg. IFooService
2. Create an empty java interface that extends IFooService and annotate it as @Local. eg. ILocalFooService.
3. Create an empty java interface that extends IFooService and annotate it as @Remote. eg. IRemoteFooService
4. Create the implementation class that implements both ILocalFooService and IRemoteFooService, eg. FooService.

Packaging:
1. compile IFooService as base-service.jar
2. compile ILocalSercie as local-service.jar
3. compile IRemoteService as remote-service.jar
4. compile FooService as service-implementation.jar


when running in a remote environment, include only base-service.jar and remote-service.jar in the client environment.
when running in a local environment, include only base-service.jar and local-service.jar in the client environment.
service-implementation.jar always in the service provider environment. 


LinkWithin

Related Posts Plugin for WordPress, Blogger...