Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Payload Enricher doesnot work when palyload is empty.

  1. #1
    Join Date
    Jun 2012
    Posts
    11

    Default Payload Enricher doesnot work when palyload is empty.

    When the payload is empty the PayloadEnricher fails to add new values. In my case I'm using int-http:inbound-gateway for request type DELETE. So I do not have a payload body. I have to enrich the payload with the values from path parameter. However since the payload is empty the payload enricher does not add any value to it and gives exception.

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    What exception?
    What does your configuration look like?

  3. #3
    Join Date
    Jun 2012
    Posts
    11

    Default

    WARN o.s.i.h.i.HttpRequestHandlingMessagingGateway - failure occurred in gateway sendAndReceive
    org.springframework.integration.MessageHandlingExc eption: error occurred in message handler [org.springframework.integration.transformer.Conten tEnricher#0]


    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
    at org.springframework.util.LinkedMultiValueMap.put(L inkedMultiValueMap.java:1) ~[spring-core-3.0.7.RELEASE.jar:3.0.7.RELEASE]


    My Configuration reads


    <int-http:inbound-gateway request-channel="deletePayloadEnricher"
    id="deletePaymentInstrumentGateway" error-channel="errorChannel"
    path="/consumer/{consumerId}/paymentInstruments/{paymentInstrumentToken}/gateways/{gatewayId}"
    message-converters="converters"
    supported-methods="DELETE">
    <int-http:header name="consumerId" expression="#pathVariables.consumerId" />
    <int-http:header name="paymentInstrumentToken"
    expression="#pathVariables.paymentInstrumentToken" />
    <int-http:header name="gatewayId"
    expression="#pathVariables.gatewayId" />
    </int-http:inbound-gateway>

    <int:enricher id="deletePaymentInstrumentEnricher" input-channel="deletePayloadEnricher" >
    <introperty name="paymentInstrumentToken" value="onewerewrwerwe" />
    </int:enricher>

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    That's correct, You are getting CCE because you are assuming that what comes out of HttpInboundGateway is a String but in fact its a multipart request and what you get is LinkedMultiValueMap.
    Please look at this sample, for more details
    https://github.com/SpringSource/spri...multipart-http

    You can actually modify it for your use case.

  5. #5
    Join Date
    Jun 2012
    Posts
    11

    Default

    I'm sorry, but I couldn't get what you have suggested. In case of method type delete there is no request body that gets submitted, so the payload remains empty payload{}. Now I want to use the PayloadEnricher to set the values from the pathVariables so that I have values in payload that I can use in the next channel where i have to create a SOAP request using xsl transformation for values in PayloadBody.

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    All I am saying is that the empty payload is an empty LinkedMultiValueMap which comes from Http Inbound Gateway.

    Not only that I don't think you even need the enricher since you already have all the info in the Message headers set in Http Inbound Gateway.

    Can you explain your use case? What are you trying to accomplish?

  7. #7
    Join Date
    Jun 2012
    Posts
    11

    Default

    Yes I agree that I have all the values in the header. I need to create a Soap Request using the xsl transformer where I have
    <xslaram name="paymentInstrumentToken" />
    <deletePaymentInstrumentRequest>
    <paymentInstrumentReference><xsl:value-of select="$paymentInstrumentToken"></xsl:value-of></paymentInstrumentReference>
    </deletePaymentInstrumentRequest>

    Since the payload is empty the xsl transformer gives exception, even though I'm using the values set as header. So I was trying to avoid this exception by trying to set the values using the Payload Enricher.

    When you say Payload is an Empty LinkedMultiValueMap, how can i set the value in the payload enricher. I've tried this and it gives exception.

    <int:enricher id="deletePaymentInstrumentEnricher" input-channel="deletePayloadEnricher" >
    <int: property name="paymentInstrumentToken" value="onewerewrwerwe" />
    </int:enricher>

  8. #8
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Ok, now I see. So few things here.
    Content Enricher (what you currently using) is designed to enrich the "properties" of the payload and in the case of payload being a Map its key/value structure does not really follow the 'properties' conventions with set/get*.
    Having said that I do believe there is a room for improvement in our implementation where you should (for the cases like you have) be able to do something like this:
    Code:
    <int:enricher input-channel="input" output-channel="output">
    	<int:expression value="payload.put('foo', headers.foo)"/>
            <int:expression value="payload.put('bar', headers.bar)"/>
    </int:enricher>
    Basically the above allows you to execute an expression to enrich payload directly even if the payload type does not follow JavaBeans convention.
    So I suggest raising the JIRA issue (as an Improvement) and we'll take care of it.
    For the time being I's use regular Java transformer
    Code:
    public class MyTransformer {
        public Object enrich(Message<Map<Object, Object>> message) {
                Map<Object, Object> payload = message.getPayload();
                Map<String, Object> headers = message.getHeaders();
                payload.put('foo', headers.get("foo"));
                payload.put('bar', headers.get("bar"));
                return payload;
        }
    }
    
    And in XML
    
    <int:transformer input-channel="input" output-channel="output">
          <bean class="foo.bar.MyTransformer"/>
    </int:transformer>
    Hoep that helps

  9. #9
    Join Date
    Jun 2012
    Posts
    11

    Default

    Thank you for the response and the work around. It works fine.

  10. #10
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Still, please raise a JIRA for the improvement https://jira.springsource.org/browse/INT

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •