我正在与这一整天打架:我想从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)
我的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>
我的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;
}
}
}
我的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"
}
}
});
});
请问是否有人可以帮助我并为此提供可能的解决方案..
谢谢,
答案 0 :(得分:0)
在如此多的层面上有太多错误
没有&#34; Authentification&#34;这样的词。它&#34;认证&#34; : - )
@ApplicationPath
应该在应用程序配置类上使用,而不是在资源类上使用。例如
@ApplicationPath("/rest")
public class AppConfig extends PackagesConfig {
public AppConfig() {
super("the.packages.to.scan.for.resources.and.provders");
}
}
有了这个,您可以摆脱我们的web.xml(或者至少是您尝试过的servlet配置)。这几乎完全相同。将包名称更改为资源包。并从资源类中删除@ApplicationPath
。
在您的web.xml中,您无法
<servlet>
<servlet-name>AuthentificationService</servlet-name>
<servlet-class>
net.iots.iotshub.web.service.AuthentificationService
</servlet-class>
</servlet>
除非AuthentificationService
是一个真正的Servlet(我无法告诉我,因为我不知道AbstractService
是什么。无论如何,即使它是,这个配置仍然不会工作。