Search in sources :

Example 1 with ResourceInfoImpl

use of org.apache.cxf.jaxrs.impl.ResourceInfoImpl in project cxf by apache.

the class ServerProviderFactory method doApplyDynamicFeatures.

private void doApplyDynamicFeatures(ClassResourceInfo cri) {
    Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
    for (OperationResourceInfo ori : oris) {
        String nameBinding = DEFAULT_FILTER_NAME_BINDING + ori.getClassResourceInfo().getServiceClass().getName() + "." + ori.getMethodToInvoke().toString();
        for (DynamicFeature feature : dynamicFeatures) {
            FeatureContext featureContext = createServerFeatureContext();
            feature.configure(new ResourceInfoImpl(ori), featureContext);
            Configuration cfg = featureContext.getConfiguration();
            for (Object provider : cfg.getInstances()) {
                Map<Class<?>, Integer> contracts = cfg.getContracts(provider.getClass());
                if (contracts != null && !contracts.isEmpty()) {
                    Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider);
                    registerUserProvider(new FilterProviderInfo<Object>(provider.getClass(), providerCls, provider, getBus(), Collections.singleton(nameBinding), true, contracts));
                    ori.addNameBindings(Collections.singletonList(nameBinding));
                }
            }
        }
    }
    Collection<ClassResourceInfo> subs = cri.getSubResources();
    for (ClassResourceInfo sub : subs) {
        if (sub != cri) {
            doApplyDynamicFeatures(sub);
        }
    }
}
Also used : Configuration(javax.ws.rs.core.Configuration) ResourceInfoImpl(org.apache.cxf.jaxrs.impl.ResourceInfoImpl) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) DynamicFeature(javax.ws.rs.container.DynamicFeature) FeatureContext(javax.ws.rs.core.FeatureContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo)

Example 2 with ResourceInfoImpl

use of org.apache.cxf.jaxrs.impl.ResourceInfoImpl in project cxf by apache.

the class JAXRSUtils method createContextValue.

public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {
    Message contextMessage = getContextMessage(m);
    Object o = null;
    if (UriInfo.class.isAssignableFrom(clazz)) {
        o = createUriInfo(contextMessage);
    } else if (HttpHeaders.class.isAssignableFrom(clazz) || ProtocolHeaders.class.isAssignableFrom(clazz)) {
        o = createHttpHeaders(contextMessage, clazz);
    } else if (SecurityContext.class.isAssignableFrom(clazz)) {
        SecurityContext customContext = contextMessage.get(SecurityContext.class);
        o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
    } else if (MessageContext.class.isAssignableFrom(clazz)) {
        o = new MessageContextImpl(m);
    } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
        o = new ResourceInfoImpl(contextMessage);
    } else if (ResourceContext.class.isAssignableFrom(clazz)) {
        o = new ResourceContextImpl(contextMessage, contextMessage.getExchange().get(OperationResourceInfo.class));
    } else if (Request.class.isAssignableFrom(clazz)) {
        o = new RequestImpl(contextMessage);
    } else if (Providers.class.isAssignableFrom(clazz)) {
        o = new ProvidersImpl(contextMessage);
    } else if (ContextResolver.class.isAssignableFrom(clazz)) {
        o = createContextResolver(genericType, contextMessage);
    } else if (Configuration.class.isAssignableFrom(clazz)) {
        o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
    } else if (Application.class.isAssignableFrom(clazz)) {
        ProviderInfo<?> providerInfo = (ProviderInfo<?>) contextMessage.getExchange().getEndpoint().get(Application.class.getName());
        o = providerInfo == null ? null : providerInfo.getProvider();
    } else if (contextMessage != null) {
        ContextProvider<?> provider = ProviderFactory.getInstance(contextMessage).createContextProvider(clazz, contextMessage);
        if (provider != null) {
            o = provider.createContext(contextMessage);
        }
    }
    if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage)) {
        o = HttpUtils.createServletResourceValue(contextMessage, clazz);
    }
    return clazz.cast(o);
}
Also used : SecurityContextImpl(org.apache.cxf.jaxrs.impl.SecurityContextImpl) ResourceContext(javax.ws.rs.container.ResourceContext) Message(org.apache.cxf.message.Message) Configuration(javax.ws.rs.core.Configuration) ResourceInfoImpl(org.apache.cxf.jaxrs.impl.ResourceInfoImpl) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) ProvidersImpl(org.apache.cxf.jaxrs.impl.ProvidersImpl) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) SecurityContext(javax.ws.rs.core.SecurityContext) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) ResourceContextImpl(org.apache.cxf.jaxrs.impl.ResourceContextImpl) RequestImpl(org.apache.cxf.jaxrs.impl.RequestImpl) MessageContextImpl(org.apache.cxf.jaxrs.ext.MessageContextImpl)

Aggregations

Configuration (javax.ws.rs.core.Configuration)2 ResourceInfoImpl (org.apache.cxf.jaxrs.impl.ResourceInfoImpl)2 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)2 DynamicFeature (javax.ws.rs.container.DynamicFeature)1 ResourceContext (javax.ws.rs.container.ResourceContext)1 FeatureContext (javax.ws.rs.core.FeatureContext)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 Providers (javax.ws.rs.ext.Providers)1 ContextProvider (org.apache.cxf.jaxrs.ext.ContextProvider)1 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)1 MessageContextImpl (org.apache.cxf.jaxrs.ext.MessageContextImpl)1 ProvidersImpl (org.apache.cxf.jaxrs.impl.ProvidersImpl)1 RequestImpl (org.apache.cxf.jaxrs.impl.RequestImpl)1 ResourceContextImpl (org.apache.cxf.jaxrs.impl.ResourceContextImpl)1 SecurityContextImpl (org.apache.cxf.jaxrs.impl.SecurityContextImpl)1 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)1 ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)1 Message (org.apache.cxf.message.Message)1