@Override public T get() { return ResteasyContext.getContextData(instanceClass); } }
@SuppressWarnings({"rawtypes", "unchecked"}) public static byte[] toByteArray(Object token, ResteasyProviderFactory factory) throws IOException { MessageBodyWriter writer = factory.getMessageBodyWriter(token.getClass(), null, null, MediaType.APPLICATION_JSON_TYPE); if (writer == null) throw new NullPointerException(Messages.MESSAGES.couldNotFindMessageBodyWriterForJSON()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Providers old = ResteasyContext.getContextData(Providers.class); ResteasyContext.pushContext(Providers.class, factory); try { writer.writeTo(token, token.getClass(), null, null, MediaType.APPLICATION_JSON_TYPE, new MultivaluedHashMap<String, Object>(), baos); return baos.toByteArray(); } finally { ResteasyContext.popContextData(Providers.class); if (old != null) ResteasyContext.pushContext(Providers.class, old); } }
public T handle(ResteasyRequestWrapper requestWrapper, HttpServletResponse httpServletResponse) throws Exception { T result = null; HttpResponse response = new HttpServletResponseWrapper(httpServletResponse, factory); HttpServletRequest servletRequest = requestWrapper.getHttpServletRequest(); try { ResteasyContext.pushContext(HttpServletRequest.class, servletRequest); ResteasyContext.pushContext(HttpServletResponse.class, httpServletResponse); ResteasyContext.pushContext(SecurityContext.class, new ServletSecurityContext(servletRequest)); result = handle(requestWrapper, response); } finally { ResteasyContext.clearContextData(); } return result; }
private void popProvidersContext(Providers current) { ResteasyContext.popContextData(Providers.class); if (current != null) ResteasyContext.pushContext(Providers.class, current); }
private Providers pushProvidersContext() { Providers current = ResteasyContext.getContextData(Providers.class); ResteasyContext.pushContext(Providers.class, configuration); return current; }
public SseEventOutputImpl(final MessageBodyWriter<OutboundSseEvent> writer) { this.writer = writer; contextDataMap = ResteasyContext.getContextDataMap(); request = ResteasyContext.getContextData(org.jboss.resteasy.spi.HttpRequest.class); asyncContext = request.getAsyncContext(); if (!asyncContext.isSuspended()) { try { asyncContext.suspend(); } catch (IllegalStateException ex) { LogMessages.LOGGER.failedToSetRequestAsync(); } } response = ResteasyContext.getContextData(HttpResponse.class); }
public void clearContextData() { Cleanables cleanables = ResteasyContext.getContextData(Cleanables.class); if (cleanables != null) { for (Iterator<Cleanable> it = cleanables.getCleanables().iterator(); it.hasNext(); ) { try { it.next().clean(); } catch(Exception e) { // Empty } } } ResteasyContext.clearContextData(); // just in case there were internalDispatches that need to be cleaned up MessageBodyParameterInjector.clearBodies(); }
@Override public void setSecurityContext(SecurityContext context) { ResteasyContext.pushContext(SecurityContext.class, context); }
public static Map<Class<?>, Object> addContextDataLevel() { if (getContextDataLevelCount() == maxForwards) { throw new BadRequestException( Messages.MESSAGES.excededMaximumForwards(getContextData(UriInfo.class).getPath())); } Map<Class<?>, Object> map = new HashMap<Class<?>, Object>(); contextualData.push(map); return map; }
@Override public Map<Class<?>, Object> capture() { return ResteasyContext.getContextDataMap(); }
Map contextDataMap = ResteasyContext.getContextDataMap(); contextDataMap.putAll(dispatcher.getDefaultContextObjects()); Application app = ResteasyDeploymentImpl.createApplication(application.trim(), dispatcher, providerFactory); ResteasyContext.removeContextDataLevel();
private CompletionStage<Object> unwrapIfRequired(HttpRequest request, Object contextData, boolean unwrapAsync) { if(unwrapAsync && rawType != CompletionStage.class && contextData instanceof CompletionStage) { // FIXME: do not unwrap if we have no request? if(request != null ) { boolean resolved = ((CompletionStage<Object>) contextData).toCompletableFuture().isDone(); if(!resolved) { // make request async if(!request.getAsyncContext().isSuspended()) request.getAsyncContext().suspend(); Map<Class<?>, Object> contextDataMap = ResteasyContext.getContextDataMap(); // Don't forget to restore the context return ((CompletionStage<Object>) contextData).thenApply(value -> { ResteasyContext.pushContextDataMap(contextDataMap); return value; }); } } return (CompletionStage<Object>) contextData; } return CompletableFuture.completedFuture(contextData); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { Method method = ((PostMatchContainerRequestContext) requestContext).getResourceMethod().getMethod(); Stream stream = method.getAnnotation(Stream.class); Stream.MODE mode = stream != null ? stream.value() : null; Class<?> clazz = method.getReturnType(); if ((mode == Stream.MODE.GENERAL && ResteasyProviderFactory.getInstance().getAsyncStreamProvider(clazz) != null) || requestContext instanceof PostMatchContainerRequestContext && ((PostMatchContainerRequestContext) requestContext).getResourceMethod().isSse()) { SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider()); ResteasyContext.getContextDataMap().put(SseEventSink.class, sink); ResteasyContext.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() { @Override public void invoke() { sink.flushResponseToClient(); } }); } }
public void clearContextData() { Cleanables cleanables = ResteasyContext.getContextData(Cleanables.class); if (cleanables != null) { for (Iterator<Cleanable> it = cleanables.getCleanables().iterator(); it.hasNext(); ) { try { it.next().clean(); } catch(Exception e) { // Empty } } } ResteasyContext.clearContextData(); // just in case there were internalDispatches that need to be cleaned up MessageBodyParameterInjector.clearBodies(); }
public ParamConverter getParamConverter(Class clazz, Type genericType, Annotation[] annotations) { try { ResteasyContext.pushContext(ResteasyProviderFactory.class, this); // For MultiValuedParamConverterProvider for (SortedKey<ParamConverterProvider> provider : getSortedParamConverterProviders()) { ParamConverter converter = provider.getObj().getConverter(clazz, genericType, annotations); if (converter != null) return converter; } return null; } finally { ResteasyContext.popContextData(ResteasyProviderFactory.class); } }
protected CompletionStage<Object> invokeOnTargetDryRun(HttpRequest request, HttpResponse response, Object target) { ResteasyContext.pushContext(ResourceInfo.class, resourceInfo); // we don't pop so writer interceptors can get at this CompletionStage<Object> rtn = null; try { rtn = internalInvokeOnTarget(request, response, target); } catch (RuntimeException ex) { throw new ProcessingException(ex); } return rtn; }
protected AbstractAsynchronousResponse(final SynchronousDispatcher dispatcher,final HttpRequest request,final HttpResponse response) { this.dispatcher = dispatcher; this.request = request; this.response = response; contextDataMap = ResteasyContext.getContextDataMap(); }
Map contextDataMap = ResteasyContext.getContextDataMap(); contextDataMap.putAll(dispatcher.getDefaultContextObjects()); ResteasyContext.removeContextDataLevel();
private CompletionStage<Object> unwrapIfRequired(HttpRequest request, Object contextData, boolean unwrapAsync) { if(unwrapAsync && rawType != CompletionStage.class && contextData instanceof CompletionStage) { // FIXME: do not unwrap if we have no request? if(request != null ) { boolean resolved = ((CompletionStage<Object>) contextData).toCompletableFuture().isDone(); if(!resolved) { // make request async if(!request.getAsyncContext().isSuspended()) request.getAsyncContext().suspend(); Map<Class<?>, Object> contextDataMap = ResteasyContext.getContextDataMap(); // Don't forget to restore the context return ((CompletionStage<Object>) contextData).thenApply(value -> { ResteasyContext.pushContextDataMap(contextDataMap); return value; }); } } return (CompletionStage<Object>) contextData; } return CompletableFuture.completedFuture(contextData); }
@Override public SecurityContext getSecurityContext() { return ResteasyContext.getContextData(SecurityContext.class); }