使用 GWT RequestBuilder 通过 Google 检查密码强度

发布于 2024-10-06 14:04:53 字数 4607 浏览 2 评论 0原文

名义上,网址 http://www.google.com/accounts/RatePassword?Passwd=aaaaa可用于检查密码aaaaa的强度。我试图在我的 GWT 系统中使用它,通过使用 RequestBuilder 来获取值,该值可能在 1 到 4 之间,但我没有获取该值。有人能猜出问题是什么吗?

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
  "http://www.google.com/accounts/RatePassword?Passwd=aaaaa");

     try {
       Request response = builder.sendRequest(null, new RequestCallback() {
         public void onError(Request request, Throwable exception) {
           //error
         }

         public void onResponseReceived(Request request, Response response) {
          Window.alert(""+response.getText());
         }
       });
     } catch (RequestException e) {
       // Code omitted for clarity
     }

我正在这样做:

class PasswordStrength extends JavaScriptObject {

            protected PasswordStrength() {}

        public final native String getRating() /*-{
            return this.rating;
        }-*/;
    }

JsonpRequestBuilder  builder = new JsonpRequestBuilder ();

    builder.requestObject(URL.encode(
              "https://www.google.com/accounts/RatePassword?Passwd=aaa"),
              new AsyncCallback <PasswordStrength>(){

        @Override
        public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
            Window.alert("Error");
        }

        @Override
        public void onSuccess(PasswordStrength result) {
            // TODO Auto-generated method stub
            Window.alert("NotError");
        }});

但我收到此错误:

java.lang.ClassFormatError: Illegal method name "<init>$" in class com/BiddingSystem/client/BiddingSystem$1PasswordStrength
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
    at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1011)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at com.BiddingSystem.client.BiddingSystem$1.onSuccess(BiddingSystem.java:1)
    at com.google.gwt.jsonp.client.JsonpRequest.onSuccess(JsonpRequest.java:201)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:662)

Nominally, the URL
http://www.google.com/accounts/RatePassword?Passwd=aaaaa can be used to check the strength of the password aaaaa. I am trying to use it in my GWT system by using a RequestBuilder to get the value, which may be between 1 and 4, but I am not getting the value. Can someone guess what the problem is?

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
  "http://www.google.com/accounts/RatePassword?Passwd=aaaaa");

     try {
       Request response = builder.sendRequest(null, new RequestCallback() {
         public void onError(Request request, Throwable exception) {
           //error
         }

         public void onResponseReceived(Request request, Response response) {
          Window.alert(""+response.getText());
         }
       });
     } catch (RequestException e) {
       // Code omitted for clarity
     }

I am doing this:

class PasswordStrength extends JavaScriptObject {

            protected PasswordStrength() {}

        public final native String getRating() /*-{
            return this.rating;
        }-*/;
    }

JsonpRequestBuilder  builder = new JsonpRequestBuilder ();

    builder.requestObject(URL.encode(
              "https://www.google.com/accounts/RatePassword?Passwd=aaa"),
              new AsyncCallback <PasswordStrength>(){

        @Override
        public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
            Window.alert("Error");
        }

        @Override
        public void onSuccess(PasswordStrength result) {
            // TODO Auto-generated method stub
            Window.alert("NotError");
        }});

But I'm getting this error:

java.lang.ClassFormatError: Illegal method name "<init>$" in class com/BiddingSystem/client/BiddingSystem$1PasswordStrength
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
    at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1011)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at com.BiddingSystem.client.BiddingSystem$1.onSuccess(BiddingSystem.java:1)
    at com.google.gwt.jsonp.client.JsonpRequest.onSuccess(JsonpRequest.java:201)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:662)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫之都 2024-10-13 14:04:53

我们按以下方式使用它(省略 ui 详细信息):

public class PasswordStrengthWidget extends Composite {

    private static class PasswordStrength extends JavaScriptObject {

        protected PasswordStrength() {}

        public final native String getRating() /*-{
            return this.rating;
        }-*/;
    }

    private static final String RATING_URL = URL.encode("https://www.google.com/accounts/RatePassword?Passwd=");
    private static final String[] STRENGTH = {"very weak", "weak", "medium", "strong"};
    @UiField
    Label indicator;
    private PasswordTextBox fPassword;

    ...

    private void updateStrengthIndicator() {
        JsonpRequestBuilder request = new JsonpRequestBuilder();
        request.requestObject(RATING_URL + fPassword.getText(), new AsyncCallback<PasswordStrength>() {

            @Override
            public void onSuccess(PasswordStrength result) {
                indicator.setText(STRENGTH[Integer.parseInt(result.getRating()) - 1] + result.getRating());
            }

            @Override
            public void onFailure(Throwable caught) {
                indicator.setText("error calculating strength");
            }
        });
    }
}

确保将此行添加到 module.xml 中:

<inherits name='com.google.gwt.jsonp.Jsonp' />

We're using it the following way (ui details omitted):

public class PasswordStrengthWidget extends Composite {

    private static class PasswordStrength extends JavaScriptObject {

        protected PasswordStrength() {}

        public final native String getRating() /*-{
            return this.rating;
        }-*/;
    }

    private static final String RATING_URL = URL.encode("https://www.google.com/accounts/RatePassword?Passwd=");
    private static final String[] STRENGTH = {"very weak", "weak", "medium", "strong"};
    @UiField
    Label indicator;
    private PasswordTextBox fPassword;

    ...

    private void updateStrengthIndicator() {
        JsonpRequestBuilder request = new JsonpRequestBuilder();
        request.requestObject(RATING_URL + fPassword.getText(), new AsyncCallback<PasswordStrength>() {

            @Override
            public void onSuccess(PasswordStrength result) {
                indicator.setText(STRENGTH[Integer.parseInt(result.getRating()) - 1] + result.getRating());
            }

            @Override
            public void onFailure(Throwable caught) {
                indicator.setText("error calculating strength");
            }
        });
    }
}

Make sure you add this line to your module.xml:

<inherits name='com.google.gwt.jsonp.Jsonp' />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文