[英]Jersey Rest service only returning 404's
對於我的應用程序,我使用REST服務檢查帳戶數據。 我的Java類AuthenticationResource檢查此數據,然后將密鑰發送回客戶端。 一切正常,直到我嘗試將其趕到gitHub上。 這搞亂了我的項目,我不得不做一些事情。 現在一切都像它破裂之前一樣。 但是REST服務會繼續發送404。
我試圖更改web.xml和pom.xml中的所有內容,但這沒有用。 我還檢查了Java類本身。 我看不到任何問題
這是AuthenticationResource.Java:
package nl.hu.v1ipass.barapp.webservices;
@Path("/authentication")
public class AuthenticationResource {
final static public SecretKey key = MacProvider.generateKey();
@POST
@Produces("application/json")
public Response authenticateUser( @FormParam("kassanummer") int kassa,
@FormParam("username") int username,
@FormParam("password") String password) throws SQLException {
try {
// Authenticate the user against the database
UserPostgressDaoImpl dao = new UserPostgressDaoImpl();
String role = dao.findRoleForUser(kassa, username, password);
if (role == null) { throw new IllegalArgumentException("No user found!"); }
String token = createToken(Integer.toString(username), role);
SimpleEntry<String, String> JWT = new SimpleEntry<String, String>("JWT", token);
return Response.ok(JWT).build();
} catch (JwtException | IllegalArgumentException e)
{ return Response.status(Response.Status.UNAUTHORIZED).build(); }
}
private String createToken(String username, String role) throws JwtException {
Calendar expiration = Calendar.getInstance();
expiration.add(Calendar.MINUTE, 30);
return Jwts.builder()
.setSubject(username)
.setExpiration(expiration.getTime())
.claim("role", role)
.signWith(SignatureAlgorithm.HS512, key)
.compact();
}
}
我的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 web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>nl.hu.v1ipass.barapp.webservices</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/restservices/*</url-pattern>
</servlet-mapping>
</web-app>
最后我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>nl.hu.v1ipass</groupId>
<artifactId>barapp</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>barapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.26</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
</project>
希望有人看到我在做錯事情,謝謝。
一切看起來不錯,值得懷疑的是服務器啟動時。 您是否在跟蹤中看到任何錯誤/異常可以幫助您進一步診斷?
1.確保服務器在指定端口上正確啟動。 2.如果以上兩個步驟都可以正常工作,請確保端口上沒有其他應用程序正在運行,然后開始調試。3.通過在方法的第一行中放置一個調試點,確保執行點到達特定方法內部。逐行檢查是否缺少任何資源或路徑
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.