Bug 1095980 - [DROOLS-437] ClassCastException is thrown while sending SOAP message to the Drools Camel Server application's webservice endpoint
Summary: [DROOLS-437] ClassCastException is thrown while sending SOAP message to the D...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss BRMS Platform 6
Classification: Retired
Component: BRE
Version: 6.0.1
Hardware: All
OS: All
high
high
Target Milestone: CR1
: 6.0.2
Assignee: Edson Tirelli
QA Contact: Marek Winkler
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-05-09 02:36 UTC by Musharraf Hussain
Modified: 2018-12-05 18:30 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Apache Camel keeps some objects in the message header for applications to use. Drools-Camel code does not expect that and hence a ClassCastException is thrown when trying to send a SOAP message to the Drools Camel Server application's webservice endpoint. This has now been fixed in the latest version of BRMS.
Clone Of:
Environment:
- Red Hat JBoss BRMS 6.0.1 - Drools Camel Server example application https://github.com/droolsjbpm/droolsjbpm-integration/tree/6.0.x/drools-camel-server-example
Last Closed: 2014-08-06 19:53:18 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
server.log part with the exception (20.41 KB, text/plain)
2014-06-06 15:07 UTC, Marek Winkler
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker DROOLS-437 0 Major Closed Kie :: Camel - ClassCast exception in PreCxfTransportSoapProcessor class 2017-11-13 04:28:13 UTC

Description Musharraf Hussain 2014-05-09 02:36:14 UTC
Description of problem:
- This is issue is mirrored from the following Community JIRA [1] as it is faced while using BRMS 6.0.1 product libraries too. 

[1] https://issues.jboss.org/browse/DROOLS-437

Version-Release number of selected component (if applicable):
- BRMS 6.0.1

How reproducible:
- While trying out the drools-camel-server-example shared in the Community Github project branch [1] and sending a SOAP message to the webservice endpoint the "java.lang.ClassCastException: org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String" exception takes place . This issue is reproducible in BRMS 6.0.1 too with the help of productised jars from the same release.

[1] https://github.com/droolsjbpm/droolsjbpm-integration/tree/6.0.x/drools-camel-server-example

Steps to Reproduce:
1. Firstly build the project after downloading it from here [1] and deploy it in BRMS 6.0.1 installation.
2. Then send similar SOAP request messages like these to the webservice endpoint [2]
~~~
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:soap="http://soap.jax.drools.org/">;
   <soapenv:Header/>
   <soapenv:Body>
      <soap:execute>
         <!--Optional:-->
         <soap:arg0>hello</soap:arg0>
      </soap:execute>
   </soapenv:Body>
</soapenv:Envelope>
~~~
3. Following SOAP fault is received
~~~
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">;
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>
~~~

[1] https://github.com/droolsjbpm/droolsjbpm-integration/tree/6.0.x/drools-camel-server-example
[2] http://localhost:8080/drools-camel-server-example-6.0.3-SNAPSHOT/kservice/soap

Actual results:
- The following exception gets thrown.
~~~
18:17:41,606 ERROR [org.apache.camel.processor.DefaultErrorHandler] (http-/localhost:8080-2) Failed delivery for (MessageId: ID-vm22-gsslab-pnq-redhat-com-56326-1399546611115-0-7 on ExchangeId: ID-vm22-gsslab-pnq-redhat-com-56326-1399546611115-0-8). Exhausted after delivery attempt: 1 caught: java.lang.ClassCastException: org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String: java.lang.ClassCastException: org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String
        at org.kie.jax.soap.PreCxfTransportSoapProcessor.process(PreCxfTransportSoapProcessor.java:36) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]
        at org.kie.camel.component.KiePolicy$KieProcess.process(KiePolicy.java:323) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) [camel-core-2.10.3.jar:2.10.3]
        ...
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86) [camel-core-2.10.3.jar:2.10.3]
        at org.apache.camel.component.cxf.CxfConsumer$1.syncInvoke(CxfConsumer.java:125) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:75) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-bundle-jaxrs-2.6.8.jar:2.6.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_51]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_51]
        at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-bundle-jaxrs-2.6.8.jar:2.6.8]
        ...

18:17:41,610 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http-/localhost:8080-2) Application {http://soap.jax.drools.org/}CommandExecutor has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String
        at org.apache.camel.component.cxf.CxfConsumer$1.checkFailure(CxfConsumer.java:200) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.camel.component.cxf.CxfConsumer$1.setResponseBack(CxfConsumer.java:178) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.camel.component.cxf.CxfConsumer$1.syncInvoke(CxfConsumer.java:130) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.camel.component.cxf.CxfConsumer$1.invoke(CxfConsumer.java:75) [camel-cxf-2.10.3.jar:2.10.3]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) [cxf-bundle-jaxrs-2.6.8.jar:2.6.8]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_51]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_51]
        at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) [cxf-bundle-jaxrs-2.6.8.jar:2.6.8]
        ...
