@Override public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) { TrackingStruct struct = new TrackingStruct(); try { String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER); Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null; ResourceAnalyzer analyzer = context.getService(reference); if (analyzer == null) return null; struct = new TrackingStruct(); struct.analyzer = analyzer; struct.filter = filter; struct.valid = true; indexer.addAnalyzer(analyzer, filter); } catch (InvalidSyntaxException e) { struct.valid = false; log.log( reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e); } return struct; }
/** * creates a Filter, but wraps the {@link InvalidSyntaxException} into an {@link * IllegalArgumentException} */ public static Filter createFilter(String filterString) { try { return FrameworkUtil.createFilter(filterString); } catch (InvalidSyntaxException e) { throw new IllegalArgumentException(e); } }
public DDMFormFieldValueRendererRegistryImpl() { Class<?> clazz = getClass(); Bundle bundle = FrameworkUtil.getBundle(clazz); _bundleContext = bundle.getBundleContext(); Filter filter = null; try { filter = FrameworkUtil.createFilter( "(&(objectClass=" + DDMFormFieldValueRenderer.class.getName() + ")(!(objectClass=" + clazz.getName() + ")))"); } catch (InvalidSyntaxException ise) { ReflectionUtil.throwException(ise); } _serviceTracker = new ServiceTracker<>( _bundleContext, filter, new DDMFormFieldValueRendererServiceTrackerCustomizer()); _serviceTracker.open(); }
public void execute(@Observes(precedence = Integer.MAX_VALUE) EventContext<BeforeSuite> event) throws Exception { Bundle bundle = FrameworkUtil.getBundle(getClass()); BundleContext bundleContext = bundle.getBundleContext(); Filter filter = FrameworkUtil.createFilter( "(&(objectClass=org.springframework.context.ApplicationContext)" + "(org.springframework.context.service.name=" + bundleContext.getBundle().getSymbolicName() + "))"); ServiceTracker<ApplicationContext, ApplicationContext> serviceTracker = new ServiceTracker<>(bundleContext, filter, null); serviceTracker.open(); try { serviceTracker.waitForService(30 * 1000L); } catch (InterruptedException e) { throw new RuntimeException(e); } serviceTracker.close(); event.proceed(); }
Filter getAuthFilter() throws InvalidSyntaxException { StringBuilder sb = new StringBuilder("("); // $NON-NLS-1$ sb.append(ServerConstants.CONFIG_AUTH_NAME); sb.append('='); sb.append(getAuthName()); sb.append(')'); return FrameworkUtil.createFilter(sb.toString()); }
@Override public Filter makeFilterForClass(String className) { try { return FrameworkUtil.createFilter(String.format("(%s=%s)", Constants.OBJECTCLASS, className)); } catch (InvalidSyntaxException e) { throw new IllegalArgumentException(e); } }
private Filter getFilter() { if (appliedFilter == null) { try { appliedFilter = FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { // we will return null } } return appliedFilter; }
@Override public Filter getFilterForLocation(String location, String context) throws IllegalArgumentException { String filter = makeLocationFilterString(location, context); try { return FrameworkUtil.createFilter(filter); } catch (InvalidSyntaxException e) { throw new IllegalArgumentException("location is invalid: " + location, e); } }
@Override public Filter makeFilter(String className, String otherFilter) throws IllegalArgumentException { if (otherFilter == null) { return makeFilterForClass(className); } try { return FrameworkUtil.createFilter("(&" + makeFilterForClass(className) + otherFilter + ")"); } catch (InvalidSyntaxException e) { throw new IllegalArgumentException(e); } }
@Override public List<ServiceState> getServiceReferences( AbstractBundle bundleState, String clazz, String filterStr, boolean checkAssignable) throws InvalidSyntaxException { Filter filter = null; if (filterStr != null) filter = FrameworkUtil.createFilter(filterStr); List<ServiceState> result = getServiceReferencesInternal(bundleState, clazz, filter, checkAssignable); result = processFindHooks(bundleState, clazz, filterStr, checkAssignable, result); return result; }
/** * Parse filter string into a Filter object. * * @param filterString The filter string to parse. * @return a Filter for this subsystem. If the specified filterString equals "*", then {@code * null} is returned to indicate a wildcard. * @throws IllegalArgumentException If the filter syntax is invalid. */ private static Filter parseFilter(String filterString) { filterString = filterString.trim(); if (filterString.equals("*")) { return null; } try { return FrameworkUtil.createFilter(filterString); } catch (InvalidSyntaxException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid filter"); iae.initCause(e); throw iae; } }
/** * Constructs an ApplicationAdminPermission. The {@code filter} specifies the target application. * The {@code filter} is an LDAP-style filter, the recognized properties are {@code signer} and * {@code pid}. The pattern specified in the {@code signer} is matched with the Distinguished Name * chain used to sign the application. Wildcards in a DN are not matched according to the filter * string rules, but according to the rules defined for a DN chain. The attribute {@code pid} is * matched with the PID of the application according to the filter string rules. * * <p>If the {@code filter} is {@code null} then it matches {@code "*"}. If {@code actions} is * {@code "*"} then it identifies all the possible actions. * * @param filter filter to identify application. The value {@code null} is equivalent to {@code * "*"} and it indicates "all application". * @param actions comma-separated list of the desired actions granted on the applications or "*" * means all the actions. It must not be {@code null}. The order of the actions in the list is * not significant. * @throws InvalidSyntaxException is thrown if the specified {@code filter} is not syntactically * correct. * @exception NullPointerException is thrown if the actions parameter is {@code null} * @see ApplicationDescriptor * @see org.osgi.framework.AdminPermission */ public ApplicationAdminPermission(String filter, String actions) throws InvalidSyntaxException { super(filter == null ? "*" : filter); if (filter == null) filter = "*"; if (actions == null) throw new NullPointerException("Action string cannot be null!"); this.applicationDescriptor = null; this.filter = (filter == null ? "*" : filter); this.actions = actions; if (!filter.equals("*") && !filter.equals("<<SELF>>")) FrameworkUtil.createFilter(this.filter); // check if the filter is valid init(); }
public boolean matches(Capability capability) { if (capability instanceof BundleCapability) return matches((BundleCapability) capability); // now we must do the generic thing if (!namespace.equals(capability.getNamespace())) return false; String filterSpec = getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); try { if (filterSpec != null && !FrameworkUtil.createFilter(filterSpec).matches(capability.getAttributes())) return false; } catch (InvalidSyntaxException e) { return false; } return hasMandatoryAttributes( ManifestElement.getArrayFromList( capability .getDirectives() .get(AbstractWiringNamespace.CAPABILITY_MANDATORY_DIRECTIVE))); }
protected <T> T getOsgiService(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(bundleContext, osgiFilter, null); tracker.open(true); // Note that the tracker is not closed to keep the reference // This is buggy, as the service reference may change i think Object svc = type.cast(tracker.waitForService(timeout)); if (svc == null) { Dictionary dic = bundleContext.getBundle().getHeaders(); System.err.println("Test bundle headers: " + explode(dic)); for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) { System.err.println("ServiceReference: " + ref); } for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) { System.err.println("Filtered ServiceReference: " + ref); } 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); } }
@Override protected void doInit() throws Exception { final String filterStr = getApplicationContext().getInitProperties().get("filter"); if (null != filterStr) { try { filter = FrameworkUtil.createFilter(filterStr); } catch (final InvalidSyntaxException e) { throw new IllegalArgumentException( String.format( "The specified filter '%s' is invalid. Please check the application configuration. %s", filterStr, e.getMessage()), e); } } final Dictionary<String, Object> props = new Hashtable<String, Object>(getApplicationContext().getInitProperties()); if (null == props.get(Constants.SERVICE_DESCRIPTION)) { props.put(Constants.SERVICE_DESCRIPTION, "Gyrex web application based OSGi HttpService"); } if (null == props.get(Constants.SERVICE_VENDOR)) { props.put(Constants.SERVICE_VENDOR, "Eclipse Gyrex"); } if (null == props.get(Constants.SERVICE_PID)) { props.put( Constants.SERVICE_PID, HttpActivator.SYMBOLIC_NAME.concat(".service-").concat(getId())); } serviceRegistration = HttpActivator.getInstance() .getBundle() .getBundleContext() .registerService( new String[] {HttpService.class.getName(), ExtendedHttpService.class.getName()}, this, props); }
// wait for the Jetty or Tomcat to start fully protected void postProcessBundleContext(BundleContext context) throws Exception { super.postProcessBundleContext(context); // create a filter for our server implementations Filter filter = FrameworkUtil.createFilter( "(&(org.springframework.osgi.bean.name=*-server)(" + Constants.SERVICE_VENDOR + "=Spring Dynamic Modules))"); ServiceTracker tracker = new ServiceTracker(context, filter, null); tracker.open(); try { // wait for 7 seconds max Object server = tracker.waitForService(7 * 1000); if (server == null) throw new IllegalStateException("no web container server found"); } finally { tracker.close(); } // the server has been started, check if the app has been properly deployed // before that however, wait 2 secs to war to be unpacked and installed Thread.sleep(2 * 1000); logger.debug("Checking webapp deployed at " + base()); long start = System.currentTimeMillis(); long waited; HttpResponse resp; // wait until the page is up do { resp = HttpClient.getLocalResponse(base()); waited = System.currentTimeMillis() - start; // wait 1 second if (!resp.isOk()) Thread.sleep(2 * 1000); } while (waited < WEB_APP_START_TIMEOUT && !resp.isOk()); }
@Override public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) { if (struct.valid) { indexer.removeAnalyzer(struct.analyzer, struct.filter); } try { String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER); Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null; struct = new TrackingStruct(); struct.filter = filter; struct.valid = true; indexer.addAnalyzer(struct.analyzer, filter); } catch (InvalidSyntaxException e) { struct.valid = false; log.log( reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e); } }
public Filter createFilter(String filter) throws InvalidSyntaxException { return FrameworkUtil.createFilter(filter); }