Subscribed unsubscribe Subscribe Subscribe

igarashitm.log

igarashitm, a Japanese software engineer writes something in English here.

Playing around with SwitchYard on OpenShift Express

Install OpenShift Express Client Tools

yum install rubygem-rhc

Create an application with jbossas-7 cartridge

Used HelloSwitchYard as the application name.

rhc app create -l <openshift-account> -a HelloSwitchYard -t jbossas-7

Add SwitchYard Subsystem to the JBoss AS7

switchyard-openshift repository provides a way of that. Let's swipe it :)

cd HelloSwitchYard
git remote add switchyard-template git://github.com/jboss-switchyard/switchyard-openshift.git
git fetch switchyard-template
git checkout switchyard-template/master -- pom.xml
git checkout switchyard-template/master -- standalone.diff
git apply standalone.diff
git rm -f standalone.diff

Edit pom.xml

Fix the artifact name as you like and profile id in the OpenShift manner

diff --git a/pom.xml b/pom.xml
index 845c81c..44e8b12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,11 +1,11 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.switchyard.sample</groupId>
-  <artifactId>swydapp</artifactId>
+  <groupId>mynamespace.helloswitchyard</groupId>
+  <artifactId>HelloSwitchYard</artifactId>
 
   <version>1.0</version>
-  <name>swydapp</name>
+  <name>HelloSwitchYard</name>
   <properties>
     <switchyard.version>0.4.0.OS1</switchyard.version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -43,9 +43,9 @@
   <build />
   <profiles>
     <profile>
-      <id>switchyard</id>
+      <id>openshift</id>
       <build>
-        <finalName>swydapp</finalName>
+        <finalName>HelloSwitchYard</finalName>
         <plugins>
           <plugin>
             <artifactId>maven-jar-plugin</artifactId>

Commit those changes

git add .
git commit -m "Added SwitchYard Subsystem"

Import the bean-service quickstart

Import the bean-service quickstart from SwitchYard distribution. bean-service is simple enough to use as template application

cp -r ${quickstarts}/bean-service/src/main/java/org src/main/java
cp -r ${quickstarts}/bean-service/src/main/resources/wsdl src/main/resources/
cp -r ${quickstarts}/bean-service/src/main/resources/META-INF src/main/resources/
cp -r ${quickstarts}/bean-service/src/test src/

Edit pom.xml

Edit pom.xml to add dependency on switchyard-component-bean, switchyard-component-soap, switchyard-test

