Extends ContainerRequestFilter / ContainerResponseFilter在JBOSS EAP 6.3中抛出class not found异常

时间:2015-06-28 03:26:49

标签: java web-services jboss jax-rs resteasy

我正在使用maven

创建REST API身份验证服务器
mvn archetype:generate -DarchetypeGroupId=org.jboss.aerogear.archetypes -DarchetypeArtifactId=jboss-html5-mobile-archetype -DarchetypeVersion=7.1.3.CR6 -Denterprise=true

这是我的RequestFilter:

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import duy.hw4.rest.HTTPHeaderName;
import duy.hw4.service.UserAuthenticator;

@Provider
@PreMatching
public class RESTRequestFilter implements ContainerRequestFilter {

    private final static Logger log = Logger.getLogger(RESTRequestFilter.class.getName());

    @Override
    public void filter(ContainerRequestContext requestCtx) throws IOException {

        String path = requestCtx.getUriInfo().getPath();
        log.info("Filtering request path: " + path);

        // IMPORTANT!!! First, Acknowledge any pre-flight test from browsers for this case before validating the headers (CORS stuff)
        if (requestCtx.getRequest().getMethod().equals("OPTIONS")) {
            requestCtx.abortWith(Response.status(Response.Status.OK).build());

            return;
        }

        // Then check is the service key exists and is valid.
        UserAuthenticator authenticator = UserAuthenticator.getInstance();
        String serviceKey = requestCtx.getHeaderString(HTTPHeaderName.SERVICE_KEY);

        if (!authenticator.isServiceKeyValid(serviceKey)) {
            // Kick anyone without a valid service key
            requestCtx.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());

            return;
        }

        // For any other methods besides login, the authToken must be verified
        if (!path.startsWith("/moneymanager/login/")) {
            String authToken = requestCtx.getHeaderString(HTTPHeaderName.AUTH_TOKEN);

            // if it isn't valid, just kick them out.
            if (!authenticator.isAuthTokenValid(serviceKey, authToken)) {
                requestCtx.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
            }
        }
    }
}

当我启动服务器并调用web服务时,我收到以下错误:

java.lang.RuntimeException: Unable to find a public constructor for class org.jboss.resteasy.core.AsynchronousDispatcher

搜索之后,我将提供的范围添加到resteasy-jaxrs依赖

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.11.Final</version>
        <scope>provided</scope>
    </dependency>

再次启动服务器时,我收到此错误:

Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/container/ContainerRequestFilter
    at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.8.0_45]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760) [rt.jar:1.8.0_45]
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:361) [jboss-modules.jar:1.3.3.Final-redhat-1]
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:482) [jboss-modules.jar:1.3.3.Final-redhat-1]
    ... 20 more
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.container.ContainerRequestFilter from [Module "deployment.moneymanager.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final-redhat-1]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final-redhat-1]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final-redhat-1]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final-redhat-1]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final-redhat-1]
    ... 24 more

有人可以帮帮我!

0 个答案:

没有答案