Caused by: java.lang.ClassCastException: org.apache.cxf.binding.soap.SoapMessage cannot be cast to java.lang.String
        at org.kie.jax.soap.PreCxfTransportSoapProcessor.process(PreCxfTransportSoapProcessor.java:36) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]
        at org.kie.camel.component.KiePolicy$KieProcess.process(KiePolicy.java:323) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) [camel-core-2.10.3.jar:2.10.3]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.10.3.jar:2.10.3]
        ...
~~~

Expected results:
- Would have successfully received a SOAP response.

Additional info:

Comment 2 Edson Tirelli 2014-05-09 12:18:34 UTC
Rajesh, Marek, this is coming from a customer and I don't know any work around for it. The fix is a one-line fix limited to the kie-camel jar that integrates Drools with Camel. Requesting the blocker flag in order to include it in 6.0.2.

Here is the commit on master:

http://github.com/droolsjbpm/droolsjbpm-integration/commit/808eadec0

Comment 3 Edson Tirelli 2014-05-10 15:41:17 UTC
Cherry-picked into 6.0.x:

http://github.com/droolsjbpm/droolsjbpm-integration/commit/a8674ecdb

Comment 4 Marek Winkler 2014-06-06 15:05:29 UTC
I tried sending the same SOAP request to drools-camel-server-example as Musharraf described.

The CCE is fixed, however now I get a NPE in PostCxfTransportSoapProcessor, see stacktrace:

Caused by: java.lang.NullPointerException
	at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:106) [rt.jar:1.7.0_55]
	at org.kie.jax.soap.PostCxfTransportSoapProcessor.process(PostCxfTransportSoapProcessor.java:39) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]
	at org.kie.camel.component.KiePolicy$KieProcess.process(KiePolicy.java:328) [kie-camel-6.0.3-SNAPSHOT.jar:6.0.3-SNAPSHOT]


It seems that the NPE is a consequence of the fact that the input argument is invalid and it could not be parsed (earlier in the log):

com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'H' (code 72) in prolog; expected '<'

Please see the attached server.log part for the whole stacktrace.

Could you please confirm if the request argument format (the 'hello' string) is valid?

Comment 5 Marek Winkler 2014-06-06 15:07:09 UTC
Created attachment 902952 [details]
server.log part with the exception

Comment 6 Marek Winkler 2014-06-06 15:11:49 UTC
Setting to ASSIGNED, as the NPE should probably be fixed anyway.

Comment 7 Edson Tirelli 2014-06-12 00:19:41 UTC
The problem happens because the input message is invalid. The server expects an XStream-marshalled command as payload, but the example in this ticket is passing in a simple "hello" string as parameter.

An example of valid request is this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.jax.drools.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:execute>
         <soap:arg0>
           <![CDATA[<batch-execution lookup="ksession1">
             <insert out-identifier="message">
               <org.drools.server.Message>
                 <text>Helllo World</text>
               </org.drools.server.Message>
             </insert>
          </batch-execution>]]>
        </soap:arg0>
      </soap:execute>
   </soapenv:Body>
</soapenv:Envelope>

Having said that, I added a couple checks to prevent the NPE at runtime in the kie-camel component:

6.0.x : http://github.com/droolsjbpm/droolsjbpm-integration/commit/96c299cf2
6.1.x : http://github.com/droolsjbpm/droolsjbpm-integration/commit/45d9931bd
master : http://github.com/droolsjbpm/droolsjbpm-integration/commit/c3f792397

Even with the above commits, if an invalid request is sent to the end point, xstream will raise an error as it won't be possible to unmarshall the request. 

Here is a sample response in case of invalid request, like the one in the description of this ticket:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>: Unexpected character 'h' (code 104) in prolog; expected '&lt;'
 at [row,col {unknown-source}]: [1,1]</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

And the server log will show the following exception:

20:11:27,929 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http--127.0.0.1-8080-1) Application {http://soap.jax.drools.org/}CommandExecutor has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault:  : Unexpected character 'h' (code 104) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]

Comment 8 Marek Winkler 2014-06-17 12:46:38 UTC
Verified on BRMS 6.0.2 CR1.

The NPE is handled and a valid message produces an expected response.


Note You need to log in before you can comment on or make changes to this bug.