I will address various cases under the SOA and tools posts labels over the next days.
For now one the issue is the ability to make the quick way an set of web-services. So, after from architecting weve just conclude to the types, number and functionality o the main ws set. There are lots of times (specially in case of existing infrastuctures), that we need to have a
- fast way to createWebServices and
- we don't want to deal/manage with J2EE containers(packaging/deployment ...)
Apache OpenEJB is an embeddable and lightweight EJB 3.0 implementationthat can be used as a standalone server or embedded into Tomcat, JUnit,TestNG, Eclipse, IntelliJ, Maven, Ant, and any IDE or application.OpenEJB is included in Apache Geronimo, IBM WebSphere ApplicationServer CE, and Apple's WebObjects.
In other words, OpenEJB isa way in which you can have everything that is available in the EJB3container, but 'outside' the container (well, not really but is close to).
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 afile inside that folder called ejb-jar.xml and just put in it thisstring "
" (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:
@WebService(portName = "TestPort",
serviceName = "TestWsService",
targetNamespace = "http://thecompanyname.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 ....
}
Thats all. After these steps, you have a stateless bean exposed as a webservice in this location: http://localhost:4204/TestImpl?wsdl
You can use a dynamic proxy (or
// this code can be placed rigth after InitialContext call, or
// can be in another program or in another thread in the same program
// The program that made the call to InitContext need to be alive,
// in order to expose the EJB3 services
Service testService = Service.create(serviceUrl, null);
// test the methods you've implemented ...
Wondering how does it works ?
The reason (expect for the quickness above) for using openejb is that, after doing the 2nd ad third bullet above you have the following major features of the OpenEJB:
Major features
- Supports EJB 3.0, 2.1, 2.0, 1.1 in all modes; embedded, standalone or otherwise.
- JAX-WS support
- JMS support
- J2EE connector support
- Can be dropped into Tomcat 5 or 6 adding various JavaEE 5 and EJB 3.0 features to a standard Tomcat install.
- CMP support is implemented over JPA allowing to freely mix CMP and JPA usage.
- Complete support for Glassfish descriptors allowing those users to embedded test their applications.
- Incrediblyflexible jndi name support allows you to specify formats at macro andmicro levels and imitate the format of other vendors.
- Allows for easy testing and debugging in IDEs such as Eclipse, Idea Intellij or NetBeans with no plugins required.
- Usable in ordinary JUnit or other style test cases without complicated setup or external processes.
- Validatesapplications entirely and reports all failures at once, with threeselectable levels of detail, avoiding several hours worth of "fix,recompile, redeploy, fail, repeat" cycles.
Of coarse, that was the case (for my case) that needed the EJB compliance (ohhh the constrains of the architecture analysis).
In part 2 i'll show you the usage of another tool that helped me lot in another project, just by using xml-xsls but in a very practical (quick & dirty) way...
No comments:
Post a Comment