无法通过@Context jersey2.x和weblogic 12.1.3在ContainerRequestFilter中注入HttpServletRequest [英] Cannot inject HttpServletRequest in ContainerRequestFilter via @Context jersey2.x and weblogic 12.1.3

查看:85
本文介绍了无法通过@Context jersey2.x和weblogic 12.1.3在ContainerRequestFilter中注入HttpServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用weblogic 12.1.3通过Jersey 2.22.1中的@Context在ContainerRequestFilter中注入HttpServletRequest.我研究了存在此问题的几个地方,并且在许多地方我看到它在Jersey 2.4中已修复,但是我仍然看到此问题.我的实现和代码已随附.如果我有任何遗漏,请告诉我.

I was not able to inject HttpServletRequest in ContainerRequestFilter via @Context in Jersey 2.22.1 using weblogic 12.1.3. I researched several places that this issue exists and in many places I see that it is fixed in Jersey 2.4, but I am still seeing this issue. My implementation and code is attached. Please let me know if I am missing anything.

AuthFilter

AuthFilter

@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthFilter implements ContainerRequestFilter {
    @Context
    HttpServletRequest webRequest;

    @Context
    HttpServletResponse webResponse;

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        final HttpSession session = webRequest.getSession();
        final String userName = (String)session.getAttribute("USER_NAME");

web.xml

<servlet>
        <servlet-name>jersey-application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
                  <param-name>jersey.config.server.provider.packages</param-name>
                  <param-value> xyz.xyz.xyz.xyz.xyz.resource</param-value>
              </init-param>

    </servlet>
    <servlet>
        <servlet-name>authentication-servlet</servlet-name>
        <servlet-class>xyz.xyz.xyz.xyz.xyz.xyz.AuthenticationServlet</servlet-class>

    </servlet>
    <servlet-mapping>
        <servlet-name>jersey-application</servlet-name>
        <url-pattern>/jaxrs/*</url-pattern>
    </servlet-mapping>

Pom.xml

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.22.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-moxy</artifactId>
    <version>2.22.1</version>
</dependency>

<dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <version>2.22.1</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-context</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-beans</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-core</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-web</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jersey-server</artifactId>
                <groupId>org.glassfish.jersey.core</groupId>
            </exclusion>
            <exclusion>
                <artifactId>
                    jersey-container-servlet-core
                </artifactId>
                <groupId>org.glassfish.jersey.containers</groupId>
            </exclusion>
            <exclusion>
                <artifactId>hk2</artifactId>
                <groupId>org.glassfish.hk2</groupId>
            </exclusion>
        </exclusions>
    </dependency>

Weblogic.xml

Weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
     <library-ref>
         <library-name>jax-rs</library-name>
         <specification-version>2.0</specification-version>
         <implementation-version>2.5.1</implementation-version>
    </library-ref>
    <container-descriptor>
    <prefer-application-packages>
        <!-- jsr311 -->
        <package-name>javax.ws.rs.*</package-name>
        <!-- javassist -->
        <package-name>javassist.*</package-name>
        <!-- aop repackaged -->
        <package-name>org.aopalliance.*</package-name>

        <!-- jersey 2 -->
        <package-name>jersey.repackaged.*</package-name>
        <package-name>org.glassfish.jersey.*</package-name>
        <package-name>com.sun.research.ws.wadl.*</package-name>

        <!-- hk2 -->
        <package-name>org.glassfish.hk2.*</package-name>
        <package-name>org.jvnet.hk2.*</package-name>
        <package-name>org.jvnet.tiger_types.*</package-name>
    </prefer-application-packages>
        <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
        <resource-reload-check-secs>0</resource-reload-check-secs>
    </container-descriptor>
    <context-root>XYZ</context-root>

</weblogic-web-app>

我看到的错误在下面

Root cause of ServletException.
A MultiException has 4 exceptions.  They are:
1. java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
2. java.lang.IllegalArgumentException: While attempting to create a Proxy for javax.servlet.http.HttpServletRequest in scope org.glassfish.jersey.process.internal.RequestScoped an error occured while creating the proxy
3. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of xyz.xyz.xyz.xyz.xyz.xyz.xyz.AuthFilter errors were found
4. java.lang.IllegalStateException: Unable to perform operation: resolve on xyz.xyz.xyz.xyz.xyz.xyz.xyz.AuthFilter

    at org.jvnet.hk2.internal.Collector.throwIfErrors(Collector.java:89)
    at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:249)
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)

如果有任何解决此问题的方法,请告诉我.

推荐答案

似乎这是Weblogic 12.1.3的错误.我尝试升级到Weblogic 12.2.1并使用@Context注入HttpServletRequest,即使在ContainerRequestFilter内部也可以正常工作.

It seems this is a bug with Weblogic 12.1.3. I tried upgrading to Weblogic 12.2.1 and injecting HttpServletRequest using @Context works correctly even inside ContainerRequestFilter.

这篇关于无法通过@Context jersey2.x和weblogic 12.1.3在ContainerRequestFilter中注入HttpServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