异步回调保存值但打印 FAILED

发布于 2024-08-26 06:35:40 字数 4137 浏览 6 评论 0原文

我正在使用嵌套异步回调将前端数据保存到后端数据库。数据按照我想要的方式保存到表中,但打印失败。这是代码:

    if(erasync == null)
        erasync = GWT.create(EntityRelationService.class);
    AsyncCallback<Void> callback = new AsyncCallback<Void>(){
        public void onFailure(Throwable caught) {
            String msg = caught.getLocalizedMessage();
             if (caught instanceof NotFoundException) {
                msg = ((NotFoundException) caught).getType()
                      + ((NotFoundException) caught).getMessage();
             }
           System.out.println("Failed" + msg);
        }
        public void onSuccess(Void result) {
                    if(erasync == null)
                        erasync = GWT.create(EntityRelationService.class);
                    AsyncCallback<Void> callbackOthers = new AsyncCallback<Void>(){
                        @Override
                        public void onFailure(Throwable caught) {
                            String msg = caught.getLocalizedMessage();
                             if (caught instanceof NotFoundException) {
                                msg = ((NotFoundException) caught).getType()
                                      + ((NotFoundException) caught).getMessage();
                             }
                           System.out.println("Failed" + msg);
caught.printStackTrace();
                        }
                        public void onSuccess(Void result) {
                            System.out.println("Success");
                        }                           
                    };
                    erasync.setEntityType(name, top, left, pname, callbackOthers);
        };
        erasync.setProject(name, callback);

这里它打印第一个回调成功,但对于嵌套回调,它显示失败,尽管它保存了值。这是失败时打印的堆栈:

com.google.gwt.user.client.rpc.StatusCodeException: 
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
    at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
    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.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    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:188)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    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.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    at java.lang.Thread.run(Thread.java:619)

我错过了什么吗?

任何输入都会有很大帮助。 谢谢。

I am using nested Asynchronous callbacks to save my front-end data to the back-end database. The data is being save into the tables the way i want them to, but it is printing that it failed. Here is the code:

    if(erasync == null)
        erasync = GWT.create(EntityRelationService.class);
    AsyncCallback<Void> callback = new AsyncCallback<Void>(){
        public void onFailure(Throwable caught) {
            String msg = caught.getLocalizedMessage();
             if (caught instanceof NotFoundException) {
                msg = ((NotFoundException) caught).getType()
                      + ((NotFoundException) caught).getMessage();
             }
           System.out.println("Failed" + msg);
        }
        public void onSuccess(Void result) {
                    if(erasync == null)
                        erasync = GWT.create(EntityRelationService.class);
                    AsyncCallback<Void> callbackOthers = new AsyncCallback<Void>(){
                        @Override
                        public void onFailure(Throwable caught) {
                            String msg = caught.getLocalizedMessage();
                             if (caught instanceof NotFoundException) {
                                msg = ((NotFoundException) caught).getType()
                                      + ((NotFoundException) caught).getMessage();
                             }
                           System.out.println("Failed" + msg);
caught.printStackTrace();
                        }
                        public void onSuccess(Void result) {
                            System.out.println("Success");
                        }                           
                    };
                    erasync.setEntityType(name, top, left, pname, callbackOthers);
        };
        erasync.setProject(name, callback);

Here it prints successful for the first callback, but for the nested one it says failed though it saves the value. Here is the stack that it prints for failure:

com.google.gwt.user.client.rpc.StatusCodeException: 
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
    at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
    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.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    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:188)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    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.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    at java.lang.Thread.run(Thread.java:619)

Am i missing something?

Any input will be of great help.
Thank you.

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

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

发布评论

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

评论(1

柠檬色的秋千 2024-09-02 06:35:40

嘿我解决了问题。我遇到这个问题是因为当仍有异步调用正在进行时,窗口正在重新加载并更改状态代码。我在我的方法末尾添加了窗口重新加载,现在它工作正常。谢谢大家。

Hey I solved the problem. I was having this problem because the window was reloading and changing the status code when there were still asynchronous calls in process. I included the window reload at the end of my method and its working fine now. Thanks all.

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