Search in sources :

Example 31 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project stanbol by apache.

the class SolrDispatchFilterComponent method activate.

@Activate
protected void activate(ComponentContext context) throws ConfigurationException, ServletException {
    this.context = context;
    BundleContext bc = context.getBundleContext();
    Object value = context.getProperties().get(PROPERTY_SERVER_NAME);
    if (value == null || value.toString().isEmpty()) {
        throw new ConfigurationException(PROPERTY_SERVER_NAME, "The configured CoreContainer name MUST NOT be NULL nor empty!");
    }
    serverName = value.toString();
    String filterString = String.format("(&(%s=%s)(%s=%s))", Constants.OBJECTCLASS, CoreContainer.class.getName(), SolrConstants.PROPERTY_SERVER_NAME, serverName);
    try {
        tracker = new ServiceTracker(bc, bc.createFilter(filterString), trackerCustomizer);
    } catch (InvalidSyntaxException e) {
        throw new ConfigurationException(PROPERTY_SERVER_NAME, "Unable to build Filter for parsed CoreContainer name '" + serverName + "'", e);
    }
    value = context.getProperties().get(PROPERTY_PREFIX_PATH);
    final String prefixPath;
    if (value != null) {
        prefix = value.toString();
        if (prefix.charAt(0) != '/') {
            prefix = '/' + prefix;
        }
        prefixPath = prefix;
        if (!prefix.endsWith("*")) {
            //TODO: check if this is a good idea
            prefix = prefix + "/.*";
        }
    } else {
        prefixPath = null;
        prefix = "/.*";
    }
    filterPrpoerties = new Hashtable<String, Object>();
    if (prefixPath != null) {
        filterPrpoerties.put("path-prefix", prefixPath);
    }
    //now start tracking! ...
    //  ... as soon as the first CoreContainer is tracked the Filter will
    //      be created and added to the ExtHttpService
    tracker.open();
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceTracker(org.osgi.util.tracker.ServiceTracker) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 32 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project stanbol by apache.

the class EntityhubComponent method activate.

@Activate
protected void activate(final ComponentContext context) throws ConfigurationException {
    this.bc = context.getBundleContext();
    Dictionary<?, ?> properties = context.getProperties();
    log.info("Activate Entityhub Component:");
    this.entityhubID = OsgiUtils.checkProperty(properties, ID).toString();
    if (entityhubID == null || entityhubID.isEmpty()) {
        throw new ConfigurationException(ID, "The id for the Entityhub MUST NOT be empty!");
    } else {
        log.debug("   + id: {}", entityhubID);
    }
    this.entityhubName = OsgiUtils.checkProperty(properties, NAME, this.entityhubID).toString();
    if (entityhubName.isEmpty()) {
        throw new ConfigurationException(NAME, "The name for the Entityhub MUST NOT be empty!");
    } else {
        log.debug("   + name: {}", entityhubName);
    }
    Object entityhubDescriptionObject = properties.get(DESCRIPTION);
    this.entityhubDescription = entityhubDescriptionObject == null ? null : entityhubDescriptionObject.toString();
    log.debug("   + description: {}", entityhubDescription == null ? "<none>" : entityhubDescription);
    this.entityhubPrefix = OsgiUtils.checkProperty(properties, PREFIX).toString();
    if (entityhubPrefix.isEmpty()) {
        throw new ConfigurationException(PREFIX, "The UIR preix for the Entityub MUST NOT be empty!");
    }
    try {
        new URI(entityhubPrefix);
        log.info("   + prefix: " + entityhubPrefix);
    } catch (URISyntaxException e) {
        throw new ConfigurationException(PREFIX, "The URI prefix for the Entityhub " + "MUST BE an valid URI (prefix=" + entityhubPrefix + ")", e);
    }
    Object defaultSymbolState = properties.get(DEFAULT_SYMBOL_STATE);
    if (defaultSymbolState == null) {
        this.defaultSymblStateString = ManagedEntity.DEFAULT_SYMBOL_STATE.name();
    } else {
        this.defaultSymblStateString = defaultSymbolState.toString();
    }
    Object defaultMappingState = properties.get(DEFAULT_MAPPING_STATE);
    if (defaultMappingState == null) {
        this.defaultMappingStateString = EntityMapping.DEFAULT_MAPPING_STATE.name();
    } else {
        this.defaultMappingStateString = defaultMappingState.toString();
    }
    Object fieldMappingConfigObject = OsgiUtils.checkProperty(properties, FIELD_MAPPINGS);
    if (fieldMappingConfigObject instanceof String[]) {
        this.fieldMappingConfig = (String[]) fieldMappingConfigObject;
    } else {
        throw new ConfigurationException(FIELD_MAPPINGS, "Values for this property must be of type Stirng[]!");
    }
    String entityhubYardId = OsgiUtils.checkProperty(properties, ENTITYHUB_YARD_ID).toString();
    String filterString = String.format("(&(%s=%s)(%s=%s))", Constants.OBJECTCLASS, Yard.class.getName(), Yard.ID, entityhubYardId);
    log.debug(" ... tracking EntityhubYard by Filter:" + filterString);
    Filter filter;
    try {
        filter = context.getBundleContext().createFilter(filterString);
    } catch (InvalidSyntaxException e) {
        throw new ConfigurationException(ENTITYHUB_YARD_ID, "Unable to parse OSGI filter '" + filterString + "' for configured Yard id '" + entityhubYardId + "'!", e);
    }
    entityhubYardTracker = new ServiceTracker(context.getBundleContext(), filter, new ServiceTrackerCustomizer() {

        final BundleContext bc = context.getBundleContext();

        @Override
        public void removedService(ServiceReference reference, Object service) {
            if (service.equals(entityhubYard)) {
                entityhubYard = (Yard) entityhubYardTracker.getService();
                updateServiceRegistration(bc, entityhubYard, siteManager, nsPrefixService);
            }
            bc.ungetService(reference);
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            //the service.ranking might have changed ... so check if the
            //top ranked yard is a different one
            Yard newYard = (Yard) entityhubYardTracker.getService();
            if (newYard == null || !newYard.equals(entityhubYard)) {
                //set the new yard
                entityhubYard = newYard;
                //and update the service registration
                updateServiceRegistration(bc, entityhubYard, siteManager, nsPrefixService);
            }
        }

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = bc.getService(reference);
            if (service != null) {
                if (//the first added Service or
                entityhubYardTracker.getServiceReference() == null || //the new service as higher ranking as the current
                (reference.compareTo(entityhubYardTracker.getServiceReference()) > 0)) {
                    entityhubYard = (Yard) service;
                    updateServiceRegistration(bc, entityhubYard, siteManager, nsPrefixService);
                }
            // else the new service has lower ranking as the currently use one
            }
            //else service == null -> ignore
            return service;
        }
    });
    //start the tracking
    entityhubYardTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ServiceReference(org.osgi.framework.ServiceReference) Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) ConfigurationException(org.osgi.service.cm.ConfigurationException) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext) Activate(org.apache.felix.scr.annotations.Activate)

