9 Replies Latest reply on Sep 17, 2010 3:05 PM by heiko.braun

    Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.

    misqu23

      Hi

       

      In our application for simplicity we don't use dto. We are using jpa entites in the client/server communication, but using this approach we have to use library such as gilead for proper clonning and merging entities. We have been using gilead with gwt-dispatcher and I'm trying to use it with errai as well.

      I looked into the errai-persistenc e code and I'm trying to write my own extension component which will provide our GileadModelAdapter.

      Below there is the code snippet of our PersistenceErraiExtension and GileadModelAdapter :

       

      import java.util.logging.Logger;
      
      import org.jboss.errai.bus.client.api.ResourceProvider;
      import org.jboss.errai.bus.client.framework.ModelAdapter;
      import org.jboss.errai.bus.server.annotations.ExtensionComponent;
      import org.jboss.errai.bus.server.api.ErraiConfig;
      import org.jboss.errai.bus.server.api.ErraiConfigExtension;
      
      /**
       * @author Marcin Misiewicz
       *
       */
      @ExtensionComponent
      public class PersistenceErraiExtension implements ErraiConfigExtension {
      
           private final static Logger log = Logger.getLogger(PersistenceErraiExtension.class.getName());
      
           /* (non-Javadoc)
            * @see org.jboss.errai.bus.server.api.ErraiConfigExtension#configure(org.jboss.errai.bus.server.api.ErraiConfig)
            */
           @Override
           public void configure(ErraiConfig config) {
                log.info("Configuring persistence extension.");
                
                //Map<Class<?>, ResourceProvider> extensionBindings = new HashMap<Class<?>, ResourceProvider>();
                
                final ModelAdapter modelAdapter = new GileadModelAdapter();
                ResourceProvider<ModelAdapter> modelAdapterProvider = new ResourceProvider<ModelAdapter>() {
      
                     @Override
                     public ModelAdapter get() {
                          return modelAdapter;
                     }
                };
                
                log.info("adding binding for: "+modelAdapter.getClass());
                config.addBinding(ModelAdapter.class, modelAdapterProvider);
           }
      
      }
      
       
      
      import java.util.logging.Logger;
      
      import org.jboss.errai.bus.client.framework.ModelAdapter;
      
      /**
       * @author Marcin Misiewicz
       *
       */
      public class GileadModelAdapter implements ModelAdapter {
      
           private final static Logger log = Logger.getLogger(GileadModelAdapter.class.getName());
           
           /* (non-Javadoc)
            * @see org.jboss.errai.bus.client.framework.ModelAdapter#clone(java.lang.Object)
            */
           @Override
           public Object clone(Object entity) {
                log.info("Cloning entity");
                return null;
           }
      
           /* (non-Javadoc)
            * @see org.jboss.errai.bus.client.framework.ModelAdapter#merge(java.lang.Object)
            */
           @Override
           public Object merge(Object dto) {
                log.info("Merging dto");
                return null;
           }
      
      }
      
       
      

       

      As you can see the code is very simple. Right know I only want to check if loading extension works.

       

      Of course extension is loaded during the bootstrap of the errai :

       

      14:40:39,239 INFO  [Errai] Starting Errai Service
      14:40:41,082 INFO  [OrderedBootstrap] Bootstrap Errai
      14:40:41,110 INFO  [DefaultComponents] using dispatcher implementation: org.jboss.errai.bus.server.SimpleDispatcher
      14:40:41,141 INFO  [DefaultComponents] using session provider implementation: org.jboss.errai.bus.server.HttpSessionProvider
      14:40:41,187 INFO  [LoadExtensions] beging searching for Errai extensions ...
      14:40:41,213 INFO  [LoadExtensions] found extension org.jboss.errai.tools.monitoring.MonitorExtension
      14:40:46,374 INFO  [LoadExtensions] found extension pl.scentia.smartoffice.persistence.server.utils.PersistenceErraiExtension
      14:40:46,388 INFO  [PersistenceErraiExtension] Configuring persistence extension.
      14:40:46,403 INFO  [PersistenceErraiExtension] adding binding for: class pl.scentia.smartoffice.persistence.server.utils.GileadModelAdapter
      14:40:46,405 INFO  [LoadExtensions] added extension binding: org.jboss.errai.bus.client.framework.ModelAdapter
      14:40:46,405 INFO  [LoadExtensions] total extension binding: 1
      14:40:46,492 INFO  [DiscoverServices] auto-discovery of services disabled.
      14:40:46,493 INFO  [BootstrapContext] Running deferred bootstrap tasks ...
      14:40:46,493 INFO  [OrderedBootstrap] Bootstrap complete. Ready to rumble!
      
      

       

      As you can see extension is loaded, but unfortunately when I call rpc services I can't see the messages coming from GileadModelAdapter. I thought that for some reason errai still uses NoopModelAdapater which is default ModelAdapter but adding loging messages to the clone and merge operations of the NoopModelAdapter also doesn't produce any log messages.

       

      So it seems that providing custom implementation of the model adapter is still in development, am I right ?

      If not please tell what am I doing wrong ?

       

      Regards

        • 1. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
          heiko.braun

          Hi Marcin,

           

          first of all you might want to check if the existing extension fit's your purpose:

          See PersistenceConfiguration.java (persistence module). It uses the HibernateAdapter.

          So if you use hibernate, this might already work out of the box.

          • 2. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
            heiko.braun

            Btw, I just saw that you are using the SimpleDispatcher. Is there a reason not to use the Async one?

            • 3. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
              misqu23

              PersistenceConfiguration.java was the inspiration for me.

              Since I'm using jboss and Gilead has JBoss specific configurator I wanted to provide my own implementation which uses this helper class. The main reason why I want to this is because I don't want to store hibernate configuration in two different places (persistence.xml and ErraiService,properties). Of course I will try errai-persistence module and see if its working. But if you take a closer look at my classes you will notice that it looks very similar to PersistenceConfiguration (it doesn't have hibernate specific code) and it registers very dummy at least for now ModelAdapter (right know adapter should only log the calls to the appropriate methods).

               

              In my opinion it should work anyway.

              • 4. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                misqu23

                 

                Im using SimpleDispatcher temporarily. Mainly because for now I want to get my app working in the simplest scenario,

                When I switch to Async dispatcher I get jaas security exceptions. I simply didn't configured JAASAdapter yet to work with my security domain.

                 

                BTW how can I configure errai to work with my security domain which is defined in server profile login-config.xml file.

                • 5. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                  heiko.braun

                  You are right. It should work with your custom adapter as well. I'll check tomorrow and get back to you.

                  BTW did you realize we moved over to github: http://github.com/errai/errai

                   

                  Maybe you want to help improving the gilead integration. Currently it's merely a prototype.

                  Especially the question how to provide external persistence context hasn't been solved yet.

                  • 6. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                    misqu23

                    Hi

                     

                    I've checked PersistenceConfiguration, unfortunately with no luck , it seems that errai-bus is simply ignoring custom ModelAdapter.

                     

                    And of course I can help you improve gilead integration I will have to do by myself so I will share my work with pleasure .

                    If you need, you can contact with me using email.

                     

                    Yes, I know that you have moved errai to git, and of course I'm in sync with git.

                    BTW. I have also notice that you have moved errai-cdi to the git but unfortunately I get following build error :

                     

                    [INFO] --------------------------------------------------------------------
                    
                    

                     

                    [INFO] ------------------------------------------------------------------------
                    [INFO] Building Errai::CDI::Examples::Server
                    [INFO]    task-segment: [clean, install]
                    [INFO] ------------------------------------------------------------------------
                    [INFO] [clean:clean {execution: default-clean}]
                    [INFO] Deleting file set: /home/misiek/dev/errai/errai-cdi/examples/server/target (included: [**], excluded: [])
                    [INFO] [resources:resources {execution: default-resources}]
                    [INFO] Using 'UTF-8' encoding to copy filtered resources.
                    [INFO] Copying 2 resources
                    [INFO] Copying 1 resource
                    Downloading: https://repository.jboss.org/nexus/content/groups/public//org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.pom
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:pom:1.0.1-FINAL' in repository jboss-public-repository-group (https://repository.jboss.org/nexus/content/groups/public/)
                    Downloading: https://repository.jboss.org/nexus/content/repositories/deprecated//org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.pom
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:pom:1.0.1-FINAL' in repository jboss-deprecated (https://repository.jboss.org/nexus/content/repositories/deprecated/)
                    Downloading: http://repo1.maven.org/maven2/org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.pom
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:pom:1.0.1-FINAL' in repository central (http://repo1.maven.org/maven2)
                    Downloading: https://repository.jboss.org/nexus/content/groups/public//org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.jar
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:jar:1.0.1-FINAL' in repository jboss-public-repository-group (https://repository.jboss.org/nexus/content/groups/public/)
                    Downloading: https://repository.jboss.org/nexus/content/repositories/deprecated//org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.jar
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:jar:1.0.1-FINAL' in repository jboss-deprecated (https://repository.jboss.org/nexus/content/repositories/deprecated/)
                    Downloading: http://repo1.maven.org/maven2/org/jboss/weld/weld-se/1.0.1-FINAL/weld-se-1.0.1-FINAL.jar
                    [INFO] Unable to find resource 'org.jboss.weld:weld-se:jar:1.0.1-FINAL' in repository central (http://repo1.maven.org/maven2)
                    [INFO] ------------------------------------------------------------------------
                    [ERROR] BUILD ERROR
                    [INFO] ------------------------------------------------------------------------
                    [INFO] Failed to resolve artifact.
                    
                    Missing:
                    ----------
                    1) org.jboss.weld:weld-se:jar:1.0.1-FINAL
                    
                      Try downloading the file manually from the project website.
                    
                      Then, install it using the command: 
                          mvn install:install-file -DgroupId=org.jboss.weld -DartifactId=weld-se -Dversion=1.0.1-FINAL -Dpackaging=jar -Dfile=/path/to/file
                    
                      Alternatively, if you host your own repository you can deploy the file there: 
                          mvn deploy:deploy-file -DgroupId=org.jboss.weld -DartifactId=weld-se -Dversion=1.0.1-FINAL -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
                    
                      Path to dependency: 
                           1) org.jboss.errai:errai-cdi-examples-server:jar:1.1-SNAPSHOT
                           2) org.jboss.weld:weld-se:jar:1.0.1-FINAL
                    
                    ----------
                    1 required artifact is missing.
                    
                    for artifact: 
                      org.jboss.errai:errai-cdi-examples-server:jar:1.1-SNAPSHOT
                    
                    from the specified remote repositories:
                      central (http://repo1.maven.org/maven2),
                      jboss-deprecated (https://repository.jboss.org/nexus/content/repositories/deprecated/),
                      jboss-public-repository-group (https://repository.jboss.org/nexus/content/groups/public/)
                    
                    
                    
                    [INFO] ------------------------------------------------------------------------
                    [INFO] For more information, run Maven with the -e switch
                    [INFO] ------------------------------------------------------------------------
                    [INFO] Total time: 56 seconds
                    [INFO] Finished at: Thu Sep 16 21:15:58 CEST 2010
                    [INFO] Final Memory: 68M/327M
                    [INFO] ------------------------------------------------------------------------
                    
                     
                    
                    • 7. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                      heiko.braun

                      I've checked PersistenceConfiguration, unfortunately with no luck , it seems that errai-bus is simply ignoring custom ModelAdapter.

                       

                      right, is got lost along the way. Didn't survive one of the recent refactorings. However I've re-introduced it. If you update from master then your custom ModelAdapter should be invoked:

                       

                      http://github.com/errai/errai

                      • 8. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                        misqu23

                        Hi Heiko

                         

                        To make it working there is still one thing to do in the DefaultComponents.java line 68 should look like this :

                         

                                        return new MessageModelWrapper(delegate.get(), (ModelAdapter) config.getExtensionBindings().get(ModelAdapter.class).get());
                         
                        
                        

                         

                        Otherwise whether or not we have provided custom model adapter implementaion we always use NoopModelAdapter.

                         

                        With that modification everything works as expected right now.

                         

                        Hope that helps.

                        • 9. Re: Providing custom ModelAdapter implementation using ExtensionCompoment doesn't work.
                          heiko.braun

                          Of course, you are right. next time just send me a pull request through github. We do appreciate small contributions like this as well as full blown feature additions.