Exposing Fractal Components as Webservices in PEtALS ESB

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 :

  1. The @Provides part. The KernelWebService.class interface MUST be named « service ». The ‘business’ interface to be exposed (here InformationService.class MUST be named « webservice »)
  2. The Component field is mandatory (used by the webservice manager). Its accessor is mandatory too!
  3. 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 »/>

B. Bind component (dependencies to other components)
<binding client= »InformationWebServiceImpl.adminService » server= »this.adminService »/>

C. Say to the Web service Manager to expose this component as Web service

<binding client= »WebServiceManagerImpl.webservice-information » server= »InformationWebServiceImpl.service »/>


Note that in the last point, you MUST always give ‘WebServiceManagerImpl-webservice-SOMETHING’ as client and give the implementation service as server.
Done! Your component is now exposed as Web service and accessible at ‘http://HOST:7600/petals/ws/SERVICE&rsquo; where HOST is the host on which you start petals and SERVICE depends on the JAXWS WebService annotation or class name.

5 réflexions sur “Exposing Fractal Components as Webservices in PEtALS ESB

    • 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

  1. Pingback: Outils Petals ESB : Librarie pour binder des services Web « Christophe Hamerling's TechBlog

  2. Pingback: Exposer ses composants Fractal en Webservice dans Petals ESB #2 « Christophe Hamerling TechBlog

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s