Example 33 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project sling by apache.

the class PostOperationProxyProvider method activate.

// DS activation/deactivation
/**
     * Activates the proxy provider component:
     * <ol>
     * <li>Keep BundleContext reference</li>
     * <li>Start listening for SlingPostOperation services</li>
     * <li>Register proxies for all existing SlingPostOperation services</li>
     * </ol>
     */
@SuppressWarnings("unused")
@Activate
private void activate(final BundleContext bundleContext) {
    this.bundleContext = bundleContext;
    try {
        bundleContext.addServiceListener(this, REFERENCE_FILTER);
        final ServiceReference[] serviceReferences = bundleContext.getServiceReferences(SlingPostOperation.SERVICE_NAME, null);
        if (serviceReferences != null) {
            for (ServiceReference serviceReference : serviceReferences) {
                register(serviceReference);
            }
        }
    } catch (InvalidSyntaxException ise) {
    // not expected for tested static filter
    // TODO:log !!
    }
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.osgi.service.component.annotations.Activate)

Example 34 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project sling by apache.

the class TenantProviderImpl method getTenants.

@Override
public Iterator<Tenant> getTenants(final String tenantFilter) {
    final Filter filter;
    if (tenantFilter != null && tenantFilter.length() > 0) {
        try {
            filter = FrameworkUtil.createFilter(tenantFilter);
        } catch (InvalidSyntaxException e) {
            throw new IllegalArgumentException(e.getMessage(), e);
        }
    } else {
        filter = null;
    }
    Iterator<Tenant> result = call(new ResourceResolverTask<Iterator<Tenant>>() {

        @SuppressWarnings("unchecked")
        @Override
        public Iterator<Tenant> call(ResourceResolver resolver) {
            Resource tenantRootRes = resolver.getResource(tenantRootPath);
            if (tenantRootRes != null) {
                List<Tenant> tenantList = new ArrayList<Tenant>();
                Iterator<Resource> tenantResourceList = tenantRootRes.listChildren();
                while (tenantResourceList.hasNext()) {
                    Resource tenantRes = tenantResourceList.next();
                    if (filter == null || filter.matches(ResourceUtil.getValueMap(tenantRes))) {
                        TenantImpl tenant = new TenantImpl(tenantRes);
                        tenantList.add(tenant);
                    }
                }
                return tenantList.iterator();
            }
            return Collections.EMPTY_LIST.iterator();
        }
    });
    if (result == null) {
        // no filter or no resource resolver for calling
        result = Collections.<Tenant>emptyList().iterator();
    }
    return result;
}
Also used : Resource(org.apache.sling.api.resource.Resource) Tenant(org.apache.sling.tenant.Tenant) Filter(org.osgi.framework.Filter) Iterator(java.util.Iterator) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project sling by apache.

