2017-04-16 5 views
0

저는 기존 GWT 프로젝트를 변환하기 위해 부트 스트랩을 사용하기 시작했습니다. 원래의 rpc 호출은 다음 코드에서 작동합니다. 그러나 대체 코드는 원본 코드와 "연결에 실패했습니다. 다시 시도하십시오." 트리거 될 때 팝업으로 화면에 표시됩니다. 로그에 아무 것도 없습니다. 창에 올바른 값이 표시됩니다. 부트 스트랩이 작동하면 원본 코드를 대체합니다. 다음 오류가 반환이 계정이 잘못GWT 자바 rpc 호출 작동; 그러나 대체 GWTBootstrap - rpc 호출이 작동하지 않습니다.

if (stored_hash == null){ 
     System.out.println("Incorrect account."); 
     account = null; 
    }else{ 
     //Check that the hashed value of the password equals the stored hashed value 
     //If it does not then account will be set to null. 
     if (BCrypt.checkpw(pass, stored_hash)) { 
      System.out.println("Success!"); 
     }else{ 
      System.out.println("Incorrect password."); 
      account = null; 
     } 
    } 
    //Done 
    return account; 

경우 (즉, BCrypt 사용하지 않는) :

package org.AwardTracker.client; 
/** 
* The purpose of this View is to allow the account holder 
* to login to their account using an Account Name and password. 
*/ 

import com.google.gwt.user.client.ui.Composite; 
import com.google.gwt.user.client.ui.RootPanel; 
import com.google.gwt.user.client.ui.VerticalPanel; 
import com.google.gwt.user.client.ui.Label; 
import com.google.gwt.user.client.ui.FlexTable; 
import com.google.gwt.user.client.ui.TextBox; 
import com.google.gwt.user.client.ui.PasswordTextBox; 
import com.google.gwt.user.client.ui.Button; 
import com.google.gwt.core.client.GWT; 
import com.google.gwt.dom.client.Document; 
import com.google.gwt.event.dom.client.ClickHandler; 
import com.google.gwt.event.dom.client.ClickEvent; 
import com.google.gwt.event.logical.shared.AttachEvent; 
import com.google.gwt.event.logical.shared.AttachEvent.Handler; 
import com.google.gwt.user.client.History; 
import com.google.gwt.user.client.Window; 
import com.google.gwt.user.client.rpc.AsyncCallback; 
import com.google.gwt.user.client.rpc.ServiceDefTarget; 
import com.google.gwt.user.client.ui.HorizontalPanel; 
import com.google.gwt.user.client.ui.HasHorizontalAlignment; 
import com.google.gwt.user.client.ui.HasVerticalAlignment; 

public class LoginView extends Composite { 

    private DBConnectionAsync rpc; 

    final VerticalPanel verticalPanel = new VerticalPanel(); 
    final HorizontalPanel horizontalPanel = new HorizontalPanel(); 
    final Label lblWelcomeToThe = new Label("Welcome to the Award Tracker login page.\r\n\r\nPlease Sign into your account."); 
    final FlexTable flexTable = new FlexTable(); 
    final Label lblAccountName = new Label("*Account name:"); 
    final Label lblAccountName2 = new Label("(username (e.g., email))"); 
    final Label lblPassword = new Label("*Password:"); 

    private PasswordTextBox passwordTextBox; 
    private TextBox textBoxAccountName; 

    int loginAttempt = 0; 
    public String youthMemberID = null; 
    int youthMembersLinked = 0; 

    public String accountID = null; 
    public String accountLevel = null; 
    public String scoutGroup = null; 
    public String scoutGroupSection = null; 

