Running the example

In order to run the example you need a JBoss AS 7 installation- the simplest way is to pickup the switchyard-as7-0.6.0.Final.zip from http://www.jboss.org/switchyard/downloads which already contains all modules bundled into the AS 7 installation.

Once you are done with unzipping and starting Switchyard AS 7, compile and package the project using Maven:


C:\switchyard-as7-0.6\quickstarts\demos\orders mvn install

This will create a file named switchyard-quickstart-demo-orders.war which needs to be deployed on your Switchyard AS 7's deployment folder. Once deployed you can test your Service using a variety of approaches.

Testing the example using JSF

Switchyard jsf tutorial soa jboss esb

At the moment the only Item which is accepted (contained in the InventoryService) is "BUTTER"

Testing the Service using SOAP clients

One thing we have not mentioned yet is that our Service is including a Transformer class. Transformers are a key feature of every integration software since the format of the message is often different from service consumers and providers. So if we want to provide an additional channel to the Service, for example if we want to allow to be consumed it by SOAP clients, we can just write a trasnformer which converts from Java Objects to XML Element and viceversa.

Coding the Trasnformation in a separate class (not in the business class itself) allows a clean separation of the trasnformation logic from the business methods.

Tip

Here's the core section of the Transformers class:


public class Transformers {

    // Element names in XML document
    private static final String ORDER_ID = "orderId";
    private static final String ITEM_ID = "itemId";
    private static final String QUANTITY = "quantity";

    /**
     * Transform from a DOM element to an Order instance.
     * <p/>
     * No need to specify the "to" type because Order is a concrete type.
     * @param from Order element.
     * @return Order instance.
     */
    @Transformer(from = "{urn:switchyard-quickstart-demo:orders:1.0}submitOrder")
    public Order transform(Element from) {
        Order order = new Order();

        order.setOrderId(getElementValue(from, ORDER_ID));
        order.setItemId(getElementValue(from, ITEM_ID));
        order.setQuantity(Integer.valueOf(getElementValue(from, QUANTITY)));

        return order;
    }

    /**
     * Transform from an OrderAck to an Element.
     * <p/>
     * No need to specify the "from" type because OrderAck is a concrete type.
     * @param orderAck OrderAck.
     * @return Order response element.
     */
    @Transformer(to = "{urn:switchyard-quickstart-demo:orders:1.0}submitOrderResponse")
    public Element transform(OrderAck orderAck) {
        StringBuffer ackXml = new StringBuffer()
            .append("<orders:submitOrderResponse xmlns:orders=\"urn:switchyard-quickstart-demo:orders:1.0\">")
            .append("<orderAck>")
            .append("<orderId>" + orderAck.getOrderId() + "</orderId>")
            .append("<accepted>" + orderAck.isAccepted() + "</accepted>")
            .append("<status>" + orderAck.getStatus() + "</status>")
            .append("</orderAck>")
            .append("</orders:submitOrderResponse>");

        return toElement(ackXml.toString());
    }

}

As you can see from the server logs, Apache CXF has associated a Web service to your Order Service and exposed a WSDL of it at http://localhost:8080/demo-orders/OrderService?wsdl

10:03:29,801 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-8) Creating Service {urn:switchyard-quickstart-demo:orders:1.0}OrderService from WSDL: vfs:/C:/switchyard-as7-0.6/bin/content/switchyard-quickstart-demo-orders.war/WEB-INF/classes/wsdl/OrderService.wsdl
10:03:30,737 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-8) Setting the server's publish address to be http://localhost:8080/demo-orders/OrderService
10:03:31,048 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-8) WSDL published to: file:/C:/switchyard-as7-0.6/standalone/data/wsdl/demo-orders.deployment/OrderService.wsdl

Now you can use any SOAP client utility to test the Web service, such as SOAP ui (See a tutorial about SOAP ui and Eclipse here )

Enter the WSDL in your SOAP ui project: http://localhost:8080/demo-orders/OrderService?wsdl

soa switchyard tutorial soa JSF jboss soa

Finally, if you are not willing to use Eclipse ui, you can still run the built-in SOAP client contained in the Project. Just reference it via Maven as it is:

mvn exec:java

SOAP Reply:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <orders:submitOrderResponse xmlns:orders="urn:switchyard-quickstart-demo:orders:1.0">
      <orderAck>
        <orderId>PO-19838-XYZ</orderId>
        <accepted>true</accepted>
        <status>Order Accepted</status>
      </orderAck>
    </orders:submitOrderResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
0
0
0
s2smodern