Mule Collection-splitter throwing exception: CopyOnWriteArrayList cannot be cast to java.lang.String

StackOverflow https://stackoverflow.com/questions/20066628

  •  31-07-2022
  •  | 
  •  

Question

Here my java component has returned a arrylist that i am splitting using Collection splitter, and wire tapping the list objects. but once after wire tapping when i am changing my original paylaod it is not working. i am getting class cast exception that CopyOnWriteArrayList cannot be cast to java.lang.String. I think that splitted object are get aggregated at the end of flow, without using any additional aggregator, i dont understand why i am not getting the changed payload by set-payload transformer.

below are the flow source code-

<flow name="StandaloneTestFlow1" doc:name="StandaloneTestFlow1">
        <http:inbound-endpoint exchange-pattern="request-response"   doc:name="HTTP" address="http://0.0.0.0:10114/jaxbtest"/>
        <cxf:jaxws-service serviceClass="com.standalone.test.StandaloneTest" doc:name="SOAP"/>
        <component doc:name="Java">
            <method-entry-point-resolver>
                <include-entry-point method="getxmlString"/>
            </method-entry-point-resolver>  
            <spring-object bean="standalonBean"/>
        </component>
        <collection-splitter doc:name="Collection Splitter"/>
        <mulexml:jaxb-object-to-xml-transformer name="autoBeanToSmartxml" jaxbContext-ref="testJaxbContext"/>
        <object-to-string-transformer doc:name="Object to String"/>
        <wire-tap>
            <vm:outbound-endpoint address="vm://testJaxbvm"/>
        </wire-tap>
        <set-payload value="adfafasdfasdfasd " doc:name="Set Payload"/>
 </flow>

following is the exception stack-

org.apache.cxf.interceptor.Fault: java.util.concurrent.CopyOnWriteArrayList cannot be cast to java.lang.String
        at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:116)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
Was it helpful?

Solution

Mule's Collection Splitter is the reason for this issue.

Collection Splitter splits the Collection object into individual objects and passes each object to the next part of the remaining flow one at a time. Its like it is iterating the collection and executing the remaining the flow in the loop of iteration.

Here it is a HTTP request-response inbound. So after the collection splitter has split the collection and executed the remaining flow multiple times based on the size of the colleciton. The end response is aggregated by mule and is given back as the response. But as it is JAXWS service the method signature might have been returning a String. So there is a class cast exception.

So two options.

Either changes the  return type of the method to CopyOnWriteArraylist  which provied with an output like
<response>
 <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
     <greeting>adfafasdfasdfasd</greeting>
 </response>

or

Change the logic to avoid using collection splitter.

Here is more information related to Collection Splitter.

Mule Collection Splitter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top