    public LoginView() { 
     verticalPanel.addAttachHandler(new Handler() { 
      public void onAttachOrDetach(AttachEvent event) { 
       if (event.isAttached()) { 

        rpc = (DBConnectionAsync) GWT.create(DBConnection.class); 
        ServiceDefTarget target = (ServiceDefTarget) rpc; 
        String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection"; 
        target.setServiceEntryPoint(moduleRelativeURL); 

        //Display the login page 

        //This is the nice green background with the small Scout logo 
        verticalPanel.setStyleName("gwt-Scout-Background"); 
        verticalPanel.setWidth("100%"); 
        verticalPanel.setHeight("100%"); 
        verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); 
        verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); 
        verticalPanel.setBorderWidth(0); 

        //This is the nice green background with the small Scout logo 
        horizontalPanel.setStyleName("gwt-Scout-Background"); 
        horizontalPanel.setWidth("100%"); 
        horizontalPanel.setHeight("100%"); 
        horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); 
        horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); 
        verticalPanel.add(horizontalPanel); 

        //Display the welcome message 
        lblWelcomeToThe.setStyleName("gwt-Label-Login"); 
        verticalPanel.add(lblWelcomeToThe); 
        lblWelcomeToThe.setWidth("321px"); 

        verticalPanel.add(flexTable); 
        verticalPanel.setCellHorizontalAlignment(flexTable, HasHorizontalAlignment.ALIGN_CENTER); 

        //Display the Account Name text and text box 
        lblAccountName.setStyleName("gwt-Label-Login"); 
        flexTable.setWidget(0, 0, lblAccountName); 
        //lblAccountName.setSize("110px", "16px"); 
        flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT); 

        textBoxAccountName = new TextBox(); 
        flexTable.setWidget(0, 1, textBoxAccountName); 
        textBoxAccountName.setSize("155px", "20px"); 

