简体   繁体   English

Java Restful Web服务登录凭证失败

[英]Java Restful Web Service Login Credential Failure

So I built out a Java web service to connect to a mobile android app I'm developing. 因此,我建立了一个Java Web服务来连接到我正在开发的移动android应用程序。 I'm new to Java & Android, and I'm have a bit of difficulty. 我是Java和Android的新手,但遇到了一些困难。 I've got my android to send the login details to the Restful Web Service, but the restful web service fails when it tries to verify the details in the DB table made for users. 我已经将Android的登录详细信息发送到Restful Web Service,但是Restful Web Service在尝试验证为用户创建的数据库表中的详细信息时会失败。 I know it's the check credential issue because when I comment out the check credentials statement it will let me login. 我知道这是支票凭证问题,因为当我注释掉支票凭证声明时,它将让我登录。 I can't figure out where I went wrong in the credential verification statement in my code, is someone could help out that would be great. 我无法弄清楚我的代码中的凭证验证语句出了什么问题,有人可以帮忙,那会很棒。 The Login.class of my Restful service is below. 我的Restful服务的Login.class在下面。 Also I'm running everything off of tomcat7. 我也正在运行所有的tomcat7。

private boolean checkCredentials(String uname, String pwd){

        System.out.println("Inside checkCredentials");
        boolean result = false;
        if(Utitlity.isNotNull(uname) && Utitlity.isNotNull(pwd)){
            try {
                result = DBConnection.checkLogin(uname, pwd);
               // System.out.println("Inside checkCredentials try "+result);
            } catch (Exception e) {
                // TODO Auto-generated catch block
              //  System.out.println("Inside checkCredentials catch");
                result = false;
            }
        }else{
            System.out.println("Inside checkCredentials else");
            result = false;
        }

        return result;
    }

There are several issues with your code. 您的代码有几个问题。 The main one is that you handle any Exception thrown in the checkLogin() as just a regular "did not check out" case. 主要的问题是,您可以将处理在checkLogin()抛出的所有异常作为常规的“未检出”情况处理。

Do you really want to silently ignore any system failure, and handle it just like a valid business case? 您是否真的想静默地忽略任何系统故障,并像有效的业务案例一样处理它?

I'm not saying that this is wrong in every case, but make it a explicit design decision, and at least log some information on the exception, so you can see that something is wrong. 我并不是说这在每种情况下都是错误的,而是要做出明确的设计决策,并且至少记录一些有关异常的信息,以便您可以看到错误之处。

Better yet, limit the catch-clause to the Exceptions you really expect to be thrown. 更好的是,将限制条款限制为您真正希望引发的异常。 (And even then, log information on the Exception!) (即使那样,也请记录有关异常的信息!)

The usage of static methods like DBConnection.checkLogin() indicate more design problems. 诸如DBConnection.checkLogin()类的静态方法的使用表明了更多的设计问题。 It might work, and be convenient in some cases, but it will bite you in the long run. 它可能会起作用,并且在某些情况下会很方便,但是从长远来看,它会咬住您。

So, to find your immediate problem: print the stack trace of the Exception in the catch clause. 因此,要查找您的紧迫问题:在catch子句中打印Exception的堆栈跟踪。 Also log the result of the checkLogin() call right after the call, still in the try-block. 还要在调用之后立即在try块中记录checkLogin()调用的结果。 If that information is printed, no Exception was thrown, and your problem lies within checkLogin() . 如果打印了该信息,则不会引发Exception,并且您的问题出在checkLogin()

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

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