Hi Paul
Thanks for the explanation, I guess it does not work because CXFServlet
parameters are not visible to a web.xml-'global' application context
which can be shared between multiple servlets, so injecting a servlet
specific parameters into this context would be wrong.
Try using a CXFServlet config-location init param instead of a context
contextConfigLocation to refer to the application context, perhaps it
will make the init parameters visible
Cheers, Sergey
Try setting the application context
On 26/01/16 10:34, Paul Millar wrote:
Hi Sergey,
On 19/01/16 12:58, Sergey Beryozkin wrote:
> Sorry for a delay.
Sorry for my delay!
I'm not sure I understand, so you'd like to have some context-params and
CXFServlet specific init-params set in a given web.xml and make them
available to the application context ?
Can you please show some configuration fragments which will help to
understand what exactly are you trying to achieve ?
A little bit of background.
I've "inherited" a rather basic servlet that I'm trying to bring into a
reasonable shape. It provides support for a network protocol, using a
directory to store some state.
Currently, the directory it uses is hardcoded as '/data'. I would like
to expose this as a configuration option for two reasons:
a. Using '/data' might not be convenient for all users.
b. I'm adding integration testing as part of the maven build process
and I want to run the servlet (from within maven) but configuring
it to use a path within the maven-project's 'target' directory.
I believe init-param is the implementation-agnostic way of configuring a
servlet. Given I want to expose a single string argument, this seemed
appropriate.
I would also like to avoid introducing CXF-specific code in the
application: the servlet should work with any JAX-RS implementation.
Therefore, it looked like injecting the init-param as a spring argument
is the way forward and an initial scan of CXF code-base suggests that
CXF servlet transport does inject the key-value pairs from init-param
arguments into a named Spring bean; however, when I try this it doesn't
work.
Here are some details. The web.xml:
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>filesystemBaseDirectory</param-name>
<param-value>/home/paul/test-dir</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Some fragments from applicationContext.xml, omitting some unrelated parts.
<beans ...>
<context:annotation-config/>
<!-- context:component-scan .../> -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!-- ... -->
<bean id="containerDao" class="...">
<property name="baseDirectoryName"
value="#{contextParameters['filesystemBaseDirectory']}"/>
</bean>
</beans>
With the above configuration, the SpEL reference
#{contextParameters['filesystemBaseDirectory']} expands to null.
If I add context-param declaration to web.xml then the SpEL expression
expands to the correct value.
Any ideas how to get init-param to work?
Cheers,
Paul.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/