1

Currently I have a simple war that holds some spring integration configuration, and this war is deployed into a jetty container using this code:

protected void createWac(File file, ConnectorConfig config) throws Exception, InterruptedException {
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(file.getAbsolutePath());
    startServer(webapp, inboundConnector.getPort());
}

among the Spring Integration config, I have a int-http:inbound-gateway like this

<!-- External listener definition -->
<int-http:inbound-gateway id="entryHttpInboundGateway"
    request-channel="myRequestChannel"
    path="myPath" 
    reply-channel="myReplyChannel"
    request-payload-type="com.me.MyType"
    supported-methods="POST" message-converters="converters"
    reply-timeout="1000">
</int-http:inbound-gateway>

My goal is to have the values for myPath and the supported-methods values set up dynamically, the first approach I went was to have variables on my xml file as some people suggest on this post: how to read System environment variable in Spring applicationContext

for that I tried with this config

<!-- External listener definition -->
<int-http:inbound-gateway id="entryHttpInboundGateway"
    request-channel="myRequestChannel"
    path="#{ systemProperties['HTTP_PATH'] }" 
    reply-channel="myReplyChannel"
    request-payload-type="com.me.MyType"
    supported-methods="POST" message-converters="converters"
    reply-timeout="1000">
</int-http:inbound-gateway>

and setting the env on my machine, the weird thing is that when I set this, nothing happens, nor an config error, the initialization of the channel, or a property not found, I know, because if I remove the # sign, or put the actual url I get this on the console:

IntegrationRequestMappingHandlerMapping - Mapped "{[/{ systemProperties['HTTP_PATH'] }],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

Any ideas on how to solve this, or another approach to be able to inject the values to the war's context file before its deployed into the jetty container?

Community
  • 1
  • 1
Camilo Casadiego
  • 907
  • 3
  • 9
  • 33

1 Answers1

1

You have to take a look in to the Environment Abstraction in the Spring: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-environment

And consider some hook for your application in face of PropertySourcesPlaceholderConfigurer and looks like in your case for the ServletConfig:

For a common StandardServletEnvironment, the full hierarchy looks as follows, with the highest-precedence entries at the top: * ServletConfig parameters (if applicable, e.g. in case of a DispatcherServlet context) * ServletContext parameters (web.xml context-param entries) * JNDI environment variables ("java:comp/env/" entries) * JVM system properties ("-D" command-line arguments) * JVM system environment (operating system environment variables)

From other side consider to migrate to Spring Boot.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118