javax.ws.rs.container.ResourceContext Java Examples

The following examples show how to use javax.ws.rs.container.ResourceContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricAppBeanOptional.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/get-context-params")
public String  getContextParams(
        final @Context HttpHeaders httpheaders,
        final @Context Request request,
        final @Context UriInfo uriInfo,
        final @Context ResourceContext resourceContext,
        final @Context Providers providers,
        final @Context Application application,
        final @Context SecurityContext securityContext,
        final @Context Configuration configuration) throws Exception {
    
    return "This is a GET request with context parameters";
}
 
Example #2
Source File: SwaggerJsonBareService.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/swagger")
@ApiOperation(value = "The swagger definition in JSON", hidden = true)
public Response getListingJsonBare(
        @Context Application app,
        @Context ServletConfig sc,
        @Context HttpHeaders headers,
        @Context UriInfo uriInfo,
        @Context ResourceContext rc) {
    ApiListingResource apiListingResource = rc.getResource(ApiListingResource.class);
    return apiListingResource.getListingJson(app, sc, headers, uriInfo);
}
 
Example #3
Source File: TemplateModelProcessor.java    From ameba with MIT License 5 votes vote down vote up
/**
 * Create a {@code TemplateModelProcessor} instance.
 *
 * @param resourceContext         (injected) resource context.
 * @param extendedUriInfoProvider (injected) extended uri info provider.
 */
@Inject
TemplateModelProcessor(final ResourceContext resourceContext,
                       final Provider<ConfiguredValidator> validatorProvider,
                       final Provider<ExtendedUriInfo> extendedUriInfoProvider) {
    this.resourceContext = resourceContext;
    this.validatorProvider = validatorProvider;
    this.extendedUriInfoProvider = extendedUriInfoProvider;
}
 
Example #4
Source File: ThreadLocalContextManager.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static Object findThreadLocal(final Class<?> type) {
    if (Request.class.equals(type)) {
        return REQUEST;
    } else if (UriInfo.class.equals(type)) {
        return URI_INFO;
    } else if (HttpHeaders.class.equals(type)) {
        return HTTP_HEADERS;
    } else if (SecurityContext.class.equals(type)) {
        return SECURITY_CONTEXT;
    } else if (ContextResolver.class.equals(type)) {
        return CONTEXT_RESOLVER;
    } else if (Providers.class.equals(type)) {
        return PROVIDERS;
    } else if (ServletRequest.class.equals(type)) {
        return SERVLET_REQUEST;
    } else if (HttpServletRequest.class.equals(type)) {
        return HTTP_SERVLET_REQUEST;
    } else if (HttpServletResponse.class.equals(type)) {
        return HTTP_SERVLET_RESPONSE;
    } else if (ServletConfig.class.equals(type)) {
        return SERVLET_CONFIG;
    } else if (ServletContext.class.equals(type)) {
        return SERVLET_CONTEXT;
    } else if (ResourceInfo.class.equals(type)) {
        return RESOURCE_INFO;
    } else if (ResourceContext.class.equals(type)) {
        return RESOURCE_CONTEXT;
    } else if (Application.class.equals(type)) {
        return APPLICATION;
    } else if (Configuration.class.equals(type)) {
        return CONFIGURATION;
    }
    return null;
}
 
Example #5
Source File: TestClass5.java    From jaxrs-analyzer with Apache License 2.0 4 votes vote down vote up
public Object method() {
    ResourceContext rc = null;
    if ("".equals(""))
        return rc.getResource(AnotherSubResource.class);
    return rc.getResource(SubResource.class);
}
 
Example #6
Source File: TestClass1.java    From jaxrs-analyzer with Apache License 2.0 4 votes vote down vote up
public SubResource method() {
    ResourceContext rc = null;
    return rc.getResource(SubResource.class);
}
 
Example #7
Source File: TestClass3.java    From jaxrs-analyzer with Apache License 2.0 4 votes vote down vote up
public Object method() {
    ResourceContext rc = null;
    final Object resource = rc.getResource(SubResource.class);
    return resource;
}
 
