Announcement Announcement Module
Collapse
No announcement yet.
Usage of expressions in http namespace element 'url' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Usage of expressions in http namespace element 'url'

    I am using Springframework 3.0.5.RELEASE and Spring Integration 2.0.5.RELEASE.
    I am actually using http outbound gateway as following.

    Code:
    	<int-http:outbound-gateway 
    		id="netflixHttpOutBoundGateway"
    		request-channel="requestChannel"
    		url="http:/www.goforit.com/v1"
    		http-method="POST"
    		extract-request-payload="true" 
    		charset="UTF-8"		
    		request-timeout="1234" 
    		reply-channel="responseChannel"
    		request-factory="commonRequestFactory"		
    	/>
    Works as expected. However, when i change the above http namespace to use Spring expressions to extract information from message headers, i am getting exceptions.
    Code:
    	<int-http:outbound-gateway 
    		id="netflixHttpOutBoundGateway"
    		request-channel="requestChannel"
    		url="#{headers[url]}"
    		http-method="POST"
    		extract-request-payload="true" 
    		charset="UTF-8"		
    		request-timeout="1234" 
    		reply-channel="responseChannel"
    		request-factory="commonRequestFactory"		
    	/>
    The exception is
    Code:
    ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
    .......
    .........
    	at 
    org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
    	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:207)
    	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:71)
    	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
    	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
    	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)
    	at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:138)
    	... 27 more
    Aug 16, 2011 2:23:38 PM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
    	at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:141)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1287)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:224)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:200)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:616)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
    	at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
    	at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:207)
    	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:71)
    	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
    	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
    	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)
    	at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:138)
    	... 27 more
    Is this supported?
    I am planning to use http gateway for multiple outbound urls. The actual url is coming in message headers.

    Thanks
    sri

  • #2
    SpEL expressions of the form #{...} are evaluated once, when the application context is initialized.

    They are static and cannot use dynamic data such as information from a message.

    Instead, use a URI with ReST-like placeholders, and add <uri-variable/> elements to define the dynamic parts to fill in the placeholders.

    Here is an example...

    Code:
    	<int-http:outbound-gateway 
    		id="netflixHttpOutBoundGateway"
    		request-channel="requestChannel"
    		url="http://test/{foo}"
    		http-method="POST"
    		extract-request-payload="true" 
    		charset="UTF-8"		
    		request-timeout="1234" 
    		reply-channel="responseChannel"
    		request-factory="commonRequestFactory">
    	    <int-http:uri-variable name="foo" expression="headers.bar"/>
    	</int-http:outbound-gateway

    Comment


    • #3
      Thanks for the suggestion. This is what is working for me after making changes as per your suggestion.
      <int-http:outbound-gateway
      id="httpOutBoundGateway"
      request-channel="requestChannel"
      url="{url}"
      http-method="POST"
      extract-request-payload="true"
      charset="UTF-8"
      request-timeout="1234"
      reply-channel="responseChannel"
      request-factory="commonRequestFactory">
      <int-http:uri-variable name="url" expression="headers.url"/>
      </int-http:outbound-gateway>
      I am assuming that the underlying httpClient and its connection pool will appropriately pickup the http Connection based on different urls (HostConfiguration). I have to actually debug this and find out for sure though.
      I have 2 http outbound urls going to completely different clients. One is http and the other https. Also the request parameters are different.
      Let me know, if i am missing anything else. In due course of time there can be few more http clients who may need real time data for us and we are looking to consolidate all http based clients with one http gateway.
      Thanks
      sri

      Comment

      Working...
      X