Results 1 to 4 of 4

Thread: HTTP Inbound Gateway - using JSON to Object transformer for HashMap

  1. #1
    Join Date
    Feb 2011
    Posts
    9

    Default HTTP Inbound Gateway - using JSON to Object transformer for HashMap

    I am trying to setup a Spring Integration based Restful service. I am trying to avoid creating individual objects for request and response but instead use a HashMap for simple functions such as isUserAvailableForRegistration at service.

    e.g

    Code:
    HashMap<String, String> isUserAvailableForRegistration(HashMap<String,String> request)
    The following is the integration related context information:
    Code:
    <bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>
    
    <int-http:inbound-gateway id="inboundGateway"
        request-channel="incoming" reply-channel="outgoing" 
        supported-methods="POST" reply-timeout="5000"
        path="/customer/isUserAvailable" />
    
    <int:channel id="incoming" />
    <int:channel id="outgoing" />
    
    <int:service-activator id="activator" input-channel="incoming" ref="customerManagementGateway"
        method="isUserAvailableForRegistration" output-channel="outgoing" requires-reply="true" />
    
    <int:object-to-json-transformer id="outgoingJsonConverter"
        input-channel="outgoing" />
    
    <int:json-to-object-transformer id="incomingJsonConverter" input-channel="incoming" type="java.util.HashMap"  />
    While I can successfully test that I could marshall HashMap to JSON successfully, I am missing the configuration to unmarshall JSON data into HashMap.

    I get the following exception:

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed. Multiple causes:
        failed to transform message
        org.springframework.expression.AccessException: Problem invoking method: public java.util.Map com.testapp.customer.CustomerManagementServiceActivator.isUserAvailableForRegistration(java.util.Map)
    See below for the stacktrace of the first cause.
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    
    org.springframework.integration.dispatcher.AggregateMessageDeliveryException: All attempts to deliver Message to MessageHandlers failed. Multiple causes:
        failed to transform message
        org.springframework.expression.AccessException: Problem invoking method: public java.util.Map com.testapp.customer.CustomerManagementServiceActivator.isUserAvailableForRegistration(java.util.Map)
    See below for the stacktrace of the first cause.
        org.springframework.integration.dispatcher.UnicastingDispatcher.handleExceptions(UnicastingDispatcher.java:164)
        org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:127)
        org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
        org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
        org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
        org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
        org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
        org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
        org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:233)
        org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:207)
        org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:378)
        org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:95)
        org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    
    org.springframework.integration.transformer.MessageTransformationException: failed to transform message
        org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:44)
        org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:67)
        org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
        org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
        org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
        org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
        org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
        org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
        org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
        org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
        org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
        org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:233)
        org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:207)
        org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:378)
        org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:95)
        org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        [skipped]
    root cause
    
    java.lang.ClassCastException: [B cannot be cast to java.lang.String
        org.springframework.integration.json.JsonToObjectTransformer.transformPayload(JsonToObjectTransformer.java:30)
        org.springframework.integration.transformer.AbstractPayloadTransformer.doTransform(AbstractPayloadTransformer.java:33)
        org.springframework.integration.transformer.AbstractTransformer.transform(AbstractTransformer.java:33)
        org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:67)
        org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
        org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
        org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
        org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
        org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
        org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
        org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
        org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
        org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
        org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:233)
        org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceiveMessage(MessagingGatewaySupport.java:207)
        org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.doHandleRequest(HttpRequestHandlingEndpointSupport.java:378)
        org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:95)
        org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    Can anybody help me with figuring out what could possible be wrong ?

    I have double checked the headers, hence i am sure that I it's something with the configuration or Jackson's support for unmarshalling to HashMap. Thanks for your time.

  2. #2
    Join Date
    Oct 2011
    Location
    Mumbai, India
    Posts
    213

    Default

    The input channel to your service activator should be the output channel of your json to object transformer. You have used the same channel incoming as the input channel of the transformer and service activator which is not right.

    Also, the output channel of your service activator cannot be the channel outgoing as you expect a json string to be sent out, so change that to something else and that channel be the input channel to the object to json transformer.

    To simplify things, define a chain of json to object transformer, service activator and object to json transformer. The input and output channel of the chain be incoming and outgoing

    Hope that helps..

  3. #3
    Join Date
    Oct 2011
    Location
    Mumbai, India
    Posts
    213

    Default

    Just in case you are new to Spring Integration, this is what I meant when i said use a chain
    http://static.springsource.org/sprin...ce/htmlsingle/
    Last edited by Amol Nayak; Feb 4th, 2012 at 12:01 AM. Reason: Changed the reference to the latest manual

  4. #4
    Join Date
    Feb 2011
    Posts
    9

    Default

    Thanks, Amol, forgot to reply for this, you pointed me to the right direction. it was an issue with the integration graph which i constructed, correcting it solved the problem

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
  •