I just added a new feature to PEtALS ESB kernel in order to expose Fractal Components as Webservices in the PEtALS ESB kernel. As an example, let’s expose some PEtALS runtime information as Web service.
Here are the steps to follow :
1. Create your component interface and add JAXWS annotations
package org.ow2.petals.kernel.ws.api;
import java.util.Date;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService
public interface InformationService {
/**
* Get the container version
*
* @return
* @throws PEtALSWebServiceException
*/
@WebMethod()
@WebResult(name = "version")
String getVersion() throws PEtALSWebServiceException;
/**
* Get the container type : standalone, platform, quickstart...
*
* @return
* @throws PEtALSWebServiceException
*/
@WebMethod()
@WebResult(name = "type")
String getType() throws PEtALSWebServiceException;
@WebMethod
Date getLocalTime() throws PEtALSWebServiceException;
}
2. Implement your Fractal component
package org.ow2.petals.ws;
import java.util.Date;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
import org.objectweb.fractal.fraclet.annotation.annotations.Monolog;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;
import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
import org.objectweb.util.monolog.api.Logger;
import org.ow2.petals.jbi.management.admin.AdminService;
import org.ow2.petals.kernel.ws.api.InformationService;
import org.ow2.petals.kernel.ws.api.PEtALSWebServiceException;
import org.ow2.petals.tools.ws.KernelWebService;
import org.ow2.petals.util.LoggingUtil;
@FractalComponent
@Provides(interfaces = { @Interface(name = "webservice", signature = InformationService.class),
@Interface(name = "service", signature = KernelWebService.class) })
public class InformationServiceImpl implements KernelWebService, InformationService {
@Monolog(name = "logger")
private Logger logger;
private LoggingUtil log;
@org.objectweb.fractal.fraclet.annotation.annotations.Service(name = "component")
private Component component;
@Requires(name = "adminService", signature = AdminService.class)
private AdminService adminService;
@LifeCycle(on = LifeCycleType.START)
protected void start() {
this.log = new LoggingUtil(this.logger);
this.log.debug("Starting...");
}
@LifeCycle(on = LifeCycleType.STOP)
protected void stop() {
this.log.debug("Stopping...");
}
/**
* {@inheritDoc}
*/
public Component getComponent() {
return this.component;
}
/**
* {@inheritDoc}
*/
public String getType() throws PEtALSWebServiceException {
return "Platform";
}
/**
* {@inheritDoc}
*/
public String getVersion() throws PEtALSWebServiceException {
return this.adminService.getSystemInfo();
}
/**
* {@inheritDoc}
*/
public Date getLocalTime() throws PEtALSWebServiceException {
return new Date();
}
}
In the implementation, the important points are :
- The @Provides part. The KernelWebService.class interface MUST be named “service”. The ‘business’ interface to be exposed (here InformationService.class MUST be named “webservice”)
- The Component field is mandatory (used by the webservice manager). Its accessor is mandatory too!
- The implementation MUST implement KernelWebService and the interface you want to expose
The implementation will not be exposed as Web service if the previous points are not followed.
3. Add the component to the WebServiceManager component with the help of Fractal descriptors
For now, the Fractal composite used to expose Fractal components as Web services is defined in the Tools.fractal descriptor (located under your favorite petals distribution). Here are the important steps :
A. Instanciate the component
<component definition=”org.ow2.petals.ws.InformationServiceImpl” name=”InformationWebServiceImpl”/>
<binding client=”WebServiceManagerImpl.webservice-information” server=”InformationWebServiceImpl.service”/>
Interesting post.
Another option to expose Fractal components (ie, their server interfaces) via web-services, is to use the Fractal Binding Factory, which sports Apache CXF for pure, bus-free, web-service support.
More infos at http://bit.ly/fractal-bf-0_7
Comments and feedbacks are welcome.
Yes I know that there are work around this type of things in Fractal and especially within SCA/Frascati project. Thanks for this link we will probably look at it in the next months.
Indeed, FraSCAti is the first project to embeds the Fractal-BF to support different binding protocols. Nevertheless, the BF can be used standalone for pure fractal applications.
hope it helps,
valerio
Ping : Outils Petals ESB : Librarie pour binder des services Web « Christophe Hamerling's TechBlog·
Ping : Exposer ses composants Fractal en Webservice dans Petals ESB #2 « Christophe Hamerling TechBlog·