6 Replies Latest reply on Nov 24, 2013 12:14 AM by n3k0

    How to detonate a post task like errai old version?

    n3k0

      Hi everybody.

      I tried to make a task like this antique example: https://community.jboss.org/message/629755#629755 with errai 2.3.1, the code is as flollows:

       

       @PostConstruct  
          public void onModuleLoad(){  
              ((ClientMessageBus) bus).addPostInitTask(new Runnable() {  
                     public void run() {  
                         MessageBuilder.createCall(new RemoteCallback<Boolean>() {        
                             public void callback(Boolean isHappy) {                     
                                 if (isHappy) Window.alert("Everyone is happy!");           
                             }                                                             
                         }, TheRemoteService.class).isEveryoneHappy();  
                     }  
              });  
          } 
      
      

      BUT, the addPostInitTask method is not anymore declared in the ClientMessageBus interface!

      How can i achieve the same result?

       

      Thanks in advance.

        • 1. Re: How to detonate a post task like errai old version?
          csa

          Hi,

           

          @AfterInitialization can be used for executing RPC requests as soon as the bus is ready and federated with the server:

           

          @AfterInitialization
          private void afterInit() {
            MessageBuilder.createCall(new RemoteCallback<Boolean>() {
              public void callback(Boolean isHappy) {
                if (isHappy) Window.alert("Everyone is happy!");            
              }
            }, TheRemoteService.class).isEveryoneHappy();  
          }
          

           

           

          Cheers,

          Christian

          • 2. Re: Re: How to detonate a post task like errai old version?
            n3k0

            Sorry Christian, it did not work, this stack trace appears:

             

            22:02:21.115 [ERROR] [demoapp] Async Task Execution Failed. Future executions (if any) are cancelled.
            java.lang.RuntimeException: There are no proxy providers registered.
                at org.jboss.errai.common.client.framework.RemoteServiceProxyFactory.getRemoteProxy(RemoteServiceProxyFactory.java:37)
                at org.jboss.errai.bus.client.api.builder.DefaultRemoteCallBuilder.call(DefaultRemoteCallBuilder.java:63)
                at org.jboss.errai.bus.client.api.builder.DefaultRemoteCallBuilder.call(DefaultRemoteCallBuilder.java:59)
                at org.jboss.errai.bus.client.api.base.MessageBuilder.createCall(MessageBuilder.java:185)
                at mx.app.site.client.Site.afterInit(MyDemo.java:37)
                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:172)
                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)
                at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
                at org.jboss.errai.ioc.client.BootstrapperImpl._311098333_afterInit(BootstrapperImpl.java)
                at org.jboss.errai.ioc.client.BootstrapperImpl$11$1.run(BootstrapperImpl.java:139)
                at org.jboss.errai.common.client.api.extension.InitVotes$OneTimeRunnable.run(InitVotes.java:398)
                at org.jboss.errai.common.client.api.extension.InitVotes._runAllRunnables(InitVotes.java:370)
                at org.jboss.errai.common.client.api.extension.InitVotes._runAllRunnables(InitVotes.java:355)
                at org.jboss.errai.common.client.api.extension.InitVotes.finishInit(InitVotes.java:340)
                at org.jboss.errai.common.client.api.extension.InitVotes.access$3(InitVotes.java:335)
                at org.jboss.errai.common.client.api.extension.InitVotes$1.run(InitVotes.java:184)
                at org.jboss.errai.common.client.api.tasks.ClientTaskManager$ClientAsyncTask.run(ClientTaskManager.java:89)
                at org.jboss.errai.common.client.api.tasks.ClientTaskManager$TaskManagerTimer.run(ClientTaskManager.java:190)
                at com.google.gwt.user.client.Timer.fire(Timer.java:149)
                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:172)
                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
                at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
                at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
                at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
                at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
                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:242)
                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:172)
                at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
                at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
                at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
                at java.lang.Thread.run(Thread.java:662)
            
            
            • 3. Re: How to detonate a post task like errai old version?
              csa

              This should definitely work. Which version of Errai are you using?

               

              Can you post or check your .errai/RpcProxyLoaderImpl.java  file to see if a proxy was generated for that specific remote service and also check that your remote interface is annotated with @Remote?

              • 4. Re: Re: How to detonate a post task like errai old version?
                n3k0

                Hi Christian.

                The  errai version is 2.4.2.

                 

                The code of RpcProxyLoaderImpl.java is this:

                 

                package org.jboss.errai.bus.client.framework;
                
                import example.app.site.shared.service.ItemService;
                import java.util.List;
                import org.jboss.errai.bus.client.api.base.MessageBuilder;
                import org.jboss.errai.bus.client.api.builder.RemoteCallSendable;
                import org.jboss.errai.bus.client.api.messaging.MessageBus;
                import org.jboss.errai.common.client.framework.ProxyProvider;
                import org.jboss.errai.common.client.framework.RemoteServiceProxyFactory;
                
                public class RpcProxyLoaderImpl implements RpcProxyLoader {
                  public void loadProxies(final MessageBus bus) {
                    class example_app_site_shared_service_ItemServiceImpl extends AbstractRpcProxy implements ItemService {
                      public List loadItems() {
                        RemoteCallSendable sendable = null;
                        if (errorCallback == null) {
                          sendable = MessageBuilder.createCall().call("example.app.site.shared.service.ItemService").endpoint("loadItems:", qualifiers, new Object[] { }).respondTo(List.class, remoteCallback).defaultErrorHandling();
                        } else {
                          sendable = MessageBuilder.createCall().call("example.app.site.shared.service.ItemService").endpoint("loadItems:", qualifiers, new Object[] { }).respondTo(List.class, remoteCallback).errorsHandledBy(errorCallback);
                        }
                        ga_kravma_app_site_shared_service_ItemServiceImpl.this.sendRequest(bus, sendable);
                        return null;
                      }
                    }
                    RemoteServiceProxyFactory.addRemoteProxy(ItemService.class, new ProxyProvider() {
                      public Object getProxy() {
                        return new ga_kravma_app_site_shared_service_ItemServiceImpl();
                      }
                    });
                  }
                }
                

                 

                The class is ItemService, and the method is loadItems (not isEveryoneHappy() like the snippet, but is the same effect). Apparently, the class is mapping fine my interface, but it not works. The code of the interface is as follows:

                 

                
                @Remote
                public interface ItemService {
                    List<Item> loadItems();
                }
                
                

                 

                And the Item bean i use is like this:

                 

                 import java.io.Serializable; 
                import java.util.ArrayList; 
                import java.util.Date; 
                
                import org.jboss.errai.common.client.api.annotations.Portable; 
                
                @Portable 
                public class Item implements Serializable { 
                    private static final long serialVersionUID = 1L; 
                
                    private Long id; 
                    private Date creationDate; 
                     private String title; 
                    private String body; 
                
                //getters and setters 
                }
                

                 

                Both, the interface and the bean, are in the "shared" package, and the server implementation is:

                 

                @Service
                public class ItemServiceImpl implements ItemService {
                
                    @Override
                    public List<Item> loadItems() {
                        Item item = new Item();
                        item.setBody("body");
                        item.setId(1000L);
                        item.setTitle("title");
                        List<Item>items = new ArrayList<Item>(1);
                        items.add(item);
                        return items;
                    }
                }
                
                
                

                 

                 

                and my XML config:

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <!-- When updating your version of GWT, you should also update this DTD reference, 
                    so that your app can take advantage of the latest GWT module capabilities. -->
                <!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
                  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
                <module rename-to='example'>
                
                    <inherits name='com.google.gwt.user.User' />
                    <inherits name='com.google.gwt.user.theme.dark.Dark' />
                
                    
                    <inherits name="org.jboss.errai.bus.ErraiBus" />
                    <inherits name="org.jboss.errai.marshalling.ErraiMarshalling" />
                    <inherits name="org.jboss.errai.ioc.Container" />
                    <inherits name="org.jboss.errai.enterprise.CDI" />
                    <inherits name="org.jboss.errai.common.ErraiCommon" />
                    <inherits name="org.jboss.errai.ui.UI" />
                    <inherits name="org.jboss.errai.databinding.DataBinding" />
                    
                    
                
                    <source path='client' />
                    <source path='shared' />
                
                </module>
                
                
                
                
                

                 

                 

                I can't see anything irregular thing :S

                • 5. Re: Re: Re: How to detonate a post task like errai old version?
                  csa

                  Hi,

                   

                  I attached a sample application that makes use of the classes you provided (Item, ItemService, etc). The RPC in @AfterInitializiation works fine there. The sample app is based on our tutorial project but that shouldn't make a difference. I'd recommend checking your browser's console and see if you can spot an errors. It seems that your bus isn't bootstrapping correctly. I am assuming you didn't deactivate remote communication? I can't see anything wrong with the files you shared.

                   

                  Cheers,

                  Christian

                  1 of 1 people found this helpful
                  • 6. Re: How to detonate a post task like errai old version?
                    n3k0

                    Hi Christian.

                    I tried to compile your example, but some exceptions appears related with "there is no servlet javax.ws.rs.core.Application" so, i maked a brand new example with errai cdi maven archetype; and i pasted the code, and i don't know why but the code runs! i see any piece of code and configuration file, and everything is identical!

                    So, thanks for your assistance!