Example #8
Source File: TestClass2.java    From jaxrs-analyzer with Apache License 2.0 4 votes vote down vote up
public Object method() {
    ResourceContext rc = null;
    return rc.getResource(SubResource.class);
}
 
Example #9
Source File: JerseyGuiceModule.java    From soabase with Apache License 2.0 4 votes vote down vote up
@Provides
@RequestScoped
public ResourceContext providesResourceContext()
{
    return filter.getResourceContext();
}
 
Example #10
Source File: JerseyGuicierModule.java    From dropwizard-guicier with Apache License 2.0 4 votes vote down vote up
@Provides
public ResourceContext providesResourceContext(ServiceLocator serviceLocator) {
  return serviceLocator.getService(ResourceContext.class);
}
 
Example #11
Source File: BookStore.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Path("/booksubresource/instance/context")
public Book2 getBookSubResourceInstanceRC(@Context ResourceContext rc) {
    return rc.initResource(book2Sub);
}
 
Example #12
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
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);
    }
 
Example #13
Source File: CxfRSService.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void contextCDIIntegration(final WebBeansContext wbc) {
    if (!enabled) {
        return;
    }

    final BeanManagerImpl beanManagerImpl = wbc.getBeanManagerImpl();
    if (!beanManagerImpl.getAdditionalQualifiers().contains(Context.class)) {
        beanManagerImpl.addAdditionalQualifier(Context.class);
    }
    if (!hasBean(beanManagerImpl, SecurityContext.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(SecurityContext.class, ThreadLocalContextManager.SECURITY_CONTEXT));
    }
    if (!hasBean(beanManagerImpl, UriInfo.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(UriInfo.class, ThreadLocalContextManager.URI_INFO));
    }
    if (!hasBean(beanManagerImpl, HttpServletResponse.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(HttpServletResponse.class, ThreadLocalContextManager.HTTP_SERVLET_RESPONSE));
    }
    if (!hasBean(beanManagerImpl, HttpHeaders.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(HttpHeaders.class, ThreadLocalContextManager.HTTP_HEADERS));
    }
    if (!hasBean(beanManagerImpl, Request.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(Request.class, ThreadLocalContextManager.REQUEST));
    }
    if (!hasBean(beanManagerImpl, ServletConfig.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ServletConfig.class, ThreadLocalContextManager.SERVLET_CONFIG));
    }
    if (!hasBean(beanManagerImpl, Providers.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(Providers.class, ThreadLocalContextManager.PROVIDERS));
    }
    if (!hasBean(beanManagerImpl, ContextResolver.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ContextResolver.class, ThreadLocalContextManager.CONTEXT_RESOLVER));
    }
    if (!hasBean(beanManagerImpl, ResourceInfo.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ResourceInfo.class, ThreadLocalContextManager.RESOURCE_INFO));
    }
    if (!hasBean(beanManagerImpl, ResourceContext.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ResourceContext.class, ThreadLocalContextManager.RESOURCE_CONTEXT));
    }
    if (!hasBean(beanManagerImpl, HttpServletRequest.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(HttpServletRequest.class, ThreadLocalContextManager.HTTP_SERVLET_REQUEST));
    }
    if (!hasBean(beanManagerImpl, ServletRequest.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ServletRequest.class, ThreadLocalContextManager.SERVLET_REQUEST));
    }
    if (!hasBean(beanManagerImpl, ServletContext.class)) {
        beanManagerImpl.addInternalBean(new ContextBean<>(ServletContext.class, ThreadLocalContextManager.SERVLET_CONTEXT));
    }
    beanManagerImpl.getInjectionResolver().clearCaches(); // hasBean() usage can have cached several things
}
 
Example #14
Source File: ThreadLocalResourceContext.java    From tomee with Apache License 2.0 4 votes vote down vote up
protected ThreadLocalResourceContext() {
    super(ResourceContext.class);
}