OpenEJB is an embedable and ligthweight implementation of EJB3, can be used as a standalone server also. In popular words, OpenEJB is a way in which you can have everything that is available in the EJB3 container, but 'outside' the container (well, not really).
Consider the next step by step tutorial for creating a webservice.
- Create a sampleproject
- Download openejb-3.0.zip from http://openejb.apache.org/download.html and unpack it
- Add to the classpath of your sampleproject every .jar file that's in unpacked/lib
- Create a META-INF folder inside your src directory and create a file inside that folder called ejb-jar.xml and just put in it this stringr "<ejb-jar/>" (without quotes)
- Create now the interface that defines the contract of your webservice and anotate it with
public interface TestWs { ... }
- Create the class that implements your interface and anotate it like this:
@WebService(portName = "TestPort",
serviceName = "TestWsService",
targetNamespace = "http://yourcompany.com/wsdl",
endpointInterface = "full.qualified.name.of.your.interface.TestWs")
public class TestImpl { ... }
- To start the Webservice you need to do this:
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
properties.setProperty("openejb.embedded.remotable", "true");
new InitialContext(properties); // here the magic starts ....
}
Taran !, after this steps what you have is a stateless bean exposed as a webservice in this location: http://localhost:4204/TestImpl?wsdl
// this code can be placed rigth after InitialContext call, or
// can be in another program or in another thread in the same program
// Of course, the program that made the call to InitContext need to be
// alive for the EJB3 services to be exposed
Service testService = Service.create(serviceUrl, null);
// test the methods you've implemented ...
You would be wondering how does it works ?
prop.setProperty("ejbd.bind", "0.0.0.0");
httpejbd.port, ejbd.bind
Suppose your machine has more than one IP and you want that openejb answers only to requests comming from only one of the IPs in the server, then put the desired IP instead of 0.0.0.0