You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Rene Richard <re...@nrc.gc.ca> on 2008/09/26 16:15:51 UTC
Accessing properties file content
Hello,
I would like to read a properties file and get configuration information to
feed into my web service (all of this inside a tomcat container).
I have a hello world web service and I would like to read a properties file
and respond with something inside it. How do I get the servlet context from
inside a CXF web service?
I can also configure this as a Spring bean with properties set in the
configuration file. I don't know how to get the spring context either..
Can someone provide a hint?
R.
Re: Accessing properties file content
Posted by Daniel Kulp <dk...@apache.org>.
On Friday 26 September 2008 10:15:51 am Rene Richard wrote:
> Hello,
>
>
> I would like to read a properties file and get configuration information to
> feed into my web service (all of this inside a tomcat container).
>
> I have a hello world web service and I would like to read a properties file
> and respond with something inside it. How do I get the servlet context from
> inside a CXF web service?
In your service, you can have a
@Resource
WebServiceContext ctx;
thing and for each invoke, you can get the Servlet context out of it.
> I can also configure this as a Spring bean with properties set in the
> configuration file. I don't know how to get the spring context either..
If it's in spring config, just let spring inject it into your bean.
Dan
> Can someone provide a hint?
>
> R.
--
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog
Re: Accessing properties file content
Posted by ha...@raceeend-2.demon.nl.
> Hello,
>
>
> I would like to read a properties file and get configuration information to
> feed into my web service (all of this inside a tomcat container).
>
> I have a hello world web service and I would like to read a properties file
> and respond with something inside it. How do I get the servlet context from
> inside a CXF web service?
>
> I can also configure this as a Spring bean with properties set in the
> configuration file. I don't know how to get the spring context either..
>
> Can someone provide a hint?
>
> R.
>
>
I guess you mean this?
Filename:service_ws.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:wsa="http://cxf.apache.org/ws/addressing"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>${jboss.server.config.url}/props/myprops.properties</value>
</property>
</bean>
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="dbConnection" class="a.b.c.DBConnection">
<property name="jdbcDriver" value="${one.two.jdbc.driver}"/>
<property name="jdbcUrl" value="${one.two.jdbc.url}"/>
<property name="jdbcUser" value="${one.two.jdbc.user}"/>
<property name="jdbcPwd" value="${one.two.jdbc.password}"/>
</bean>
and so on...
You see, the properties file 'myprops.properties' is accesible over the predefined JBOSS property '${jboss.server.config.url}'.
But the use of the JBOSS property is of course optional. Any valid path suffices.
After the property file is read, the property values are directly usable for initialising your beans,
i.e. : <property name="jdbcDriver" value="${one.two.jdbc.driver}"/>
The above file is referred to in web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebService"
version="2.5">
<display-name>WebService</display-name>
<description>WebService</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/service_ws.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>WebService</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<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>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
So during startup the whole mess is activated...
Bye,
Harry van Rijn
Re: Accessing properties file content
Posted by Adrian Corcoran <ad...@gmail.com>.
look at PropertyPlaceholderConfigurer
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html#beans-factory-placeholderconfigurer
On Fri, Sep 26, 2008 at 3:15 PM, Rene Richard <re...@nrc.gc.ca>wrote:
> Hello,
>
>
> I would like to read a properties file and get configuration information to
> feed into my web service (all of this inside a tomcat container).
>
> I have a hello world web service and I would like to read a properties file
> and respond with something inside it. How do I get the servlet context from
> inside a CXF web service?
>
> I can also configure this as a Spring bean with properties set in the
> configuration file. I don't know how to get the spring context either..
>
> Can someone provide a hint?
>
> R.
>
>