Created by Luan Cestari / G+/ Facebook/ @BR_LuanCestari
http://bit.ly/124mbpZ
Luan = algorithms + entrepreneur + computer nerd/geek + open source
Are you a boy or a girl?
A long time ago in a galaxy far, far away....
Service Contract
Transparency and loose couple
Registry
BPM
Enterprise Decision Management
...
Organization for the Advancement of Structured Information Standards (OASIS)
SCA
public interface HelloService {
String sayHello(String name);
}
@Service(HelloService.class)
public class HelloServiceBean implements HelloService {
@Override
public String sayHello(String name) {
System.out.println("Recieved name is: " + name);
return "Hello " + name;
}
}
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(mixins = CDIMixIn.class, config = SwitchYardTestCaseConfig.SWITCHYARD_XML)
public class HelloServiceTest {
@ServiceOperation("HelloService")
private Invoker service;
@Test
public void testSayHello() throws Exception {
String message = "JUDCon 2013 Brazil";
String result = service.operation("sayHello").sendInOut(message).getContent(String.class);
Assert.assertTrue("the result is: " + result, ("Hello " + message).equals(result));
}
}
public final class HelloServiceTransformer {
@Transformer(to = "{urn:com.example.switchyard:judcon-brazil:0.0.1-SNAPSHOT}sayHelloResponse")
public Element transformStringToSayHelloResponse(String from) {
StringBuffer sbuffer = new StringBuffer();
sbuffer.append("<sayHelloResponse xmlns=\"urn:com.example.switchyard:judcon-brazil:0.0.1-SNAPSHOT\">")
.append("<string>" + from + "</string>").append("</sayHelloResponse>");
return toElement(sbuffer.toString());
}
@Transformer(from = "{urn:com.example.switchyard:judcon-brazil:0.0.1-SNAPSHOT}sayHello")
public String transformSayHelloToString(Element from) {
return new String(getElementValue(from, "urn:string"));
}
}
<sca:composite name="judcon-brazil" targetNamespace="urn:com.example.switchyard:judcon-china:0.0.1-SNAPSHOT">
<sca:component name="HelloServiceBean">
<bean:implementation.bean class="com.example.switchyard.judcon_brazil.HelloServiceBean"/>
<sca:service name="HelloService">
<sca:interface.java interface="com.example.switchyard.judcon_brazil.HelloService"/>
</sca:service>
</sca:component>
<sca:service name="HelloServicePortType" promote="HelloServiceBean/HelloService">
<sca:interface.wsdl interface="HelloService.wsdl#wsdl.porttype(HelloServicePortType)"/>
<soap:binding.soap>
<soap:contextMapper/>
<soap:wsdl>HelloService.wsdl</soap:wsdl>
<soap:wsdlPort>HelloServicePort</soap:wsdlPort>
<soap:contextPath>judcon-brazil</soap:contextPath>
</soap:binding.soap>
</sca:service>
</sca:composite>
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(
config = SwitchYardTestCaseConfig.SWITCHYARD_XML,
scanners = {BeanSwitchYardScanner.class, TransformSwitchYardScanner.class},
mixins = {CDIMixIn.class, HTTPMixIn.class})
public class HelloServiceSoapTest {
private HTTPMixIn httpMixIn;
@Test
public void testHelloService() throws Exception {
httpMixIn.postResourceAndTestXML("http://localhost:8080/judcon-brazil/HelloService", "/soap-request.xml", "/soap-response.xml");
}
}
Check out the quickstarts, it should give you answers to all of above, and much more!
Hosted at the Github witht his structure:
public interface Component {
Activator createActivator(ServiceDomain domain);
String getName();
void init(Configuration config);
void destroy();
......
}
public interface Activator {
ServiceHandler activateBinding(QName name, BindingModel config);
void deactivateBinding(QName name, ServiceHandler handler);
ServiceHandler activateService(QName name, ComponentModel config);
void deactivateService(QName name, ServiceHandler handler);
......
}
/**
* The role of a Handler is to handle messages and fault events during the
* course of a service invocation...
*/
public interface ExchangeHandler {
void handleMessage(Exchange exchange) throws HandlerException;
void handleFault(Exchange exchange);
}
/**
* Lifecycle-aware version of ExchangeHandler. The deployer will invoke
* start() and stop() in accordance with the deployment's lifecycle.
*/
public interface ServiceHandler extends ExchangeHandler {
void start();
void stop();
}
<sca:component name="SayHelloService">
<bpel:implementation.bpel process="sh:SayHello" />
......
<schema targetNamespace="http://docs.oasis-open.org/ns/opencsa/sca/200903"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<!-- SCA-Assembly XML Schema -->
<import namespace="http://docs.oasis-open.org/ns/opencsa/sca/200912"/>
<!-- SCA-BPEL Component Implementation Type -->
<element name="implementation.bpel" type="sca:BPELImplementation" substitutionGroup="sca:implementation" />
....
</schema>
public interface BPELComponentImplementationModel extends ComponentImplementationModel {
.....
}
public class V1BPELComponentImplementationModel extends V1ComponentImplementationModel implements... {
......
}
public class V1BPELMarshaller extends V1CompositeMarshaller {
/**
* Reads in the Configuration, looking for "implementation.bpel".
* If not found, it falls back to the super class (V1CompositeMarshaller).
*/
@Override
public Model read(Configuration config) {
String name = config.getName();
if (IMPLEMENTATION_BPEL.equals(name)) {
return new V1BPELComponentImplementationModel(config, getDescriptor());
}
return super.read(config);
}
}
bpel1.namespace=http://docs.oasis-open.org/ns/opencsa/sca/200903
bpel1.schema=bpel-v1.xsd
bpel1.location=/org/switchyard/component/bpel/config/model/v1/
bpel1.marshaller=org.switchyard.component.bpel.config.model.v1.V1BPELMarshaller