Search in sources :

Example 6 with MdsRestFacade

use of org.motechproject.mds.rest.MdsRestFacade in project motech by motech.

the class MdsRestFacadeRetriever method getRestFacade.

public MdsRestFacade getRestFacade(String entityName, String moduleName, String namespace) {
    String restId = ClassName.restId(entityName, moduleName, namespace);
    MdsRestFacade restFacade = null;
    try {
        String filter = String.format("(org.eclipse.gemini.blueprint.bean.name=%s)", restId);
        Collection<ServiceReference<MdsRestFacade>> refs = bundleContext.getServiceReferences(MdsRestFacade.class, filter);
        if (refs != null && refs.size() > 1 && LOGGER.isWarnEnabled()) {
            LOGGER.warn("More then one Rest Facade matching for entityName={}, module={}, namespace={}. " + "Using first one available.", entityName, moduleName, namespace);
        }
        if (refs != null && refs.size() > 0) {
            ServiceReference<MdsRestFacade> ref = refs.iterator().next();
            restFacade = bundleContext.getService(ref);
        }
    } catch (InvalidSyntaxException e) {
        throw new IllegalArgumentException("Invalid Syntax for Rest Facade retrieval", e);
    }
    if (restFacade == null) {
        throw new RestNotSupportedException(entityName, moduleName, namespace);
    }
    return restFacade;
}
Also used : MdsRestFacade(org.motechproject.mds.rest.MdsRestFacade) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) RestNotSupportedException(org.motechproject.mds.exception.rest.RestNotSupportedException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

MdsRestFacade (org.motechproject.mds.rest.MdsRestFacade)6 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RestBadBodyFormatException (org.motechproject.mds.exception.rest.RestBadBodyFormatException)2 RestNotSupportedException (org.motechproject.mds.exception.rest.RestNotSupportedException)1 QueryParams (org.motechproject.mds.query.QueryParams)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1