[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-3965) @Providers not working - ResteasyDispatcher registers components and providers in wrong order

Balazs Pataki (JIRA) jira-events at lists.jboss.org
Fri Feb 20 09:32:49 EST 2009


    [ https://jira.jboss.org/jira/browse/JBSEAM-3965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12453490#action_12453490 ] 

Balazs Pataki commented on JBSEAM-3965:
---------------------------------------

Jozef,

thanks for the clarification! Hope I not bother you too much, however I have a developing story. :-)

 It seems to me that one cannot register a provider which is also a Seam component.

I have this converter:

@Name("TaskConverter")
@Provider
@Scope(ScopeType.APPLICATION)
public class TaskConverter implements StringConverter<Task>{

    @Logger private Log log;

    @In EntityManager entityManager;

	public Task fromString(String id) {	
		Task obj = entityManager.find(Task.class, id);
        return obj;
    }

	public String toString(Task obj) {
		return String.valueOf(obj.getId());
	}	
}   

Basically, when I get an ID ina REST call I want to transparently convert it to the matching Task object with this ID.

It is registered by ResteasyDispatcher like this:

	public void onStartup()
	...
			else if (ScopeType.APPLICATION.equals(seamComponent.getScope()))
                {
                    Object providerInstance = Component.getInstance(seamComponent.getName());
                    providerFactory.registerProviderInstance(providerInstance);
                }
	...
Then ResteasyProviderFactory is called and in effect its addStringConverter() gets invoked:

   public void addStringConverter(StringConverter provider)
   {
      providers.put(provider.getClass(), provider);
      PropertyInjectorImpl injector = new PropertyInjectorImpl(provider.getClass(), this);
      injector.inject(provider);
      Type[] intfs = provider.getClass().getGenericInterfaces();
      for (Type type : intfs)
      {
         if (type instanceof ParameterizedType)
         {
            ParameterizedType pt = (ParameterizedType) type;
            if (pt.getRawType().equals(StringConverter.class))
            {
               Class<?> aClass = Types.getRawType(pt.getActualTypeArguments()[0]);
               stringConverters.put(aClass, provider);
            }
         }
      }
   }	

Now, when I debug addStringConverter I can see the following:

provider is of type TaskConverter_$$_javassist_seam_3

intfs is Class<T>[5] = [interface org.jboss.seam.Instance, interface org.jboss.seam.intercept.Proxy, interface javax.servlet.http.HttpSessionActivationListener, interface org.jboss.seam.core.Mutable, interface javassist.util.proxy.ProxyObject]

Now, there should probably be there a StringConverter<Task> interface as well so that the "if (type instanceof ParameterizedType)" evaluate to true and so my TaskConverter to be registered. However there's no StringConverter<Task> interface in the "intfs" list (although the provider parameter at the source code level is of type StringConverter). Maybe javassist screws up something ...

Nevertheless, the current situation seems to be that one cannot register a provider which is also a Seam component.

Could you please confirm that this is actually the case, or should I do some other configuration or annotation to have an object act both as a provider and a Seam component?

Thanks,
---
balazs


