
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