Home » Newcomers » Newcomers » Inject attribute into Apache CXF servlet (from Spring, over Jetty, to Apache CXF)
Inject attribute into Apache CXF servlet (from Spring, over Jetty, to Apache CXF) [message #1098877] |
Sat, 31 August 2013 21:03 |
Jana Weschenfelder Messages: 6 Registered: August 2013 |
Junior Member |
|
|
Dear Ladies and Gentlemen,
I have a problem and maybe someone can help me here:
The problem is described in the forum of Spring. I will copy the whole content in
my next response to this post, since Eclipse does not allow links for new people.
It cost me 3 days of my time already and I am really stuck now...
I am working with a JAR file and not with a WAR file.
I would like to use the ServletContextAware interface to get the
ServletContext, but it would only work with the ContextLoaderListener as
far as I have found out. But ContextLoaderListener is from Spring (like
ServletContextAware), as the classpath
"org.springframework.web.context.ContextLoaderListener" says and the
ServletContextHandler is from Eclipse as the classpath
"org.eclipse.jetty.servlet.ServletContextHandler" tells, while the
CXFServlet uses Apache CXF classes
("org.apache.cxf.transport.servlet.CXFServlet"). I think that might be the
problem, because 3 institutions are involved here. I do not know how
much compatible all three are, since I have not found a documentation for
such a case. Every institutions only describes its part in the main, but
not a combination of all three together.
I am sorry, if it is posted below the Spring forum and here, but I am not a
professional here and I do not really know who to ask here since 3 institutions
are involved here.
Have you an idea how I can pass an attribute from Spring over Jetty to Apache CXF?
Any help is highly appreciated. I tried already many, many ways, but the
ServletContext is null then. If this forum feels responsible for this problem, I
would delete my other post in the other forum again.
Many thanks,
Jana
|
|
|
Re: Inject attribute into Apache CXF servlet (from Spring, over Jetty, to Apache CXF) [message #1099068 is a reply to message #1098877] |
Sun, 01 September 2013 04:30 |
Jana Weschenfelder Messages: 6 Registered: August 2013 |
Junior Member |
|
|
Okay, now the more detailed information, it would have been here earlier if it wouldn't need an approval of the Eclipse admin every time:
From the Spring Forum:
"Hello,
I am new to Spring and I am working on a Maven multi-module project where Spring is used.
My problem is that I try to inject an attribute or bean into a Apache CXF servlet. On the other side, I want to extract the ServletContext and that attribute there again. The problem sounds simple.
Since the parent project has a web module already, it is wanted that my module is not a web application project.
So I have a following construct: An existing web application (based on Spring, with applicationContext.xml and web.xml) which starts an Apache CXF server with JAX-RS support) is embedded in my non-web application module (Maven project) as dependency/as JAR file via my POM.xml. The existing web application is the official CDMI Reference Implementation from SNIA.ORG in this case. But I think that information is less important.
My project has an own XML-based configuration file that starts the CDMI RI (which is a JAR dependency in my project) as follows:
<bean id="server" class="org.eclipse.jetty.server.Server"
init-method="start" destroy-method="stop">
<description>Jetty server hosting the web application</description>
<property name="gracefulShutdown" value="${cdmi.limits.jetty.graceful-shutdown}"/>
<property name="threadPool" ref="thread-pool"/>
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8542" />
<property name="host" value="#{ T(com.google.common.base.Strings).emptyToNull( '${cdmi.net.listen}' ) }"/>
</bean>
</list>
</property>
<property name="handler">
<bean class="org.eclipse.jetty.server.handler.HandlerList">
<property name="handlers">
<list>
<bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
<!-- <bean class="org.springframework.web.context.ContextLoaderListener"> -->
<bean class="org.eclipse.jetty.servlet.ServletContextHandler">
<property name="contextPath" value="/cdmi-server" /> <!-- here -->
<property name="servletHandler">
<bean class="org.eclipse.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.eclipse.jetty.servlet.ServletHolder">
<property name="name" value="cdmi-server" />
<property name="servlet">
<bean class="org.apache.cxf.transport.servlet.CXFServlet" />
</property>
<property name="initParameters">
<map>
<entry key="contextConfigLocation" value="classpath:cxf-jsr-config.xml" />
</map>
</property>
<property name="attributes">
<bean class="org.eclipse.jetty.util.AttributesMap">
<constructor-arg>
<map>
<entry key="org.dcache.cdmi.container" value-ref="container"/>
</map>
</constructor-arg>
</bean>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.eclipse.jetty.servlet.ServletMapping">
<property name="servletName" value="cdmi-server" />
<property name="pathSpec" value="/*" />
</bean>
</list>
</property>
</bean>
</property>
</bean>
<bean class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</list>
</property>
</bean>
</property>
</bean>
The cxf-jsr-config.xml is the former applicationContext.xml of the CDMI RI and includes the Apache CFX configuration and JAX-RS resources. It is included in the XML file of my project, too. The servlet gets started, I can see it in my web browser, it works fine so far. That means, the code of the cxf-jsr-config.xml looks like this plus some Spring beans:
<context:annotation-config/>
<!-- Register autowired components -->
<context:component-scan base-package="org.snia.cdmiserver"/>
<!-- Apache CXF Core Configuration -->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxrs:server id="cdmiService" address="/" beanNames="objectIdResource pathResource">
...
</jaxrs:server>
...
My problem are those lines of my XML-based configuration file of my project (see first code snippet):
<property name="attributes">
<bean class="org.eclipse.jetty.util.AttributesMap">
<constructor-arg>
<map>
<entry key="org.dcache.cdmi.container" value-ref="container"/>
</map>
</constructor-arg>
</bean>
</property>
"container" is a Spring bean which is in my XML file as well:
<bean id="container" class="org.dcache.cdmi.dao.ContainerDaoImpl"
init-method="start" destroy-method="stop">
<property name="pnfsStub" ref="pnfs-stub"/>
<property name="pnfsHandler" ref="pnfs-handler"/>
<property name="listDirectoryHandler" ref="list-handler"/>
</bean>
Within the ContainerDaoImpl.java which implements an interface of the CDMI RI (which is the CXFServlet), I have implemented the org.springframework.web.context.ServletContextAwar e interface. And I try to extract the ServletContext and the attribute with Object attribute = servletContext.getAttribute("org.dcache.cdmi.conta iner") there again. Before that I try to get the servletContext with the function "@Override public void setServletContext(ServletContext ctx) { this.servletContext = ctx; }". But this function never gets called and so the servletContext is null.
I have searched for a solution here many, many hours already, but I don't find an example or tutorial which solves the problem in a similar way or I am just entering the wrong keywords in the Google search.
Can someone please point me the right direction? What am I doing wrong?
I have tried this already, but it doesn't work, too (It seems that I would have to implement a HTTPServlet here which I have already with the CDMI RI):
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.dcache.cdmi.container">
<ref bean="container" />
</entry>
</map>
</property>
</bean>
Many thanks in advance (I am sorry for some mistakes in my post, I am not a native English speaker),
Jana"
I think that might explain my problem better now. An answer would be highly appreciated. Many thanks!!!
Jana
|
|
| | | | |
Goto Forum:
Current Time: Thu Apr 18 16:30:38 GMT 2024
Powered by FUDForum. Page generated in 0.03534 seconds
|