7 Replies Latest reply on Mar 17, 2014 7:19 PM by cristianmiranda

    Errai Testing - Calling RPC

    cristianmiranda

      Hi guys,

       

           I've created a test for an RPC and I'm having the following error: http://pastebin.com/FjpbbRpH

       

      package app.client.local;
      
      
      import app.client.shared.service.AsyncRPCService;
      import org.jboss.errai.bus.client.api.base.MessageBuilder;
      import org.jboss.errai.bus.client.tests.AbstractErraiTest;
      import org.jboss.errai.common.client.api.RemoteCallback;
      
      
      /**
      * Created by cristianmiranda on 3/13/14.
      */
      public class GreetingRPCTest extends AbstractErraiTest {
      
      @Override
      public String getModuleName() {
           return "app.App";
      }
      
      
      @Override
      protected void gwtSetUp() throws Exception {
           super.gwtSetUp();
      }
      
      public void testcreateStrategy() throws Exception {
        System.out.println("-- Testing create strategy --");
        runAfterInit(new Runnable() {
             @Override
             public void run() {
                  MessageBuilder.createCall(new RemoteCallback<String>() {
                       @Override
                       public void callback(String response) {
                            System.out.println("-- Got a response! --");        
                            assertEquals("foobar", response);                  
                            finishTest();
                       }
                  }, AsyncRPCService.class).doSomeTask();
             }
        });
      }
      
      }
      
      
      
      
      
      
      
      

       

      I already have this in my web.xml:

       

      <servlet>
        <servlet-name>ErraiServlet</servlet-name>
        <servlet-class>org.jboss.errai.bus.server.servlet.DefaultBlockingServlet</servlet-class>
        <init-param>
         <param-name>auto-discover-services</param-name>
         <param-value>true</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
        </servlet>
      
      
      
      
      
      
      

       

           My @Remote interface is in the client package and my @Service implementation is in the server package.

           Server side service is not being found in ServiceProcessor.java:70

       

      @Override
        public void process(final BootstrapContext context, MetaDataScanner reflections) {
          final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();
          final Set<Class<?>> services = reflections.getTypesAnnotatedWithExcluding(Service.class, CLIENT_PKG_REGEX);
          final Set<Method> methodServices = reflections.getMethodsAnnotatedWithExcluding(Service.class, CLIENT_PKG_REGEX);
      
      
          for (Class<?> loadClass : services) {
            processServiceClass(loadClass, context, config);
          }
          for (Method loadMethod : methodServices) {
            processServiceMethod(loadMethod, context, config);
          }
        }
      
      
      
      

       

      I have debugged the sources and noticed the following in ClientMessageBusImpl.java:793

       

      if (!localOnly && remotes.containsKey(subject)) {
              //  LogUtil.log("[bus] sent to remote: " + message);
                remotes.get(subject).callback(message);
                routedToRemote = true;
              }
      
      
      
      
      
      

       

                ... remotes does not contain my Remote service AsyncRPCService (it is annotated with @org.jboss.errai.bus.server.annotations.Remote)

       

      I see this in my generated RpcProxyLoaderImpl.java

       

      class app_client_shared_service_AsyncRPCServiceImpl extends AbstractRpcProxy implements AsyncRPCService { public CallableFuture doSomeTask() {
              RemoteCallSendable sendable = null;
              if (errorCallback == null) {
                sendable = MessageBuilder.createCall().call("app.client.shared.service.AsyncRPCService").endpoint("doSomeTask:", qualifiers, new Object[] { }).respondTo(CallableFuture.class, remoteCallback).defaultErrorHandling();
              } else {
                sendable = MessageBuilder.createCall().call("app.client.shared.service.AsyncRPCService").endpoint("doSomeTask:", qualifiers, new Object[] { }).respondTo(CallableFuture.class, remoteCallback).errorsHandledBy(errorCallback);
              }
              app_client_shared_service_AsyncRPCServiceImpl.this.sendRequest(bus, sendable);
              return null;
            }
          }
          RemoteServiceProxyFactory.addRemoteProxy(AsyncRPCService.class, new ProxyProvider() {
            public Object getProxy() {
              return new app_client_shared_service_AsyncRPCServiceImpl();
            }
          });
      
      

       

           Here is my App.gwt.xml: http://pastebin.com/Dj70VRzL

       

      Any ideas?

       

      Thanks in advance!

        • 1. Re: Errai Testing - Calling RPC
          magick93

          Hi Max and Christian - I know you guys are very busy working on the next stable release.

          If you can help us with this issue, it would be greatly appreciated!

           

          Thanks

          • 2. Re: Errai Testing - Calling RPC
            vwjugow

            Hi, I'm having the exact same issue, I took this example errai/errai-bus/src/test/java/org/jboss/errai/bus/client/tests/AsyncRPCServicesTest.java at master · errai/errai · GitHu… but seems like there's something wrong on the server side configuration, it seems like the "server side" hasn't subscribed to the message bus so no rpc calls get executed

            • 3. Re: Errai Testing - Calling RPC
              vwjugow

              Code for @Service class

              package app.server.service;
              
              import app.client.shared.service.AsyncRPCService;
              import org.jboss.errai.bus.client.api.CallableFuture;
              import org.jboss.errai.bus.server.annotations.Service;
              import org.jboss.errai.bus.server.api.CallableFutureFactory;
              import java.util.concurrent.Executors;
              
              
              /**
               * @author Mike Brock
               */
              @Service
              public class AsyncRpcServiceImpl implements AsyncRPCService {
                @Override
                public CallableFuture<String> doSomeTask() {
                final CallableFuture<String> future = CallableFutureFactory.get().createFuture();
              
              
                final java.util.concurrent.ExecutorService executorService = Executors.newSingleThreadExecutor();
                executorService.submit(new Runnable() {
                @Override
                public void run() {
                try {
                Thread.sleep(5000);
                future.setValue("foobar");
                }
                catch (Throwable t) {
                t.printStackTrace();
                }
                }
                });
                executorService.shutdown();
              
              
                return future;
                }
              }
              
              
              
              
              
              
              
              
              
              
              • 4. Re: Re: Errai Testing - Calling RPC
                mbarkley

                Victor,

                 

                Can you please try the following:

                • Create a log4j.properites in src/test/resources with the following contents:
                log4j.rootLogger=DEBUG, CONSOLE
                log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
                log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
                log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n
                
                • Run your test.
                • Look for output that looks like this (there'll be a lot of output, but this should be near the beginning):
                2014-03-14 10:31:29,217 [Thread-10] DEBUG ClasspathScanning - scanning inside: /home/yyz/mbarkley/Documents/errai-projects/errai/errai-bus/target/test-classes/
                2014-03-14 10:31:29,218 [Thread-10] DEBUG ClasspathScanning - scanning inside: /home/yyz/mbarkley/Documents/errai-projects/errai/errai-bus/target/classes/
                2014-03-14 10:31:29,218 [Thread-10] DEBUG ClasspathScanning - scanning inside: /home/yyz/mbarkley/.m2/repository/org/jboss/errai/errai-common/3.0-SNAPSHOT/errai-common-3.0-SNAPSHOT.jar
                2014-03-14 10:31:29,218 [Thread-10] DEBUG ClasspathScanning - scanning inside: /home/yyz/mbarkley/.m2/repository/org/jboss/errai/errai-marshalling/3.0-SNAPSHOT/errai-marshalling-3.0-SNAPSHOT.jar
                2014-03-14 10:31:29,256 [Thread-10] DEBUG Reflections - going to scan these urls:
                  jar:file:/home/yyz/mbarkley/.m2/repository/org/jboss/errai/errai-common/3.0-SNAPSHOT/errai-common-3.0-SNAPSHOT.jar!/
                  file:/home/yyz/mbarkley/Documents/errai-projects/errai/errai-bus/target/test-classes/
                  jar:file:/home/yyz/mbarkley/.m2/repository/org/jboss/errai/errai-marshalling/3.0-SNAPSHOT/errai-marshalling-3.0-SNAPSHOT.jar!/
                  file:/home/yyz/mbarkley/Documents/errai-projects/errai/errai-bus/target/classes/
                

                 

                Instead of the paths shown here, you should see:

                • The errai-bus jar.
                • The jar path to your @Service class.
                1 of 1 people found this helpful
                • 5. Re: Re: Errai Testing - Calling RPC
                  cristianmiranda

                  This is all we have at the beginning: http://pastebin.com/NiAnH88G

                  • 6. Re: Errai Testing - Calling RPC
                    vwjugow

                    Ok, so this turned out to be a class path error. We've fixed that by having this in the pom:

                     

                            <build>
                                    <resources>
                                        <resource>
                                            <directory>src/main/java</directory>
                                        </resource>
                                        <resource>
                                            <directory>src/main/resources</directory>
                                        </resource>
                                    </resources>
                                    <testResources>
                                        <testResource>
                                            <directory>src/main/java</directory>
                                        </testResource>
                                        <testResource>
                                            <directory>src/main/resources</directory>
                                        </testResource>
                                    </testResources>
                    ...
                    
                    
                    

                     

                    Now we know that both main and test are being included in the classpath (checked by debugging errai sources)

                     

                    Now we are getting this:

                     

                    http://pastebin.com/LMKxbwqU

                     

                    If I comment the reference to that interface, another one throws same error. It happens with all fields that have @javax.inject.Inject annotation.

                    I tried using @google.inject.Inject but same error occurs.

                    If anyone can help it would be very appreciated!

                     

                    Thanks in advanced.

                    • 7. Re: Errai Testing - Calling RPC
                      cristianmiranda

                      Hi guys, after debugging the sources we've found that the error occurs when trying to find an implementation for the bean interface.

                      I don't know if it helps but here is the piece of code where the exception is thrown, in OrderedBootstrap:56

                       

                      public void execute(final BootstrapContext context) {

                          log.info("starting errai bus ...");

                          try {

                            for (BootstrapExecution execution : bootstrap) {

                             execution.execute(context); // THIS IS THE LINE FAILING

                            }

                            context.executeDeferred();

                            ((ErraiServiceConfiguratorImpl) context.getConfig()).lockdown();

                            log.info("errai bus started.");

                          }

                          catch (Exception e) {

                            e.printStackTrace();

                            throw new RuntimeException("server bootstrap failed", e);

                          }

                        }

                       

                      ... and a bit deeper in InjectorImpl:961

                       

                      public <T> Provider<T> getProvider(Class<T> type) {

                          return getProvider(Key.get(type));

                      }

                       

                      Thanks!