Announcement Announcement Module
Collapse
No announcement yet.
Note about ConcurrentModificationException when MessageHeaders is serialized Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Note about ConcurrentModificationException when MessageHeaders is serialized

    Hello, colleagues

    I want to share some experiences in usage of SI.

    immediately with an example.

    My application calls some external system via HTTP. My task to logging request-response into DB.
    So, I use SI-abilities for that solution: WireTap, queues, aggregator, JdbcMessageStore.
    It is my config:
    HTML Code:
        <channel id="httpGatewayChannel"/>
    
        <channel id="authorizeRequestChannel">
            <interceptors>
                <wire-tap channel="externalServiceAuditAggregatorChannel"/>
            </interceptors>
        </channel>
    
        <channel id="parseBusinessErrorChannel">
            <interceptors>
                <wire-tap channel="externalServiceAuditResponseChannel"/>
            </interceptors>
        </channel>
    
       <channel id="externalServiceAuditAggregatorChannel">
            <queue/>
        </channel>
    
        <channel id="externalServiceAuditResponseChannel">
            <queue/>
        </channel>
    
    <http:outbound-gateway 
                               url="http://url"
                               request-channel="httpGatewayChannel"
                               reply-channel="parseBusinessErrorChannel">
    
    
    <transformer input-channel="parseBusinessErrorChannel" output-channel="transformResponseChannel"
                     ref="businessErrorParser"/>
    
     <chain input-channel="transformParamToFormChannel" output-channel="authorizeRequestChannel">
            <transformer>
                <groovy:script>
                    <![CDATA[
                    return payload.collectEntries { key, value -> [key.toString(), value?.toString()] }
                 ]]>
                </groovy:script>
            </transformer>
            <header-enricher default-overwrite="true">
                <correlation-id expression="headers.id"/>
                <header name="sequenceSize" value="2" type="int"/>
                <header name="sequenceNumber" value="0" type="int"/>
                <header name="date" expression="new java.util.Date()"/>
            </header-enricher>
            <header-filter header-names="accept"/>
        </chain>
    
        <transformer input-channel="authorizeRequestChannel" output-channel="httpGatewayChannel">
            <groovy:script>
                <![CDATA[
                    return payload << headers.credentials
                 ]]>
            </groovy:script>
        </transformer>
    
     <header-enricher input-channel="externalServiceAuditResponseChannel"
                         output-channel="externalServiceAuditAggregatorChannel" default-overwrite="true">
            <header name="sequenceNumber" value="1" type="int"/>
            <header name="date" expression="new java.util.Date()"/>
        </header-enricher>
    
        <aggregator input-channel="externalServiceAuditAggregatorChannel"
                    message-store="messageStore"
                    output-channel="saveAuditChannel"
                    send-timeout="10000"
                    send-partial-result-on-expiry="true"
                    ref="externalServiceAuditAggregator"/>
    The problem of ConcurrentModificationException occurs when my aggregator tries to serialize message to external messageStore and proceeds from groovy-transformer when I add to my Map-payload some additinal entry - headers.credentials in multi-threaded context.
    it is not regularly and also it is difficult to identify problem.
    I hope this helps someone ...

    Also pay attention to
    <header-filter header-names="accept"/>
    This header has value of type ArrayList<MediaType>. ArrayList implements Serializable, but MediaType doesn't. So, when message tries to serialize before save to messageStore the
    NotSerializableException: org.springframework.http.MediaType
    occurs.
    I already opened an issue https://jira.springsource.org/browse/SPR-8738.

    Cheers,
    Artem Bilan
Working...
X