Overview
In this tutorial we will create two SwitchYard composites, a provider and a consumer. We will publish a SOAP web service from the provider, and invoke it from the consumer.
The implementation of both the provider and the consumer will be plain old Java beans.
Prerequisites
- JBoss Developer Studio 7.1
- JBoss EAP 6.1 server with SwitchYard 1.1 installed
- Basic knowledge of SwitchYard and the JBDS SwitchYard tooling
Creating the Provider Application
Provider Service Implementation
- In the JBDS project explorer, right click and select "New SwitchYard Project"
Use the project name "soap-provider" - In the project configuration page...
- Accept the auto-generated defaults for group id, package name and target namespace
- Select a JBoss EAP 6.1 with SwitchYard runtime (see prerequisites)
- In components, select "Implementation Support > Bean" and "Gateway Bindings > SOAP"
- This project will have a service implementation as a Java Bean, and a SOAP service interface
- Finish the project creation wizard; you should see a blank SCA diagram
- Add a Bean implementation to the composite
- Click the “Interface” link to create a new Java interface with the name "HelloProvider"
- The bean name (HelloProviderBean) and service name (HelloProvider) should be filled in automatically
- Add a method String greet(String name); to the HelloProvider interface
- Add the corresponding method & implementation to HelloProviderBean...
return "Hello " + name; - Back on the SwitchYard diagram, hover over the component interface and click the green "Promote Service" button
- Select interface type "WSDL" and create a new interface by clicking the "Interface" hyperlink
- Use the name "HelloService.wsdl" for the WSDL
- Replace the service name with "HelloService"
- Uncheck "wrapped messages"
- Accept defaults for the rest of the wizard
- Make sure “Create required transformers” is checked
- Accept the defaults on the Transformers page (should be Java transformers)
- Use "ProviderTransformers" as the name of the Transformer class
- Add a SOAP binding to the new composite service
- Edit the new ProviderTransformers class...
- Change the return type of transformStringToString(String) to String
- Change the method body to...
return "<string>" + from + "</string>"; - Change the body of transformStringToString1() to...
return from.getTextContent();
Provider Test Client
- In project explorer, right click on the "soap-provider" project and select "New > SwitchYard Test"
- Use "HelloProviderTest" as the name, "HelloProvider" as the service
- Edit the HelloProviderTest unit test...
- Change the parameter to sendInOut() to "Fred"
- Change the assertion at the end to
Assert.assertEquals("Hello Fred", result);
- Run the HelloProviderTest unit test and make sure it passes
Provider Deployment
- Deploy the composite to your EAP server
- Open http://localhost:8080/HelloProvider/HelloProvider?wsdl in your web browser to confirm deployment.
- Adjust the URL as appropriate if your JBoss/SwitchYard server isn’t running on localhost:8080.
- Test the service with SoapUI if possible
Creating the Consumer Application
Consumer Service Implementation
In the first part of the consumer implementation we create the component & service that will eventually consume the external service reference, but without actually using that external service.
- In the JBDS project explorer, right click and select "New SwitchYard Project"
- Use the project name "soap-consumer"
- In the project configuration page...
- Use the default group ID, package name and target namespace
- In components, select "Implementation Support > Bean", "Gateway Bindings > SOAP" and "Gateway Bindings > SCA"
- Finish the project creation wizard; you should see a blank SCA diagram
- Add a Bean implementation to the composite
- Create a new Java interface (click the "Interface" link) with the name "HelloConsumer"
- The bean name and service name should be filled in automatically
- Add a method String greet(); to the HelloConsumer interface
- Add the corresponding method & implementation to HelloConsumerBean
return "Hello world"; - Back on the SwitchYard diagram, hover over the component interface and click the green "Promote Service" button
- Select interface type "Java" and accept the defaults to re-use the existing Java interface
- Add an SCA binding to the promoted service interface, accepting the defaults
Consumer Test Client
- In project explorer, right click on "soap-consumer" project and select "New > SwitchYard Test"
- Use "HelloConsumerTest" as the name, "HelloConsumer" as the service
- Edit the HelloConsumerTest unit test
- Change the assertion at the end to...
Assert.assertEquals("Hello world", result);
- Change the assertion at the end to...
- Run the HelloConsumerTest unit test and make sure it passes
Adding the Provider Service Reference
- Download the published HelloService.wsdl into src/main/resources in soap-consumer project
- Make sure it is named “HelloService.wsdl”
- Refresh the project to make the file visible in JBDS
- Back in the service-consumer SwitchYard SCA composite diagram, drag a "Core > Reference" onto the composite (not onto a component)
- Select "WSDL" as the interface type
- Click "Browse" and select the HelloService.wsdl file
- Right-click on the reference and select "Generate Java interface"
- Delete the HelloProviderPortType reference you just created
- We'll re-create it later by promoting a component reference
- Add a new reference to the HelloConsumer component
- Interface Type is Java
- Browse and select "HelloProviderPortType"
- Hover over the component reference and click the green "promote" button
- Select interface type "WSDL" and browse for "HelloService.wsdl"
- Enter "HelloService" as the service name
- Make sure “Create required transformers” is checked
- Select defaults for transformers, and "ConsumerTransformers" for the transformer class name
- Edit the ConsumerTransformers class
- Change the return type of transformStringToString(String) to String
- Change the body to...
return "<string xmlns=\"urn:com.example.switchyard:soap-provider:1.0\">" + from + "</string>" ;- Confirm the namespace matches the one in the @Transform annotation
- Change the transformStringToString1 method body to
return from.getTextContent();
- Back in the SwitchYard SCA diagram, add a SOAP binding to the HelloService reference, accepting all the defaults
- Edit the HelloConsumerBean class, adding a reference to the provider service...
@Reference @Inject
HelloProviderPortType provider; - Change the body of the HelloConsumerBean.test() method to invoke the provider...
return provider.greet("world"); - Run the HelloConsumerTest unit test again and make sure it still passes
- Change the HelloConsumerBean and HelloConsumerTest implementations to use your own name, and make sure the test still passes.
Comments