use of org.osgi.framework.InvalidSyntaxException in project karaf by apache.
the class KarafTestSupport method getOsgiService.
@SuppressWarnings({ "rawtypes", "unchecked" })
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);
}
}
use of org.osgi.framework.InvalidSyntaxException in project karaf by apache.
the class SecuredCommandConfigTransformer method refreshTheAffectedShellCommandBundle.
private void refreshTheAffectedShellCommandBundle(ConfigurationEvent event, Configuration config) {
if (!config.getPid().startsWith(PROXY_COMMAND_ACL_PID_PREFIX)) {
// not a command scope configuration file
return;
}
String filter = "";
String scopeName = config.getPid().substring(PROXY_COMMAND_ACL_PID_PREFIX.length());
if (scopeName.indexOf('.') >= 0) {
// scopes don't contains dots, not a command scope
return;
}
scopeName = scopeName.trim();
for (Entry<String, String> entry : loadScopeBundleMaps().entrySet()) {
if (entry.getKey().equals(scopeName)) {
filter = "(" + "osgi.blueprint.container.symbolicname" + "=" + entry.getValue() + ")";
break;
}
}
if (filter.length() == 0) {
return;
}
BundleContext bundleContext = event.getReference().getBundle().getBundleContext();
try {
ServiceReference<?>[] sr = bundleContext.getServiceReferences("org.osgi.service.blueprint.container.BlueprintContainer", filter);
if (sr == null) {
LOGGER.error("can't find the command bundle for scope " + scopeName);
return;
}
LOGGER.debug("the refreshed bundle is " + sr[0].getBundle().getSymbolicName());
ServiceReference ref = bundleContext.getServiceReference(PackageAdmin.class.getName());
if (ref == null) {
LOGGER.error("PackageAdmin service is unavailable.");
return;
}
try {
PackageAdmin pa = (PackageAdmin) bundleContext.getService(ref);
if (pa == null) {
LOGGER.error("PackageAdmin service is unavailable.");
return;
}
pa.refreshPackages(new Bundle[] { sr[0].getBundle() });
} finally {
bundleContext.ungetService(ref);
}
} catch (InvalidSyntaxException ex) {
LOGGER.error("Problem refresh the affected shell command bundle", ex);
}
}
use of org.osgi.framework.InvalidSyntaxException in project jackrabbit-oak by apache.
the class SegmentBlobTrackerRegistrationTest method unregisterNodeStoreService.
@Override
protected void unregisterNodeStoreService() {
ServiceReference[] serviceReferences;
try {
serviceReferences = context.bundleContext().getServiceReferences(SegmentNodeStoreService.class.getName(), null);
} catch (InvalidSyntaxException e) {
throw new IllegalStateException("Unable to read references to SegmentNodeStoreService", e);
}
for (ServiceReference serviceReference : serviceReferences) {
Object service = context.bundleContext().getService(serviceReference);
if (service == null) {
continue;
}
deactivate(service, serviceReference.getBundle().getBundleContext());
}
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class BundleRepositoryManagerImpl method getBundleRepositoryCollection.
public Collection<BundleRepository> getBundleRepositoryCollection(String appName, String appVersion) {
LOGGER.debug(LOG_ENTRY, "getBundleRepositoryCollection", new Object[] { appName, appVersion });
ServiceCollection<BundleRepository> providers = new ArrayServiceList<BundleRepository>(bc);
String appScope = appName + "_" + appVersion;
String filter = "(|(" + BundleRepository.REPOSITORY_SCOPE + "=" + BundleRepository.GLOBAL_SCOPE + ")(" + BundleRepository.REPOSITORY_SCOPE + "=" + appScope + "))";
try {
ServiceReference[] refs = bc.getServiceReferences(BundleRepository.class.getName(), filter);
if (refs != null) {
for (ServiceReference ref : refs) {
providers.addService(ref);
}
}
} catch (InvalidSyntaxException e) {
LOGGER.error(LOG_EXCEPTION, e);
}
LOGGER.debug(LOG_EXIT, "getBundleRepositoryCollection");
return providers;
}
use of org.osgi.framework.InvalidSyntaxException in project aries by apache.
the class DeploymentMetadataImpl method getFilters.
private Collection<Filter> getFilters(String filterString) throws InvalidAttributeException {
Collection<Filter> filters = new ArrayList<Filter>();
List<String> fs = ManifestProcessor.split(filterString, ",");
if ((fs != null) && (!!!fs.isEmpty())) {
for (String filter : fs) {
try {
filters.add(FrameworkUtil.createFilter(FilterUtils.removeMandatoryFilterToken(filter)));
} catch (InvalidSyntaxException ise) {
InvalidAttributeException iae = new InvalidAttributeException(ise);
throw iae;
}
}
}
return filters;
}
Aggregations