Results 1 to 5 of 5

Thread: Possible to pass the http outbound-gateway output to an xpath-transformer

  1. #1
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Question Possible to pass the http outbound-gateway output to an xpath-transformer

    I'm sure it's possible, but can't seem to figure it out. My app makes a POST request for some HTML and I'd like to somehow just retrieve a certain part of the HTML document. So I've set my expected-response-type as javax.xml.transform.Source. The response goes to a channel that will eventually have an xpath-expression for the node of HTML I want, but for now I'm simply testing to at least get an attribute value from the html root element.

    At first when I ran my app, it told me that no MessageConverter could be found for javax.xml.transform.Source, so I created my own list of messageConverters and referenced it on the message-converters attribute. The list contains a SourceHttpMessageConverter. However when I run the app, I still get the same error. Maybe I'm not taking the correct approach.

    Code:
    	<channel id="conferenceStandingsRequestChannel"/>
    	
    	<int-http:outbound-gateway id="conferenceStandings"
    		request-channel="conferenceStandingsRequestChannel"
    		url="${nhl.conference.standings.url}"
    		http-method="POST"
    		expected-response-type="javax.xml.transform.Source"
    		charset="UTF-8"
    		reply-channel="conferenceStandingsResponseChannel"
    		message-converters="messageConverters">
    		<int-http:uri-variable name="season" expression="payload"/>
    	</int-http:outbound-gateway>
    	
    	<int-xml:xpath-transformer input-channel="conferenceStandingsResponseChannel"
    		output-channel="myChannel"
    		xpath-expression="/html/@xmlns"
    		evaluation-type="STRING_RESULT"/>
    	
    	<service-activator input-channel="myChannel"
    		ref="conferenceStandingsMessageHandler" method="handleMessage"/>
    		
    	<util:list id="messageConverters">
    		<beans:bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
    		<beans:bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
    	</util:list>

  2. #2
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    I've also tried an expected-response-type="org.w3c.dom.Document" with the same result.

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    Can you provide the relevant excerpt of the stack trace from that exception?

  4. #4
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    Hi Mark, here is my stack trace. I get the same exception when setting expected-response-type to either org.w3c.dom.Document or javax.xml.transform.Source.

    Code:
    Exception in thread "main" org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [http://www.nhl.com/ice/standings.htm?season={season}&type=con]
    	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:262)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:98)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:110)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:44)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
    	at com.myco.pools.nhl.ConferenceStatsRequester.requestConferenceStandings(ConferenceStatsRequester.java:47)
    	at com.myco.pools.nhl.StatConsumer.consumeStats(StatConsumer.java:105)
    	at com.myco.pools.nhl.Client.main(Client.java:64)
    Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [org.w3c.dom.Document] and content type [text/html;charset=UTF-8]
    	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:77)
    	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:619)
    	at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:1)
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:446)
    	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
    	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:384)
    	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:240)
    Last edited by pgrimard; Mar 30th, 2011 at 06:22 AM.

  5. #5
    Join Date
    Nov 2009
    Location
    Montreal, Quebec
    Posts
    398

    Default

    Well I managed to get what I needed. I quickly determined that expecting a Source or Document as the response type was probably not going to work, and trying to get some kind of xpath expression working correctly on the returned HTML would be an even bigger challenge.

    What I ended up doing (over 2 days of work) was creating my own @Transformer which accepts the http outbound-gateway response as a String payload. I then create a org.w3c.dom.Document from that payload and perform various operations on it, all to return a List of domain objects for the data I was interested in. That List is then passed off to a service-activator.

    The lesson I learned from all of this? Creating my own transformers is cool!

Posting Permissions

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