        //Display the Account Name hint 
        lblAccountName2.setStyleName("gwt-Label-Login"); 
        flexTable.setWidget(0, 2, lblAccountName2); 
        //lblAccountName2.setSize("200px", "16px"); 
        flexTable.getCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_LEFT); 

        //Display the password text and text box. 
        lblPassword.setStyleName("gwt-Label-Login"); 
        flexTable.setWidget(1, 0, lblPassword); 
        //lblPassword.setSize("73px", "16px"); 
        flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); 

        passwordTextBox = new PasswordTextBox(); 
        flexTable.setWidget(1, 1, passwordTextBox); 
        passwordTextBox.setSize("155px", "20px"); 

        //The following code will be replaced when the bootstrap code is working 
        //Display the sign in button and handle the click event 
        Button btnSignIn2 = new Button("Sign In"); 
        btnSignIn2.addClickHandler(new ClickHandler() { 
         public void onClick(ClickEvent event) { 
          //Store whether details have been entered for error handling 
          //textBoxAccountName.setText("accountName"); 

          Integer tracker = 0; 
          if (textBoxAccountName.getText().length() == 0) { 
            tracker = tracker + 1; 
          } 
          if (passwordTextBox.getText().length() == 0) { 
           tracker = tracker + 2; 
          } 

          //Check if details have been entered and display an error if 
          //they have not been entered. 
          if (tracker == 1) { 
           textBoxAccountName.setStyleName("gwt-TextBox-Error"); 
           passwordTextBox.setStyleName("gwt-TextBox"); 
           Window.alert("Please enter your Account name."); 
           }else if (tracker == 2) { 
            textBoxAccountName.setStyleName("gwt-TextBox"); 
            passwordTextBox.setStyleName("gwt-TextBox-Error"); 
            Window.alert("Please enter your Password."); 
           }else if (tracker == 3) { 
            textBoxAccountName.setStyleName("gwt-TextBox-Error"); 
            passwordTextBox.setStyleName("gwt-TextBox-Error"); 
            Window.alert("Please enter your Account name and Password."); 
           }else { 
            //If the required details have been entered then search the database for a match 
            textBoxAccountName.setStyleName("gwt-TextBox"); 
            passwordTextBox.setStyleName("gwt-TextBox"); 
            AsyncCallback<AccountGroup> callback = new AuthenticationHandler<AccountGroup>(); 
            rpc.authenticateAccountGroup(textBoxAccountName.getText(), passwordTextBox.getText(), callback); 
           } 
         } 
        }); 
        flexTable.setWidget(3, 1, btnSignIn2); 

        //The following code is for bootstrap 
        RootPanel.get("payPalDonate"); 
        RootPanel.get("payPalDonate").setVisible(true); 
        RootPanel.get("login"); //From bootstrap 
        RootPanel.get("login").setVisible(true); 
        Button btnSignIn = Button.wrap(Document.get().getElementById("submit")); //From bootstrap 
        final TextBox textBoxAccountName = TextBox.wrap(Document.get().getElementById("accountName")); //From bootstrap 
        final PasswordTextBox passwordTextBox = PasswordTextBox.wrap(Document.get().getElementById("enterPassword")); //From bootstrap 

        //Display the sign in button and handle the click event 
        btnSignIn.addClickHandler(new ClickHandler() { 
         public void onClick(ClickEvent event) { 
          //Store whether details have been entered for error handling 

          Integer tracker = 0; 
          if (textBoxAccountName.getText().length() == 0) { 
            tracker = tracker + 1; 
          } 
          if (passwordTextBox.getText().length() == 0) { 
           tracker = tracker + 2; 
          } 

          //Check if details have been entered and display an error if 
          //they have not been entered. 
          if (tracker == 1) { 
           textBoxAccountName.setStyleName("gwt-TextBox-Error"); 
           passwordTextBox.setStyleName("gwt-TextBox"); 
           Window.alert("Please enter your Account name."); 
           }else if (tracker == 2) { 
            textBoxAccountName.setStyleName("gwt-TextBox"); 
            passwordTextBox.setStyleName("gwt-TextBox-Error"); 
            Window.alert("Please enter your Password."); 
           }else if (tracker == 3) { 
            textBoxAccountName.setStyleName("gwt-TextBox-Error"); 
            passwordTextBox.setStyleName("gwt-TextBox-Error"); 
            Window.alert("Please enter your Account name and Password."); 
           }else { 
            //If the required details have been entered then search the database for a match 
            textBoxAccountName.setStyleName("gwt-TextBox"); 
            passwordTextBox.setStyleName("gwt-TextBox"); 
            Window.alert("textBoxAccountName.getText() = " + textBoxAccountName.getText()); 
            Window.alert("passwordTextBox.getText() = " + passwordTextBox.getText()); 
            AsyncCallback<AccountGroup> callback = new AuthenticationHandler<AccountGroup>(); 
            rpc.authenticateAccountGroup(textBoxAccountName.getText(), passwordTextBox.getText(), callback); 
           } 
         } 
        }); 
       } 
      } 
     }); 
     initWidget(verticalPanel); 

    } 

    class AuthenticationHandler<T> implements AsyncCallback<AccountGroup> { 
     public void onFailure(Throwable ex) { 
      System.out.println("RPC call failed - AuthenticationHandler - Notify Administrator."); 
      Window.alert("Connection failed - please retry."); 
     } 
     public void onSuccess(AccountGroup result) { 
      AccountGroup account = result; 
      if (account == null) { 
       //Only three invalid login attempts are allowed. Disable the account after 
       //three invalid login attempts. 
       if (loginAttempt > 2){ 
        AsyncCallback<Void> callback = new DisableHandler<Void>(); 
        rpc.disableAccount(textBoxAccountName.getText(), 0, callback); 
       }else{ 
        Window.alert("Incorrect Account name or Password entered. Please try again."); 
       } 
      }else{ 
       if (account.getLevel() == null) { 
        Window.alert("Your account has not yet been set up. Please contact your administrator."); 
       }else{ 
        if (account.getArchived() != null) { 
         Window.alert("Your account has been archived. Please contact your administrator."); 
        }else{ 
         if (account.getEnabled() == 1){ 
          accountLevel = account.getLevel(); 
          accountID = account.getAccountId(); 
          scoutGroup = account.getScoutGroupId(); 
          scoutGroupSection = account.getGroupSection(); 

          //Is a Leader or Administrator. 
          //Store the LoginView data for use in subsequent Views. 
          AsyncCallback<ViewData> callback2 = new ViewDataStoreHandler<ViewData>(); 
          rpc.setViewData(account.getAccountId(), account.getLevel(), null, null, null, 
            scoutGroup, null, 0, scoutGroupSection, null, null, callback2);       
         }else{ 
          //The account has had three or more invalid passwords entered and has been disabled. 
          Window.alert("Account is disabled. Please contact your administrator."); 
         } 
        } 
       } 
      } 
     } 
    } 

    class ViewDataStoreHandler<T> implements AsyncCallback<ViewData> { 

     public void onFailure(Throwable ex) { 
      System.out.println("RPC call failed - ViewDataStoreHandler - Notify Administrator."); 
      Window.alert("Connection failed - please retry."); 
     } 
     public void onSuccess(ViewData result) { 
      //The details have been stored 
      RootPanel.get("payPalDonate").setVisible(false); 
      RootPanel.get("payPalDonate").clear(); 
      RootPanel.get("login").setVisible(false); 
      RootPanel.get("login").clear(); 

      History.newItem("selectPerson", true); 
     } 
    } 


    class DisableHandler<T> implements AsyncCallback<Void> { 
     public void onFailure(Throwable ex) { 
      System.out.println("RPC call failed - DisableHandler - Notify Administrator."); 
      Window.alert("Connection failed - please retry."); 
     } 
     public void onSuccess(Void result) { 
      Window.alert("You have exceeded your password tries and your Account has been disabled. Please contact your administrator."); 
     } 
    } 

} 

