在我的 Java 应用程序中,所有 Rest 服务调用都出现以下错误,例如:
https://example.com/secselfservice/rest/ping
返回: HTTP 状态 500 - Authenticator.invoke() 失败
错误日志:
javax.servlet.ServletException: Authenticator.invoke() failed at
com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:174)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at
com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168)
at
com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94)
at
com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:38)
at
com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:807) Caused by:
java.lang.NullPointerException: while trying to invoke the method
java.lang.String.length() of a null object loaded from local variable
'name' at
org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:338)
at
org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:91)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:139)
at java.lang.ClassLoader.loadClass(ClassLoader.java:427) at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:174)
at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader.loadClass(BundleWebappClassLoader.java:298)
at java.lang.ClassLoader.loadClass(ClassLoader.java:427) at
org.apache.catalina.core.StandardWrapper.servletSecurityAnnotationScan(StandardWrapper.java:1211)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at
com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:170)
... 16 common frames omitted
这是我的 web.xml 的代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>secselfservice</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>com.sap.coe.securityselfservice.rest.SecSelfServApplication</servlet-name>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>com.sap.coe.securityselfservice.rest.SecSelfServApplication</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>user/Provider</res-ref-name>
<res-type>com.sap.security.um.user.UserProvider</res-type>
</resource-ref>
<resource-ref>
<res-ref-name>mail/SAPInternalNWCloudSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
</resource-ref>
<login-config>
<auth-method>FORM</auth-method>
</login-config>
<security-role>
<description>All SAP HANA Cloud Platform users</description>
<role-name>EVERYONE</role-name>
</security-role>
<security-role>
<description>Members of security team</description>
<role-name>Approver</role-name>
</security-role>
<security-role>
<description>Read only access to admin view</description>
<role-name>Viewer</role-name>
</security-role>
<security-role>
<description>Superadmin</description>
<role-name>Tester</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>all</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Approver</role-name>
<role-name>Viewer</role-name>
<role-name>Tester</role-name>
<role-name>EVERYONE</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<ejb-local-ref>
<ejb-ref-name>ejb/CustomDataEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Customization</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/MailTemplateEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.MailTemplates</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/QuestionEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Questions</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/UsrVariantEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.UsrVariants</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Projects</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectRequestEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.ProjectRequests</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/UserEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Users</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ResourcesEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Resources</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectAnswerObserverEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.observer.ProjectAnswerObserver</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectDataObserverEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.observer.ProjectDataObserver</local>
</ejb-local-ref>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>com.sap.coe.securityselfservice.rest.exception.WebServiceExceptionHandler</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
servlet SecSelfServApplication 的代码:
/**
* Application
*/
package com.sap.coe.securityselfservice.rest;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
/**
* JAX-RS Application
*/
public class SecSelfServApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(InitService.class);
s.add(MailTemplateService.class);
s.add(PingService.class);
s.add(ProjectRequestService.class);
s.add(ProjectService.class);
s.add(QuestionService.class);
s.add(ResourceService.class);
s.add(UserService.class);
s.add(UsrVariantService.class);
return s;
}
}
对于 PingService.java:
package com.sap.coe.securityselfservice.rest;
import javax.servlet.ServletException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
//import com.qmino.miredot.annotations.ReturnType;
import com.sap.coe.securityselfservice.rest.bean.WebServiceException;
import com.wordnik.swagger.annotations.ApiOperation;
/**
* Rest Service - Ping
*
* @author C5178621
* @servicetag Ping
*/
@Path("/ping")
public class PingService {
/**
* Ping the rest service application and check if it is alive
*
* @summary Test Application Alive
* @return "pong" if application is up and running
* @throws WebServiceException
*/
@GET
@Path("/")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "ping", notes = "ping", response = String.class)
public Response ping() throws ServletException {
return Response.ok().entity("pong").build();
}
}
还有 pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<parent>
<groupId>com.sap.it.mobile</groupId>
<artifactId>hcp-parent-pom</artifactId>
<version>2.3.3</version>
</parent>
<groupId>com.sap.coe</groupId>
<artifactId>SecSelfService</artifactId>
<version>1.1.14-SNAPSHOT</version>
<packaging>war</packaging>
<licenses>
<license>
<name>SAP DEVELOPER LICENSE AGREEMENT</name>
<url>https://tools.hana.ondemand.com/developer-license-3.1.txt</url>
</license>
</licenses>
<scm>
<url>git@github.example.corp:SRCOffice/SelfService_Backend.git</url>
<connection>scm:git:git@github.example.corp:SRCOffice/SelfService_Backend.git</connection>
<developerConnection>scm:git:git@github.example.corp:SRCOffice/SelfService_Backend.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
<java-version>1.7</java-version>
<war.name>secselfservice</war.name>
<sap.cloud.application>secselfservice</sap.cloud.application>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<!-- Project plugin versions -->
<version.eclipse-plugin>2.6</version.eclipse-plugin>
<version.shade-plugin>2.2</version.shade-plugin>
</properties>
<!--Use Java EE6-->
<profiles>
<profile>
<id>neo-javaee6-wp</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.13</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.sap.it.mobile</groupId>
<artifactId>hcp-java-util</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>secselfservice</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${version.eclipse-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${version.shade-plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
</plugins>
</pluginManagement>
</build>
</project>
任何人都知道如何解决这个问题?
谢谢