简体   繁体   English

宁静的Web服务对Java的帮助

[英]Restful webservices help in Java

Below is my code which is giving a null pointer exception on execution. 下面是我的代码,该代码在执行时给出了空指针异常。 Please help me resolve this issue: 请帮助我解决此问题:

@POST
@GET
@Path("/Auth/{uname}")
public String checkUserAccess(@PathParam("uname") String username) {
    String message = svc.checkUserAccess(username);
    return message;
}

Service Interface: 服务接口:

public String checkUserAccess(String id);

Service Implementation: 服务实施:

public String checkUserAccess(String id) {
    String message = Dao.checkUserAccess(id);
    return message;
}

DAO Interface: DAO介面:

public String checkUserAccess(String id);

DAO Implementation: DAO实施:

public String checkUserAccess(String id) {
    String result = null;
    String user = propertyProvider.getProperty("Auth");
    if (user.equalsIgnoreCase(id))
        result = "Valid User";
    else
        result = "Invalid User";
    return result;
}

I guess the line of code where you are getting user from property provider is causing the NullPointerException . 我猜想从属性提供者那里获取用户的代码行导致NullPointerException ie

String user = propertyProvider.getProperty("Auth");

I guess you are getting user as null . 我猜您正在将用户设置为null So if( user.equalsIgnoreCase(id) ) is throwing NullPointerException . 所以if( user.equalsIgnoreCase(id) )抛出NullPointerException Put a null check before authenticating the user. 在对用户进行身份验证之前,请先进行空检查。

if(user!=null && user.equalsIgnoreCase(id) ) {
    result = "Valid User"; 
else 
    result = "Invalid User"; 
return result; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM