1 2 Previous Next 16 Replies Latest reply on Jul 5, 2013 11:49 PM by ffang

    Cannot route SOAP messages

    anirban.gupta4

      Hi,

       

      I was unable to route SOAP messages using Apache Camel. I was trying a simple example. The SOAP message is

       

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:java="http://java.com/">

         <soapenv:Header/>

         <soapenv:Body>

            <java:sayHello>

               <!--Optional:-->

               <arg0>test</arg0>

            </java:sayHello>

         </soapenv:Body>

      </soapenv:Envelope>

       

      My camel-context.xml defined in Spring DSL is:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!--
          Licensed to the Apache Software Foundation (ASF) under one or more
          contributor license agreements.  See the NOTICE file distributed with
          this work for additional information regarding copyright ownership.
          The ASF licenses this file to You under the Apache License, Version 2.0
          (the "License"); you may not use this file except in compliance with
          the License.  You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

          Unless required by applicable law or agreed to in writing, software
          distributed under the License is distributed on an "AS IS" BASIS,
          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          See the License for the specific language governing permissions and
          limitations under the License.
      -->

      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:camel="http://camel.apache.org/schema/spring"
             xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://camel.apache.org/schema/spring
               http://camel.apache.org/schema/spring/camel-spring.xsd">

        <import resource="classpath:META-INF/spring/camel-cxf.xml" />

        <camelContext xmlns="http://camel.apache.org/schema/spring"
            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:java="http://java.com/">
          <route>
             
              <from uri="cxf:bean:helloConsumerEndpoint"/>
              <choice>
                  <when>
                      <xpath>/soapenv:Envelope/soapenv:Body/java:sayHello/arg0 = 'Anirban'</xpath>
                      <log message="UK message"/>
                      <to uri="file:D:/workspace/ExposeWS/target/messages/uk"/>
                  </when>
                  <otherwise>
                      <log message="Other message"/>
                      <to uri="file:D:/workspace/ExposeWS/target/messages/others"/>
                  </otherwise>
              </choice>
          </route>
      </camelContext>

      </beans>

       

      I deployed the project containing this route in JBoss Fuse and when I hit it with the above SOAP message using SOAP UI, I was not expecting any response in SOAP UI and the SOAP message in target locations, but I received the following error in SOAP UI:

       

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

         <soap:Body>

            <soap:Fault>

               <faultcode>soap:Server</faultcode>

               <faultstring>Error during type conversion from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [test] due org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.</faultstring>

            </soap:Fault>

         </soap:Body>

      </soap:Envelope>

       

      Please help.

       

      Regards,

      Anirban.

        • 1. Re: Cannot route SOAP messages
          ffang

          Hi,

           

          You need also post  cxf:bean:helloConsumerEndpoint definition here.

           

          My gut feeling is that you should set dataFormat property as "MESSAGE" but "POJO" is used here.

           

          Freeman

          1 of 1 people found this helpful
          • 2. Re: Cannot route SOAP messages
            anirban.gupta4

            cxf xml file is:

             

            <?xml version="1.0" encoding="UTF-8"?>

            <!--

                Licensed to the Apache Software Foundation (ASF) under one or more

                contributor license agreements.  See the NOTICE file distributed with

                this work for additional information regarding copyright ownership.

                The ASF licenses this file to You under the Apache License, Version 2.0

                (the "License"); you may not use this file except in compliance with

                the License.  You may obtain a copy of the License at

             

             

                http://www.apache.org/licenses/LICENSE-2.0

             

             

                Unless required by applicable law or agreed to in writing, software

                distributed under the License is distributed on an "AS IS" BASIS,

                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

                See the License for the specific language governing permissions and

                limitations under the License.

            -->

             

             

            <beans xmlns="http://www.springframework.org/schema/beans"

                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xmlns:cxf="http://camel.apache.org/schema/cxf"

                   xsi:schemaLocation="

                     http://www.springframework.org/schema/beans

                     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

                     http://camel.apache.org/schema/cxf

                     http://camel.apache.org/schema/cxf/camel-cxf.xsd">

             

             

              <cxf:cxfEndpoint id="helloProviderEndpoint"

                               address="http://localhost:9000/hello/"

                               serviceClass="com.java.HelloWorld"

                               wsdlURL="wsdl/hello.wsdl"/>

                              

              <cxf:cxfEndpoint id="helloConsumerEndpoint"

                               address="http://localhost:9001/hello/"

                               serviceClass="com.java.HelloWorld"

                               wsdlURL="wsdl/hello_consumer.wsdl"/>

            </beans>

             

            I exposed a webservice using java (endpoint 9000) and then defined configurations in camel in which the same would be exposed on a different endpoint (9001) and will access my backend java service. It worked for me. Now I was trying to define routes for SOAP message and getting the folowing error. Please sugges what changes I'll have to make.

             

            Regards,

            Anirban

            • 3. Re: Cannot route SOAP messages
              ffang

              Hi,

               

              Add

              <cxf:properties>

                      <entry key="dataFormat" value="MESSAGE"/>

                  </cxf:properties>

              for helloConsumerEndpoint, this should help

               

              Freeman

              • 4. Re: Cannot route SOAP messages
                anirban.gupta4

                It worked fine now, thanks a lot.

                 

                There is also a syntax using SIMPLE to extract the header or body of the message, would it have been of any help in this scenario? I mean any alternative to this method of routing?

                • 5. Re: Cannot route SOAP messages
                  anirban.gupta4

                  My fial aim is to route SOAP messages from one endpoint to another depending on the content of the message. The above procedure works when I am routing to a file location but when I am routing to a bean endpoint, I am getting the following error:

                   

                  Exception in thread "main"

                   

                  javax.xml.ws.soap.SOAPFaultException: Error during type conversion from type: com.sun.xml.internal.stream.XMLEventReaderImpl to the required type: java.util.List with value com.sun.xml.internal.stream.XMLEventReaderImpl@53311b due java.util.NoSuchElementException

                  : ParseError at [row,col]:[1,1]

                  Message: Premature end of file.

                  at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)

                  at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)

                  at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

                  at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

                  at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)

                  at $Proxy29.sayHello(Unknown Source)

                  at requestor.HelloWorldRequestor.main(

                   

                  HelloWorldRequestor.java:22

                  )

                  Please help.

                  Anirban

                  • 6. Re: Cannot route SOAP messages
                    ffang

                    Hi,

                     

                    The exception here

                    at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)

                    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)

                    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

                    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)

                    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)

                     

                    indicate that you are not using CXF as JAX-WS impl, somehow the metro(JAX-WS RI) was pickep up, please check your ENV ensure CXF is used

                     

                    Freeman

                    • 7. Re: Cannot route SOAP messages
                      anirban.gupta4

                      I have exposed by backend services using JAX-WS. now adding the routes in camel. In camel, the generated classes and endpoints use cxf. But the backend webservices are completely decoupled from the camel route right? The test client with which I was getting the above error generated the artifacts using wsimport but when using Soap UI, I am getting a similar error:

                      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                         <soap:Body>
                            <soap:Fault>
                               <faultcode>soap:Server</faultcode>
                               <faultstring>Error during type conversion from type: com.sun.xml.internal.stream.XMLEventReaderImpl to the required type: java.util.List with value com.sun.xml.internal.stream.XMLEventReaderImpl@296c9f due java.util.NoSuchElementException: ParseError at [row,col]:[1,1]
                      Message: Premature end of file.</faultstring>
                            </soap:Fault>
                         </soap:Body>
                      </soap:Envelope>

                      Is there anything I'll have to change in the

                      <cxf:properties>

                      <entry key="dataFormat" value="MESSAGE"/>

                      </cxf:properties>

                       

                      section?

                      I also tried adding the above section in both the helloConsumerEndpoint and helloProviderEndpoint but then, I'm getting the following error:

                      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
                         <soap:Body>
                            <soap:Fault>
                               <faultcode>soap:Server</faultcode>
                               <faultstring>IllegalStateException invoking http://localhost:9000/hello/: Already connected</faultstring>
                            </soap:Fault>
                         </soap:Body>
                      </soap:Envelope>

                      -Anirban

                      • 8. Re: Cannot route SOAP messages
                        ffang

                        Hi,

                         

                        Yes, you need change

                        <cxf:properties>

                        <entry key="dataFormat" value="MESSAGE"/>

                        </cxf:properties>

                         

                        to

                         

                        <cxf:properties>

                        <entry key="dataFormat" value="POJO"/>

                        </cxf:properties>

                         

                        as a java.util.List object is expected here.

                         

                        Freeman

                        • 9. Re: Cannot route SOAP messages
                          anirban.gupta4

                          Changing the message format to POJO did not help me as I was getting another exception. I changed the message format to PAYLOAD and used

                          <xpath>java:sayHello/arg0 = 'test</xpath>

                          instead of

                          <xpath>/soapenv:Envelope/soapenv:Body/java:sayHello/arg0 = 'test'</xpath>

                          Using this I was able to route message to the correct endpoint but using dataFormat type PAYLOAD only takes the body of the SOAP message, i.e. if my logic is to route message based on the content of some field of SOAP header. I will not be able to. Can you kindly suggest anything for that?

                          -Anirban

                          • 10. Re: Cannot route SOAP messages
                            ffang

                            Hi,

                             

                            Would you please post your whole camel router configuration?

                             

                            Freeman

                            • 11. Re: Cannot route SOAP messages
                              anirban.gupta4

                              My router xml looks like this:

                               

                              <?xml version="1.0" encoding="UTF-8"?>

                              <beans xmlns="http://www.springframework.org/schema/beans"
                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                     xmlns:camel="http://camel.apache.org/schema/spring"
                                     xsi:schemaLocation="
                                       http://www.springframework.org/schema/beans
                                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                       http://camel.apache.org/schema/spring
                                       http://camel.apache.org/schema/spring/camel-spring.xsd">

                                <import resource="classpath:META-INF/spring/camel-cxf.xml" />

                                <camelContext xmlns="http://camel.apache.org/schema/spring"
                                    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                                    xmlns:java="http://java.com/">
                               
                                  <route>
                                    <from uri="cxf:bean:helloConsumerEndpoint" />
                                    <choice>
                                     <when>
                                      <xpath>/java:sayHello/arg0 = 'test'</xpath>
                                      <to uri="file:D:/workspace/ExposeWS/target/mesages/test" />
                                      <to uri="cxf:bean:helloPublisherEndpoint" />
                                     </when>
                                     <otherwise>
                                      <to uri="file:D:/workspace/ExposeWS/target/mesages/others" />
                                      <to uri="cxf:bean:helloPublisherEndpoint" />
                                     </otherwise>
                                    </choice>  
                                  </route>
                                </camelContext>

                              </beans>

                               

                              and camel-cxf.xml looks like this:

                               

                              <?xml version="1.0" encoding="UTF-8"?>


                              <beans xmlns="http://www.springframework.org/schema/beans"
                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                     xmlns:cxf="http://camel.apache.org/schema/cxf"
                                     xsi:schemaLocation="
                                       http://www.springframework.org/schema/beans
                                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                       http://camel.apache.org/schema/cxf
                                       http://camel.apache.org/schema/cxf/camel-cxf.xsd">

                                <cxf:cxfEndpoint id="helloPublisherEndpoint"
                                                 address="http://localhost:9000/hello/"
                                                 serviceClass="com.java.HelloWorld"
                                                 wsdlURL="wsdl/hello_publisher.wsdl">
                                <cxf:properties>
                                 <entry key="dataFormat" value="PAYLOAD" />
                                </cxf:properties>               
                                </cxf:cxfEndpoint>
                                                
                                <cxf:cxfEndpoint id="helloConsumerEndpoint"
                                                 address="http://localhost:9001/hello/"
                                                 serviceClass="com.java.HelloWorld"
                                                 wsdlURL="wsdl/hello_consumer.wsdl">
                                  <cxf:properties>
                                <entry key="dataFormat" value="PAYLOAD" />
                              </cxf:properties>                
                                </cxf:cxfEndpoint>
                              </beans>

                              • 12. Re: Cannot route SOAP messages
                                anirban.gupta4

                                Hi,,Any sugessions on how to route SOAP messages based on message header would by highly appreciated. If the program is working for dataFormat PAYLOAD, I was also expecting it to work for dataFormat MESSAGE, but using the latter, I am getting the error:

                                 

                                Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: IllegalStateException invoking http://localhost:9000/hello/: Already connected
                                at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source)
                                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source)
                                at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
                                at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source)
                                at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source)
                                at $Proxy29.sayHello(Unknown Source)
                                at requestor.HelloWorldRequestor.main(HelloWorldRequestor.java:22)

                                 

                                when hit using testclient and a similar error using Soap UI

                                 

                                Regards,

                                Anirban.

                                • 13. Re: Cannot route SOAP messages
                                  anirban.gupta4

                                  There is some bug in stream cache (as I found by googling), the problem is solved using streamCache="true" on the <route> and using dataFormat=MESSAGE. Thanks.

                                  • 14. Re: Cannot route SOAP messages
                                    ffang

                                    Nice, thanks for sharing what you found!

                                    1 2 Previous Next