the class DistributionAgentCreationFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    SlingHttpServletRequest servletRequest = (SlingHttpServletRequest) request;
    // only intercept POST requests
    if (METHOD_POST.equalsIgnoreCase(servletRequest.getMethod())) {
        String name = request.getParameter(NAME);
        String type = request.getParameter(TYPE);
        if (type != null && name != null) {
            String filter = format(FACTORY_FILTER_PATTERN, name, type);
            try {
                ServiceReference[] services = context.getAllServiceReferences(DistributionAgent.class.getName(), filter);
                if (services != null && services.length > 0) {
                    String errorMessage = format("An agent named '%s' of different type than '%s' was already previously registered, please change the Agent name.", name, type);
                    ((HttpServletResponse) response).sendError(SC_CONFLICT, errorMessage);
                    return;
                }
            } catch (InvalidSyntaxException e) {
                // should not happen...
                log.error("Impossible to access to {} references", DistributionAgent.class.getName(), e);
            }
        }
    }
    chain.doFilter(request, response);
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) HttpServletResponse(javax.servlet.http.HttpServletResponse) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)105 ServiceReference (org.osgi.framework.ServiceReference)54 Filter (org.osgi.framework.Filter)26 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)20 BundleContext (org.osgi.framework.BundleContext)16 ServiceTracker (org.osgi.util.tracker.ServiceTracker)14 HashMap (java.util.HashMap)12 Configuration (org.osgi.service.cm.Configuration)12 Map (java.util.Map)10 Test (org.junit.Test)9 Dictionary (java.util.Dictionary)8 Hashtable (java.util.Hashtable)8 List (java.util.List)6 ConfigurationException (org.osgi.service.cm.ConfigurationException)6 Metacard (ddf.catalog.data.Metacard)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 CatalogFramework (ddf.catalog.CatalogFramework)3 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)3 InputTransformer (ddf.catalog.transform.InputTransformer)3