简体   繁体   English

球衣过滤器在Tomcat上引发异常

[英]jersey filter throwing exception on Tomcat

I'm trying to implement rest token security between my clients and webserver. 我正在尝试在我的客户端和网络服务器之间实施其余令牌安全性。 I implemented a filter to get the http authentiction header and check if the client is valid. 我实现了一个过滤器,以获取http身份验证标头,并检查客户端是否有效。 Although, for some reason my Tomcat is throwing an exception end starts. 虽然,由于某种原因,我的Tomcat引发异常结束,但该异常开始。

My implementation of the filter is: 我对过滤器的实现是:

import java.security.Principal;

    import javax.ws.rs.NotAuthorizedException;
    import javax.ws.rs.container.ContainerRequestContext;
    import javax.ws.rs.container.ContainerRequestFilter;
    import javax.ws.rs.core.HttpHeaders;
    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.SecurityContext;
    import javax.ws.rs.ext.Provider;
    import javax.annotation.Priority;
    import javax.ws.rs.Priorities;


        @Secured
        @Provider
        @Priority(Priorities.AUTHENTICATION)
        public class AuthenticationFilter implements ContainerRequestFilter {

            @Override
            public void filter(ContainerRequestContext requestContext) throws IOException {...}

The exception I get from Tomcat is: 我从Tomcat得到的异常是:

 br 05, 2017 12:09:13 PM org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: Servlet.service() for servlet [JAX-RS Servlet] in context with path [/My_App] threw exception [Servlet execution threw an exception] with root cause
    java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
        at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:120)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

I have thim POM: 我有thim POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SamuraiForge</groupId>
  <artifactId>0</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>

    </plugins>
  </build>

    <dependencies>

        <dependency>
            <groupId>net.snaq</groupId>
            <artifactId>dbpool</artifactId>
            <version>7.0.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.codehaus.jettison/jettison -->
        <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.3.8</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.8.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.8.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.0.0</version>
        </dependency>



        <!-- https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.7.24</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.24</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.24</version>
</dependency>

<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901-1.jdbc4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.19.3</version>
    <exclusions>
        <exclusion>
            <artifactId>jsr311-api</artifactId>
            <groupId>javax.ws.rs</groupId>
        </exclusion>
    </exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.19.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-servlet -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.19.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-json -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.19.3</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1-m05</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-jaxrs -->
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-jaxrs</artifactId>
    <version>1.9.13</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl -->
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>

    </dependencies>
</project>

Any idea? 任何想法?

As mentioned by Andreas, remove 如Andreas所述,删除

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.1-m05</version>
</dependency>

This is the cause of the error. 这是错误的原因。 But you seems to be trying to actually use it. 但是您似乎正在尝试实际使用它。 The ContainerRequestFilter you are using, is something that is JAX-RS 2.0, but you are using Jersey 1.x, which is JAX-RS 1.x. 您使用的ContainerRequestFilter是JAX-RS 2.0,但您使用的是Jersey 1.x,即JAX-RS1.x。 You can't use some of the JAX-RS 2 APIs in JAX-RS 1.x. 您不能在JAX-RS 1.x中使用某些JAX-RS 2 API。 This includes the ContainerRequestFilter . 这包括ContainerRequestFilter

Jersey 1.x has a filter ContainerRequestFilter , but the API is little different. Jersey 1.x具有过滤器ContainerRequestFilter ,但API几乎没有什么不同。 You can use this with Jersey 1.x, but it doesn't have some of the features that the JAX-RS ContainerRequestFilter has. 您可以在Jersey 1.x中使用它,但是它不具有JAX-RS ContainerRequestFilter具有的某些功能。 For instance there is no such concept of SecurityContext with the Jersey filter. 例如,没有带有Jersey过滤器的SecurityContext这样的概念。 So you will be able to do setSecurityContext(new YouSecurityContext()) . 因此,您将能够执行setSecurityContext(new YouSecurityContext()) This may be a problem for you, since it looks like this is what you are using the filter for. 这可能对您来说是个问题,因为看起来这就是您使用过滤器的目的。 You will need to figure some other way to do it. 您将需要找到其他方法来做到这一点。 Otherwise, you will need to make the complete switch to Jersey 2.x, where you can use JAX-RS 2 否则,您将需要完全切换到Jersey 2.x,可以在其中使用JAX-RS 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM