6 Replies Latest reply on Feb 15, 2012 6:00 PM by tagnegilles

    Camel Services and SOAP Bindings problem

    tagnegilles

      Hi Guys,

       

      i started to play around with Switchyard and built a small project which use Camel Services and Soap Bindings. I was able to deploy the Switchyard project on switchyard-as7-0.3. The classes are very simple.

       

      The interface CamelService

       

      public interface CamelService { 
                public void makeCamelCall(String message);
                public void testCamelCall(String message);
      }
      

       

      The Camel Services

       

      @Route(CamelService.class)
      public class CamelServiceBean extends RouteBuilder {
      
        @Override
                public void configure() throws Exception {
      
                          onException(Exception.class)
                                              .handled(true)
                                              .log("\nERROR: ${body}\n");
      
                          from("switchyard://CamelService")
                                               .log("\n${body}\n");
                }
      
      }
      

       

      The interface HelloService

       

      public interface HelloService { 
                public void sayHello(String name);
                public void printMessage(String message);
      }
      

       

      The Bean Services

       

      @Service(HelloService.class)
      public class HelloServiceBean implements HelloService {
      
        @Inject @Reference
                private CamelService camelService;
      
        @Override
                public void sayHello(String name) {
                          camelService.makeCamelCall(name);
                }
      
        @Override
                public void printMessage(String message) {
                          System.out.println("Switchyard Message: " + message + " :-)");
                } 
      }
      

       

      I also wrote a Transformer

       

      public class SwitchyardTransformer {
      
        private static final String SAYHELLO_EXPRESSION = "//urn:name";
      
        @Transformer(from = "{urn:gillesswitchyard:services:1.0}sayHello")
                public String transformSayHello(String xmlName) throws XPathExpressionException{
                          XPathFactory xPathFactory = XPathFactory.newInstance();
                          XPath xPath = xPathFactory.newXPath();
                          xPath.setNamespaceContext(new SwitchyardNamespaceContext());
                          return xPath.evaluate(SAYHELLO_EXPRESSION, new InputSource(new StringReader(xmlName)));
                }
      
      }
      

       

      The helloservice.wsdl

       

      <?xml version="1.0" encoding="UTF-8"?>
      <wsdl:definitions name="HelloService" targetNamespace="urn:gillesswitchyard:services:1.0" xmlns:ns1="urn:gillesswitchyard:services:1.0" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:gillesswitchyard:services:1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <wsdl:types>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:gillesswitchyard:services:1.0" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:gillesswitchyard:services:1.0">
        <xsd:element name="sayHello" type="tns:sayHello"/>
        <xsd:complexType name="sayHello">
          <xsd:sequence>
            <xsd:element minOccurs="0" name="name" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:schema>
        </wsdl:types>
        <wsdl:message name="sayHello">
          <wsdl:part name="parameters" element="ns1:sayHello">
          </wsdl:part>
        </wsdl:message>
        <wsdl:portType name="HelloServicePortType">
          <wsdl:operation name="sayHello">
            <wsdl:input name="sayHello" message="ns1:sayHello">
          </wsdl:input>
          </wsdl:operation>
        </wsdl:portType>
        <wsdl:binding name="HelloServiceSoapBinding" type="ns1:HelloServicePortType">
          <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
          <wsdl:operation name="sayHello">
            <soap:operation soapAction="urn:gillesswitchyard:services:1.0" style="document"/>
            <wsdl:input name="sayHello">
              <soap:body use="literal"/>
            </wsdl:input>
          </wsdl:operation>
        </wsdl:binding>
        <wsdl:service name="HelloService">
          <wsdl:port name="HelloServicePort" binding="ns1:HelloServiceSoapBinding">
            <soap:address location="http://localhost:9000/HelloServicePort"/>
          </wsdl:port>
        </wsdl:service>
      </wsdl:definitions>
      

       

      The switchyard.xml file

       

      <?xml version="1.0" encoding="UTF-8"?>
      <switchyard xmlns="urn:switchyard-config:switchyard:1.0"
        xmlns:swyd="urn:switchyard-config:switchyard:1.0" xmlns:trfm="urn:switchyard-config:transform:1.0"
        xmlns:bean="urn:switchyard-component-bean:config:1.0" xmlns:camel="urn:switchyard-component-camel:config:1.0"
        xmlns:soap="urn:switchyard-component-soap:config:1.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
        targetNamespace="urn:de.gilles.projects.switchyard:switchyardProjects:1.0"
        name="switchyardProjects">
      
        <sca:composite name="HelloServices" targetNamespace="urn:gillesswitchyard:services:1.0">
        <sca:service name="HelloService" promote="HelloService">
        <soap:binding.soap>
                                              <soap:wsdl>META-INF/wsdl/helloservice.wsdl</soap:wsdl>
        <soap:socketAddr>:9000</soap:socketAddr>
        </soap:binding.soap>
        </sca:service>
        </sca:composite>
      
      </switchyard>
      
      

       

      As i already told the application was deployed without problem. But when i test the webservice ( Test is done with SOAPUI) with a parameter like Test

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:gillesswitchyard:services:1.0">
         <soapenv:Header/>
         <soapenv:Body>
            <urn:sayHello>
               <!--Optional:-->
               <urn:name>Test</urn:name>
            </urn:sayHello>
         </soapenv:Body>
      </soapenv:Envelope>
      
      

       

      i have an unexpected response on the console

       

      20:06:17,894 INFO  [route1] (default-workqueue-3) 
      Test
      
      20:06:17,927 INFO  [route1] (default-workqueue-4) 
      Test
      
      20:06:17,960 INFO  [route1] (default-workqueue-5) 
      Test
      
      20:06:17,996 INFO  [route1] (default-workqueue-1) 
      Test
      

       

      Please could somebody explain me what is wrong with my code. Because i was expecting only 1 output and not 4 outputs.

       

      Thanks