Results 1 to 7 of 7

Thread: inbound-channel-adapter and RequestMapper

  1. #1

    Question inbound-channel-adapter and RequestMapper

    Hi All

    I upgraded from Spring Integration 1.0.3 to 2.0.5 Before i had a configuration like this:

    Code:
    <bean id="linefeedAwareInboundRequestMapper"
    		class="com.namics.wetteralarm.queue.endpoint.LinefeedAwareInboundRequestMapper" />
    	<!-- Receives http post xml messages. bean id must match web.xml servlet-mapping 
    		name -->
    	<bean id="sfmeteo"
    		class="org.springframework.integration.http.HttpInboundEndpoint">
    		<property name="requestChannel" ref="sFMeteoInboundChannel" />
    		<property name="supportedMethods">
    			<list>
    				<value>POST</value>
    			</list>
    		</property>
    		<property name="requestMapper" ref="linefeedAwareInboundRequestMapper" />
    	</bean>
    Now i tried to use directly a inbound-channel adapter but the attribute requestMapper isn't available:
    Code:
    <si-http:inbound-channel-adapter id="sfmeteo" channel="sFMeteoInboundChannel" supported-methods="POST"/>
    How can i define a RequestMapper on an inbound-channel-adapter? I already read in the documentation and the forum as well, but didn't find an answer.

    regards
    angela

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

    Default

    Angela

    We probably have to upgrade the documentation and migration docs with that, but first see if these two issues are what you are looking for:
    https://jira.springsource.org/browse/INT-1751
    https://jira.springsource.org/browse/INT-1677

    Especially INT-1677 where we now have a SpEL support for mapping headers and payload from the request parameters.

  3. #3

    Default

    Hello

    I'm not sure if thats what i'm looking for. My requestMapper is of type

    Code:
    public class LinefeedAwareInboundRequestMapper implements InboundMessageMapper<HttpServletRequest> {
    .....
    }
    I still don't see how to define it on the inbound-channel-adapter. Could you please update the documentaion or give me any hints?

    Thanks & Regards
    Angela

  4. #4
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Hello, Angela
    I've investigated http:inbound-channel-adapter and InboundMessageMapper support.

    1. In the backend it is invoked HttpRequestHandlingEndpointSupport.doHandleRequest which convert HttpRequest using some appropriate strategy
    2. In the end it invokes sendAndReceiveMessage from its superclass MessagingGatewaySupport and only if expectReply = true
    3. That last one doesn't invoke requestMapper because our send-object is instanceof Message

    conclusion: requestMapper is unreachable and useless in SI-2.x

    So, why do you need solution with requestMapper? There are many messageConverters registered in the HttpRequestHandlingEndpointSupport which convert ServletServerHttpRequest to an object for payload.
    Please, look at these stack of messageConverters, maybe there is some converter for you.
    Or, also you can write your own implementation of HttpMessageConverter

    Good luck,
    Artem Bilan

  5. #5

    Default

    Hi all

    I already tried to write a custom implementation of a HttpMessageConverter which removes all linefeeds:

    Code:
    public class LinefeedMessageConverter extends AbstractXmlHttpMessageConverter {
    
    	private static final Logger LOG = LoggerFactory.getLogger(LinefeedMessageConverter.class);
    
    	/**
    	 * 
    	 */
    	@Override
    	protected Object readFromSource(Class clazz, HttpHeaders headers, Source source) throws IOException {
    		InputStream stream = ((StreamSource) source).getInputStream();
    		if (source == null) {
    			throw new MessageMappingException("No message data found!");
    		}
    		// can't use the encoding of the incoming request here.
    		String payload = IOUtils.toString(stream);
    		payload = stripNonValidXMLCharacters(payload);
    		MessageBuilder<String> builder = MessageBuilder.withPayload(payload);
    
    		return builder.toString();
    
    	}
    ......
    }

    Configuration:
    Code:
    <bean id="linefeedMessageConverter" class="com.namics.wetteralarm.queue.endpoint.LinefeedMessageConverter"/>
    	
    	<si-http:inbound-channel-adapter id="sfmeteo" channel="sFMeteoInboundChannel" supported-methods="POST" 
    		message-converters="linefeedMessageConverter"/>


    But I get the following exception:

    Code:
    26.10.11 09:52:40 56016 ERROR [task-scheduler-1] com.namics.wetteralarm.service.ErrorServiceImpl - [Payload=org.springframework.integration.transformer.MessageTransformationException: failed to transform message][Headers={timestamp=1319615560389, id=09718a5a-52ec-4676-93ff-43943f9e880b}]
    So you have any ideas where the problem is? I'm also missing a good documentation about these MessageConverters.

    Regards
    Angela

  6. #6
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Why do you use MessageBuilder inside your converter?
    You should return something for future payload of message in the HttpRequestHandlingEndpointSupport
    Please, read sources of last one.

  7. #7

    Default

    Thanks! It's working now! Using MessageBuilder was just copy/paste from the old code :-/

Posting Permissions

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