I는 서버 측에서 내가 사용하여 암호를 확인할 때 것으로 나타났습니다. 그러나 BCrypt가 사용되면 (즉, 암호가 올바른지 여부로 계정이 올바른 경우) 오류 코드가 반환됩니다 (Throwable 값 = com.google.gwt.user.client.rpc.StatusCodeException : 0)

내가 찾은 Getting com.google.gwt.user.client.rpc.StatusCodeException: 0 in GWT :

나는 서버 (Thread.wait())에 rpc 호출을 걸어 놓고 브라우저가 페이지를 다시로드하기 바로 전에 클라이언트 측에서 새로 고친다면 위의 상태 코드와 함께 대기중인 콜백의 onFailure 메소드는 클라이언트에 orginate를 제안하거나 특정 아닌 catch 된 예외에 대한 일반적인 오류 코드입니다.

내 브라우저가 상쾌합니다. 이제 문제는 어떻게 상쾌하게하는 것입니까?

+0

에 있습니다. 안녕하세요.'Connection failed - please try. '메시지가'AuthenticationHandler' 콜백에 표시되지만 코드를 표시하지 않았습니다. 어떤 요소가 부트 스트랩에서 왔는지도 명확하지 않습니다. [Minimal, Complete, and Verifiable example] (http://stackoverflow.com/help/mcve)를 제공 할 수 있습니까? – Adam

+0

OK 코드가'Window.alert ("Connection failed -"onFailure() "메소드의 라인을 재 시도하십시오.");' 'AuthenticationHandler','ViewDataStoreHandler' 또는'DisableHandler'에 있습니다. 'Throwable' 값을 검사 할 수 있습니까? – Adam

+0

안녕하세요, Adam은 AuthenticationHandler에 있습니다. 나는 "Window.alert ("Throwable value = "+ ex);"를 추가했다. "공공 무효 onFailure (Throwable 예) {"및 결과 "Throwable 값 = com.google.gwt.user.client.rpc.StatusCodeException : 0" – Glyn

답변

0

많은 조사를 한 후에이 문제는 Java 코드와 관련이 없음을 발견했습니다. 새로 고침하면 gwtBootstrap의 양식에서 데이터를 반환하고 GWTJava에서 오류 코드로 선택되는 "Throwable value = com.google.gwt.user.client.rpc.StatusCodeException : 0"을 반환합니다. 따라서 HTML에서 양식 사용 div를 사용하지 마십시오. 전체 설명과 해결책은 How to stop GWTBootstrap3 from refreshing and loosing my input and returning an error code