Hello, 
I esayes to recover the blueprintcontainer from a servlet that I record 
WebContainer. Unfortunately, I can not retrieve the blueprintcontainer, here is 
my code:  
 Bundle bundle = FrameworkUtil.getBundle(getClass());        BlueprintContainer 
blueprintContainer = getBlueprintContainerForBundle(bundle.getBundleContext() , 
bundle.getSymbolicName());
        SimpleUrlHandlerMapping simpleUrlHandlerMapping = 
(SimpleUrlHandlerMapping) 
blueprintContainer.getComponentInstance("urlMapping");    }
    public BlueprintContainer getBlueprintContainerForBundle(BundleContext 
context, String symbolicName) {        return getService(context , 
BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + 
symbolicName + ")" , 5000);    }
    public <T> T getService(BundleContext context, Class<T> type, String 
filter, long timeout) {        ServiceTracker tracker = null;        try {      
      String flt;            if (filter != null) {                if 
(filter.startsWith("(")) {                    flt = "(&(" + 
Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";              
  } else {                    flt = "(&(" + Constants.OBJECTCLASS + "=" + 
type.getName() + ")(" + filter + "))";                }            } else {     
           flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";      
      }            Filter osgiFilter = FrameworkUtil.createFilter(flt);         
   tracker = new ServiceTracker(context, osgiFilter, null);            
tracker.open();
            Object svc = type.cast(tracker.waitForService(timeout));            
if (svc == null) {                System.out.println("Could not obtain a 
service in time, service-ref=" +                        
tracker.getServiceReference() +                        ", time=" + 
System.currentTimeMillis());                throw new RuntimeException("Gave up 
waiting for service " + flt);            }            return type.cast(svc);    
    } catch (InvalidSyntaxException e) {            throw new 
IllegalArgumentException("Invalid filter", e);        } catch 
(InterruptedException e) {            throw new RuntimeException(e);        }   
 }                                        

Reply via email to