> @Providers not working - ResteasyDispatcher registers components and providers in wrong order
> ---------------------------------------------------------------------------------------------
>
>                 Key: JBSEAM-3965
>                 URL: https://jira.jboss.org/jira/browse/JBSEAM-3965
>             Project: Seam
>          Issue Type: Bug
>          Components: WS
>    Affects Versions: 2.1.1.CR1
>            Reporter: Balazs Pataki
>            Assignee: Jozef Hartinger
>
> While using the latest nightly build (from 2009.02.19) I found that my @Provider annotated class is not used by Seam+RESTEasy. It seemed to be loaded but not used by injection mechanism. By debugging the code I found out that it is not used because org.jboss.seam.resteasy.ResteasyDispatcher#onStartup()  first registers the resources and after that the providers. However, as part of the resource registration the injection mechanism including the converters are set up, however at this point the converters (providers) have not been loaded.
> It seems to first load the providers and then the resources.
> This is my patch that worked in my setup:
> > diff -c ResteasyDispatcher.java ResteasyDispatcher_orig.java                                                     
> *** ResteasyDispatcher.java     2009-02-20 11:10:35.000000000 +0100                                                
> --- ResteasyDispatcher_orig.java        2009-02-19 00:18:26.000000000 +0100                                        
> ***************                                                                                                    
> *** 56,91 ****                                                                                                     
>           getDispatcher().setLanguageMappings(application.getLanguageMappings());                                  
>           getDispatcher().setMediaTypeMappings(application.getMediaTypeMappings());                                
>                                                                                                                    
> -         // Provider registration                                                                                 
> -         if (application.isUseBuiltinProviders())                                                                 
> -         {                                                                                                        
> -             log.info("registering built-in RESTEasy providers");                                                 
> -             RegisterBuiltin.register(providerFactory);                                                           
> -         }                                                                                                        
> -         for (Class providerClass : application.getProviderClasses())                                             
> -         {                                                                                                        
> -             Component seamComponent = application.getProviderClassComponent(providerClass);                      
> -             if (seamComponent != null)                                                                           
> -             {                                                                                                    
> -                 if (ScopeType.STATELESS.equals(seamComponent.getScope()))                                        
> -                 {                                                                                                
> -                     throw new RuntimeException(                                                                  
> -                             "Registration of STATELESS Seam components as RESTEasy providers not implemented!"   
> -                     );                                                                                           
> -                 }                                                                                                
> -                 else if (ScopeType.APPLICATION.equals(seamComponent.getScope()))                                 
> -                 {                                                                                                
> -                     Object providerInstance = Component.getInstance(seamComponent.getName());                    
> -                     providerFactory.registerProviderInstance(providerInstance);                                  
> -                 }                                                                                                
> -             }                                                                                                    
> -             else                                                                                                 
> -             {                                                                                                    
> -                 // Just plain RESTEasy, no Seam component lookup or lifecycle                                    
> -                 providerFactory.registerProvider(providerClass);                                                 
> -             }                                                                                                    
> -         }                                                                                                        
> -                                                                                                                  
>           // Resource registration                                                                                 
>           Registry registry = getDispatcher().getRegistry();                                                       
>           for (final Class resourceClass : application.getClasses())                                               
> --- 56,61 ----                                                                                                     
> ***************                                                                                                    
> *** 133,137 ****                                                                                                   
> --- 103,138 ----                                                                                                   
>                   registry.addResourceFactory(new POJOResourceFactory(resourceClass));                             
>               }                                                                                                    
>           }                                                                                                        
> +                                                                                                                  
> +         // Provider registration                                                                                 
> +         if (application.isUseBuiltinProviders())                                                                 
> +         {                                                                                                        
> +             log.info("registering built-in RESTEasy providers");                                                 
> +             RegisterBuiltin.register(providerFactory);
> +         }
> +         for (Class providerClass : application.getProviderClasses())
> +         {
> +             Component seamComponent = application.getProviderClassComponent(providerClass);
> +             if (seamComponent != null)
> +             {
> +                 if (ScopeType.STATELESS.equals(seamComponent.getScope()))
> +                 {
> +                     throw new RuntimeException(
> +                             "Registration of STATELESS Seam components as RESTEasy providers not implemented!"
> +                     );
> +                 }
> +                 else if (ScopeType.APPLICATION.equals(seamComponent.getScope()))
> +                 {
> +                     Object providerInstance = Component.getInstance(seamComponent.getName());
> +                     providerFactory.registerProviderInstance(providerInstance);
> +                 }
> +             }
> +             else
> +             {
> +                 // Just plain RESTEasy, no Seam component lookup or lifecycle
> +                 providerFactory.registerProvider(providerClass);
> +             }
> +         }
> +
>       }
>   }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list