Extending the DSB

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (3)

View Page History
Even if the DSB already extends the Petals ESB, you can use it and extend it to add some specific features. Extending means that you may want to add some custom core services to the Service Bus. For example, add a transport layer, use your own registry implementation, expose a service as Web service, ...

h1. Exposing Core Services as Web Services

The DSB provide a simple way to expose core services as Web services without any extra configuration. The only things that is needed are :

# Add JAX-WS annotations to core services or generate your service from a WSDL generation tool (Apache CXF is a good choice).
# Adding the core service to the right fractal composite
# There is no 3

To illustrate this feature, we provide a sample to expose a simple TestService service as Web service.

h2. Create your interface
{code:language=java|title=TestService interface}package org.petalslink.dsb.ws.api;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface TestService {

@WebMethod
void test();

}{code}
In this sample, we start from a JAXWS annotated Java interface. This is the only thing to check in this step.

h2. Create your service

Creating your service means implement the interface we just defined in the previous step. Now we have to create a Fractal component which implement the JAXWS annotated TestService interface.
{code:language=java|title=Fractal Component}package org.petalslink.dsb.kernel.ws;

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.type.LifeCycleType;
import org.objectweb.util.monolog.api.Logger;
import org.ow2.petals.util.LoggingUtil;
import org.petalslink.dsb.ws.api.TestService;

@FractalComponent
@Provides(interfaces = { @Interface(name = "service", signature = TestService.class) })
public class TestServiceImpl implements TestService {

@Monolog(name = "logger")
private Logger logger;

private LoggingUtil log;

@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 void test() {
System.out.println("This is a test!");
}

}{code}
* As a Fractal component, you MUST check that you put all the Fractal annotations (@FractalComponent, @Provides, @LifeCycle)
* This component MUST implements the TestService interface


h2. Add service to the architecture

Once the Fractal component has been created, you have to add it to the component architecture provided by the DSB. For now, it is only possible at configuration time by adding the component at the right place. By default, the _Tools.fractal_ definition file located in _trunk/research/commons/dsb/distributions/dsb-distribution/src/main/resources_ (or in your own distribution) contains a WebServiceManagerImpl (org.petalslink.dsb.kernel.tools.ws.WebServiceManagerImpl) component which will detect JAXWS annotated components defined in the _Tools.fractal_ composite and which will expose them automatically at startup on the management port (the same Petals ESB uses).

Adding your component is just instanciating it in _Tools.fractal_ like this:
{code:language=xml|title=Component definition} <component definition="org.petalslink.dsb.kernel.ws.TestServiceImpl" name="TestServiceImpl"/>{code}

That's all\! Your TestService is now exposed by the DSB at startup and is available at : *TODO*

h1. *Adding Core Services*