servlet分配中的异常

时间:2022-04-05 21:13:09

I'm fighting the whole day with this: I want to call the connect service method from AuthentificationService I have this exception (the rest of the code at the bottom):

我正在与这一整天打架:我想从AuthentificationService调用connect服务方法我有这个异常(底部的其余代码):

06-May-2015 14:29:45.986 SEVERE [http-nio-8082-exec-28] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
 com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:847)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

06-May-2015 14:29:45.986 SEVERE [http-nio-8082-exec-28] org.apache.catalina.core.StandardWrapperValve.invoke Exception lors de l'allocation pour la servlet net.iots.iotshub.web.service.AuthentificationService
 com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:847)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

My Web.xml :

我的Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>AuthentificationService</servlet-name>
        <servlet-class>net.iots.iotshub.web.service.AuthentificationService</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AuthentificationService</servlet-name>
        <url-pattern>/rest/authentificationService</url-pattern>
    </servlet-mapping>
</web-app>

My Servlet class:

我的Servlet类:

@Path("authentificationService")
@ApplicationPath("/rest")
@Produces(value = MediaType.APPLICATION_JSON)
@Consumes(value = MediaType.APPLICATION_JSON)
public class AuthentificationService extends AbstractService {


    @GET
    @Produces(value = {MediaType.APPLICATION_JSON})
    @Path("connect")
    public User connect(@QueryParam("user") String id, @Context HttpServletRequest request) {
        JUser user = null;
        User connectedUser = null;
        try {
            user = new ObjectMapper().readValue(id, JUser.class);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException();
        }
        ..................
        request.getSession().setAttribute("connectedUser", connectedUser);

        return connectedUser;
    }

    @GET
    @Path("disconnect")
    public void disconnect(@Context HttpServletRequest request) {
        request.getSession().removeAttribute("connectedUser");
        request.getSession().invalidate();
        System.out.println(" LogOut ");
    }

    @GET
    @Path("isConnected")
    @Produces(value = {MediaType.APPLICATION_JSON})
    public User isConnected(@Context HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        System.out.println(" isConnected ");
        if (session != null) {
            if (session.getAttribute("connectedUser") != null) {
                return (User) session.getAttribute("connectedUser");
            } else {
                return null;
            }
        } else {
            return null;
        }

    }
}

my AngularJS service:

我的AngularJS服务:

cmlAppModule.factory('AuthentificationService', function ($resource) {

    return $resource('rest/authentificationService/:path',
            {path: '@path'},
    {
        disconnect: {
            method: 'GET',
            params: {
                path: "disconnect"
            }
        },
        isConnected: {
            method: 'GET',
            params: {
                path: "isConnected"
            }
        },
        connect: {
            method: 'GET',
            params: {
                path: "connect"
            }
        }
    });
});

Please if can anyone help me with this and provide the possible solution for it..

请问是否有人可以帮助我并提供可能的解决方案..

Thanks,

1 个解决方案

#1


There are so many things wrong on so many levels

在这么多层面上有太多错误

  1. There is no such word as "Authentification". It's "Authentication" :-)

    没有“认证”这样的词。这是“身份验证”:-)

  2. @ApplicationPath should be used on the application configuration class, not on your resource classes. For example

    @ApplicationPath应该在应用程序配置类上使用,而不是在资源类上使用。例如

    @ApplicationPath("/rest")
    public class AppConfig extends PackagesConfig {
        public AppConfig() {
            super("the.packages.to.scan.for.resources.and.provders");
        }
    }
    

    With this, you can get rid of our web.xml (or at least your attempted servlet configuration). This does pretty much the same thing. Change the package name to the package of your resources. And remove the @ApplicationPath from the resource class.

    有了这个,你可以摆脱我们的web.xml(或至少你尝试过的servlet配置)。这几乎完全相同。将包名称更改为资源包。并从资源类中删除@ApplicationPath。

  3. In your web.xml, you can't do

    在您的web.xml中,您无法做到

    <servlet>
        <servlet-name>AuthentificationService</servlet-name>
        <servlet-class>
            net.iots.iotshub.web.service.AuthentificationService
        </servlet-class>
    </servlet>
    

    unless AuthentificationService is an actual Servlet (which I can't tell as I don't know what AbstractService is. In any case, even if it was, this configuration still wouldn't work.

    除非AuthentificationService是一个实际的Servlet(我无法分辨,因为我不知道AbstractService是什么。无论如何,即使它是,但这种配置仍然不起作用。

#1


There are so many things wrong on so many levels

在这么多层面上有太多错误

  1. There is no such word as "Authentification". It's "Authentication" :-)

    没有“认证”这样的词。这是“身份验证”:-)

  2. @ApplicationPath should be used on the application configuration class, not on your resource classes. For example

    @ApplicationPath应该在应用程序配置类上使用,而不是在资源类上使用。例如

    @ApplicationPath("/rest")
    public class AppConfig extends PackagesConfig {
        public AppConfig() {
            super("the.packages.to.scan.for.resources.and.provders");
        }
    }
    

    With this, you can get rid of our web.xml (or at least your attempted servlet configuration). This does pretty much the same thing. Change the package name to the package of your resources. And remove the @ApplicationPath from the resource class.

    有了这个,你可以摆脱我们的web.xml(或至少你尝试过的servlet配置)。这几乎完全相同。将包名称更改为资源包。并从资源类中删除@ApplicationPath。

  3. In your web.xml, you can't do

    在您的web.xml中,您无法做到

    <servlet>
        <servlet-name>AuthentificationService</servlet-name>
        <servlet-class>
            net.iots.iotshub.web.service.AuthentificationService
        </servlet-class>
    </servlet>
    

    unless AuthentificationService is an actual Servlet (which I can't tell as I don't know what AbstractService is. In any case, even if it was, this configuration still wouldn't work.

    除非AuthentificationService是一个实际的Servlet(我无法分辨,因为我不知道AbstractService是什么。无论如何,即使它是,但这种配置仍然不起作用。