diff --git a/pom.xml b/pom.xml
index 44e8b12..210a101 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,6 +21,18 @@
       <artifactId>switchyard-plugin</artifactId>
       <version>${switchyard.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.switchyard.components</groupId>
+      <artifactId>switchyard-component-bean</artifactId>
+      <version>${switchyard.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.switchyard.components</groupId>
+      <artifactId>switchyard-component-soap</artifactId>
+      <version>${switchyard.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.switchyard</groupId>
+      <artifactId>switchyard-test</artifactId>
+      <version>${switchyard.version}</version>
+    </dependency>
   </dependencies>
   <repositories>
     <repository>

Edit src/main/resources/META-INF/switchyard.xml

comment out the socketAddr & contextPath elements in the binding.soap element

diff --git a/src/main/resources/META-INF/switchyard.xml b/src/main/resources/META-INF/switchyard.xml
index 3d24bed..cb193bc 100644
--- a/src/main/resources/META-INF/switchyard.xml
+++ b/src/main/resources/META-INF/switchyard.xml
@@ -5,8 +5,8 @@
             <interface.wsdl interface="wsdl/OrderService.wsdl#wsdl.porttype(OrderService)"/>
             <binding.soap xmlns="urn:switchyard-component-soap:config:1.0">
                 <wsdl>wsdl/OrderService.wsdl</wsdl>
-                <socketAddr>:18001</socketAddr>
-                <contextPath>quickstart-bean</contextPath>
+                <!-- <socketAddr>:18001</socketAddr> -->
+                <!-- <contextPath>quickstart-bean</contextPath> -->
             </binding.soap>
         </service>
     </composite>

Edit src/test/java/org/switchyard/quickstarts/bean/service/WebServiceTest.java

Change the web service address in the testcase

diff --git a/src/test/java/org/switchyard/quickstarts/bean/service/WebServiceTest.java b/src/test/java/org/switchyard/quickstarts/bean/service/WebServiceTest.ja
index 4c6ac9e..ccdc7d0 100644
--- a/src/test/java/org/switchyard/quickstarts/bean/service/WebServiceTest.java
+++ b/src/test/java/org/switchyard/quickstarts/bean/service/WebServiceTest.java
@@ -41,7 +41,7 @@ public class WebServiceTest {
     public void invokeOrderWebService() throws Exception {
         // Use the HttpMixIn to invoke the SOAP binding endpoint with a SOAP input (from the test classpath)
         // and compare the SOAP response to a SOAP response resource (from the test classpath)...
-        httpMixIn.postResourceAndTestXML("http://localhost:18001/quickstart-bean/OrderService", "/xml/soap-request.xml", "/xml/soap-response.xml");
+        httpMixIn.postResourceAndTestXML("http://localhost:8080/OrderService", "/xml/soap-request.xml", "/xml/soap-response.xml");
     }
 }

Build and deploy

mvn -Popenshift clean package
git add .
git commit -m "Added bean-service"
git push

Check the status of application

rhc app status -l <openshift-account> -a HelloSwitchYard

Logs looks like this. Don't mind about some Japanese characters in my log, and an error as well. The important thing here is that HelloSwitchYard.jar has been Deployed successfully.

2012/03/14 14:55:38,258 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016008: Starting weld service for deployment HelloSwitchYard.jar
2012/03/14 14:55:38,993 INFO  [org.switchyard] (MSC service thread 1-3) Starting SwitchYard service
2012/03/14 14:55:39,099 INFO  [org.apache.camel.impl.converter.AnnotationTypeConverterLoader] (MSC service thread 1-3) Found 3 packages with 14 @Converter classes to load
2012/03/14 14:55:39,109 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter] (MSC service thread 1-3) Loaded 153 core type converters (total 153 type converters)
2012/03/14 14:55:39,111 INFO  [org.apache.camel.impl.converter.DefaultTypeConverter] (MSC service thread 1-3) Loaded additional 0 type converters (total 153 type converters) in 0.001 seconds
2012/03/14 14:55:40,197 INFO  [org.switchyard.component.soap.InboundHandler] (MSC service thread 1-3) Publishing WebService at http://127.13.2.129:18001/swydws/OrderService
2012/03/14 14:55:40,630 情報    [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-3) Creating Service {urn:switchyard-quickstart:bean-service:1.0}OrderService from WSDL: vfs:/content/HelloSwitchYard.jar/wsdl/OrderService.wsdl
2012/03/14 14:55:41,376 情報    [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-3) Setting the server's publish address to be http://127.13.2.129:18001/swydws/OrderService
2012/03/14 14:55:41,504 ERROR [org.jboss.as] (MSC service thread 1-3) JBAS015875: JBoss AS 7.1.0.Final "Thunder" started (with errors) in 7971ms - Started 143 of 178 services (1 services failed or missing dependencies, 31 services are passive or on-demand)
2012/03/14 14:55:41,549 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "HelloSwitchYard.jar"

Submit a WebService request using SoapUI

Assuming the namespace is "namespace", Import WSDL from http://helloswitchyard-namespace.rhcloud.com/swydws/OrderService?wsdl into SoapUI and invoke.

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:switchyard-quickstart:bean-service:1.0">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:submitOrder>
         <order>
            <orderId>XYZ</orderId>
            <itemId>BUTTER</itemId>
            <quantity>200</quantity>
         </order>
      </urn:submitOrder>
   </soapenv:Body>
</soapenv:Envelope>

Response

<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:bean-service:1.0">
         <orderAck>
            <orderId>XYZ</orderId>
            <accepted>true</accepted>
            <status>Order Accepted</status>
         </orderAck>
      </orders:submitOrderResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Then you are all set to develop the SwitchYard application on OpenShift Express!
You may want to use the forge tool instead of editing switchyard.xml by hand. Let's see this:


Enjoy!