Utilisation de la dépendance Apache CXF cxf-rt-transports-http-jetty-3.1.4.jar
pour tester les services JAXRS. Voici les Junit annotations-Requête liée sans fil trouvée
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:test-spring-context.xml"})
web.xml (ne pense pas web.xml est chargé par @WebAppConfiguration
mais il est dans le répertoire classique src/main/webapp/WEB-INF/web.xml)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- listener to inject HttpServlet Request -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- CXF Servlet -->
<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>/service/*</url-pattern>
</servlet-mapping>
configuration jetée -
<httpj:engine-factory bus="cxf" id="port9191">
<httpj:engine port="9191">
<httpj:threadingParameters minThreads="5"
maxThreads="15" />
<httpj:handlers>
<bean class="org.eclipse.jetty.server.handler.DefaultHandler" />
</httpj:handlers>
<httpj:sessionSupport>true</httpj:sessionSupport>
</httpj:engine>
</httpj:engine-factory>
Obtenir ci-dessous exception en essayant de lire qu'il ader de @Autowired HttpServletRequest request
objet request.getHeader("ApplicationName");
-
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:309) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.access$400(WebApplicationContextUtils.java:64) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:325) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:320) ~[spring-web-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:307) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
Toute aide serait grandement appréciée!
_src/main/webapp/web.xml_ n'est pas l'emplacement standard. Placez-le dans _src/main/webapp/WEB-INF/web.xml_. Peut-être que c'est la raison pour laquelle il ne remarque pas que vous avez déclaré RequestContextListener en tant qu'auditeur. –
par erreur j'avais mis le mauvais chemin en post. Il est à l'intérieur de src/main/webapp/WEB-INF seulement. J'ai mis à jour la question maintenant. –