Changeset 763

Show
Ignore:
Timestamp:
17/11/08 13:28:21 (2 months ago)
Author:
bruno
Message:

Remove shielding of KauriRouter?'s created by the RoutingService?. The shield switches the context classloader to the one of the routing module, but during routing execution it is more logical that the context classloader of the routing-using-module is used. The context classloader is now set to the one of the routing module only during building of the routing structure.
Thanks to jgou for reporting this issue.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/modules/kauri-routing/kauri-routing-impl/src/main/java/org/kauriproject/routing/impl/RoutingServiceImpl.java

    r651 r763  
    55import org.kauriproject.routing.impl.routing.KauriRouter; 
    66import org.kauriproject.runtime.rapi.KauriModule; 
    7 import org.kauriproject.runtime.module.Module; 
    8 import org.kauriproject.runtime.module.restservice.RestserviceFacet; 
    97import org.restlet.Restlet; 
    108import org.restlet.Context; 
    119 
    1210public class RoutingServiceImpl implements RoutingService { 
    13     private RestserviceFacet restserviceFacet
     11    private KauriModule routingModule
    1412 
    1513    public RoutingServiceImpl(KauriModule kauriModule) { 
    16         restserviceFacet = ((Module)kauriModule.getImplementation()).getRestserviceFacet()
     14        this.routingModule = kauriModule
    1715    } 
    1816 
     
    2220 
    2321    public Restlet createRouter(Context context, KauriModule module, RoutingConfig routingConfig) { 
    24         // Shielding the restlet is necessary in order for the ContextClassloader to switch, which is 
    25         // needed for the JAX-RS implementation to be found 
    2622        if (routingConfig == null) 
    2723            routingConfig = new RoutingConfig(); 
    2824 
    29         return restserviceFacet.shieldRestlet(new KauriRouter(context, module, routingConfig)); 
     25        return new KauriRouter(context, module, routingConfig, routingModule); 
    3026    } 
    3127} 
  • trunk/modules/kauri-routing/kauri-routing-impl/src/main/java/org/kauriproject/routing/impl/routing/KauriRouter.java

    r748 r763  
    2727    private ApplicationContext applicationContext; 
    2828    private ReloadableResource reloadableResource; 
     29    private KauriModule routingModule; 
    2930 
    30     public KauriRouter(Context context, KauriModule module, RoutingConfig routingConfig) { 
     31    public KauriRouter(Context context, KauriModule module, RoutingConfig routingConfig, KauriModule routingModule) { 
    3132        super(context); 
    3233 
     
    3435        this.module = module; 
    3536        this.routingConfig = routingConfig; 
     37        this.routingModule = routingModule; 
    3638 
    3739        this.applicationContext = ((Module)module.getImplementation()).getApplicationContext(); 
     
    4749 
    4850    private ReloadableResource.Result build() { 
     51        // During building, set the context classloader to the classloader of the routing module implementation. 
     52        // This e.g. helps the JAX-RS RuntimeDelegate to find its implementation. 
     53        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); 
     54        Thread.currentThread().setContextClassLoader(routingModule.getClassLoader()); 
    4955        try { 
    5056            log.debug("Rebuilding routing setup."); 
     
    7480            }, Collections.<DisposableRoutingComponent>emptyList()); 
    7581            return new ReloadableResource.Result(routerData, t); 
     82        } finally { 
     83            Thread.currentThread().setContextClassLoader(oldContextClassLoader); 
    7684        } 
    7785    }