use of org.jboss.resteasy.spi.Dispatcher in project resteasy by resteasy.
the class ContainerResponseContextImpl method writeException.
private void writeException(Throwable t) {
/*
* Here we cannot call AsyncResponse.resume(t) because that would invoke the response filters
* and we should not invoke them because we're already in them.
*/
HttpResponse httpResponse = (HttpResponse) contextDataMap.get(HttpResponse.class);
SynchronousDispatcher dispatcher = (SynchronousDispatcher) contextDataMap.get(Dispatcher.class);
ResteasyAsynchronousResponse asyncResponse = request.getAsyncContext().getAsyncResponse();
RESTEasyTracingLogger tracingLogger = RESTEasyTracingLogger.getInstance(request);
tracingLogger.flush(httpResponse.getOutputHeaders());
dispatcher.unhandledAsynchronousException(httpResponse, t);
onComplete.accept(t);
asyncResponse.complete();
asyncResponse.completionCallbacks(t);
}
use of org.jboss.resteasy.spi.Dispatcher in project scm-manager by scm-manager.
the class InvalidFormatExceptionMapperTest method shouldMapInvalidFormatExceptionDueToInvalidEnum.
@Test
void shouldMapInvalidFormatExceptionDueToInvalidEnum() throws URISyntaxException, UnsupportedEncodingException {
Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
dispatcher.getRegistry().addSingletonResource(new SimpleResource());
dispatcher.getProviderFactory().registerProvider(InvalidFormatExceptionMapper.class);
MockHttpRequest request = MockHttpRequest.post("/").contentType("application/json").content("{\"e\": \"NONE\"}".getBytes());
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(400);
assertThat(response.getContentAsString()).contains("2qRyyaVcJ1");
}
use of org.jboss.resteasy.spi.Dispatcher in project resteasy by resteasy.
the class SseEventSinkInterceptor method filter.
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
ResourceMethodInvoker rmi = ((PostMatchContainerRequestContext) requestContext).getResourceMethod();
if (rmi.isAsyncStreamProvider() || rmi.isSse()) {
Dispatcher dispatcher = ResteasyContext.getContextData(Dispatcher.class);
ResteasyProviderFactory providerFactory = dispatcher != null ? dispatcher.getProviderFactory() : ResteasyProviderFactory.getInstance();
SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider(providerFactory), providerFactory);
ResteasyContext.getContextDataMap().put(SseEventSink.class, sink);
ResteasyContext.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() {
@Override
public void invoke() {
sink.flushResponseToClient();
}
});
}
}
use of org.jboss.resteasy.spi.Dispatcher in project resteasy by resteasy.
the class ServletContainerDispatcher method init.
@SuppressWarnings(value = "unchecked")
public void init(ServletContext servletContext, ConfigurationBootstrap bootstrap, HttpRequestFactory requestFactory, HttpResponseFactory responseFactory) throws ServletException {
this.requestFactory = requestFactory;
this.responseFactory = responseFactory;
ResteasyDeployment ctxDeployment = (ResteasyDeployment) servletContext.getAttribute(ResteasyDeployment.class.getName());
ResteasyProviderFactory globalFactory = (ResteasyProviderFactory) servletContext.getAttribute(ResteasyProviderFactory.class.getName());
if (globalFactory == null && ctxDeployment != null) {
globalFactory = ctxDeployment.getProviderFactory();
}
Dispatcher globalDispatcher = (Dispatcher) servletContext.getAttribute(Dispatcher.class.getName());
if (globalDispatcher == null && ctxDeployment != null) {
globalDispatcher = ctxDeployment.getDispatcher();
}
String application = bootstrap.getInitParameter("jakarta.ws.rs.Application");
String useGlobalStr = bootstrap.getInitParameter("resteasy.servlet.context.deployment");
boolean useGlobal = globalFactory != null;
if (useGlobalStr != null)
useGlobal = Boolean.parseBoolean(useGlobalStr);
// in the servlet context
if (useGlobal) {
providerFactory = globalFactory;
dispatcher = globalDispatcher;
if ((providerFactory != null && dispatcher == null) || (providerFactory == null && dispatcher != null)) {
throw new ServletException(Messages.MESSAGES.unknownStateListener());
}
// We haven't been initialized by an external entity so bootstrap ourselves
if (providerFactory == null) {
deployment = bootstrap.createDeployment();
deployment.start();
servletContext.setAttribute(ResteasyProviderFactory.class.getName(), deployment.getProviderFactory());
servletContext.setAttribute(Dispatcher.class.getName(), deployment.getDispatcher());
servletContext.setAttribute(Registry.class.getName(), deployment.getRegistry());
dispatcher = deployment.getDispatcher();
providerFactory = deployment.getProviderFactory();
} else {
// ResteasyBootstrap inited us. Check to see if the servlet defines an Application class
if (application != null) {
try {
Map contextDataMap = ResteasyContext.getContextDataMap();
contextDataMap.putAll(dispatcher.getDefaultContextObjects());
Application app = ResteasyDeploymentImpl.createApplication(application.trim(), dispatcher, providerFactory);
// push context data so we can inject it
processApplication(app);
servletMappingPrefix = bootstrap.getParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX);
if (servletMappingPrefix == null)
servletMappingPrefix = "";
servletMappingPrefix = servletMappingPrefix.trim();
} finally {
ResteasyContext.removeContextDataLevel();
}
} else {
servletMappingPrefix = bootstrap.getParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX);
if (servletMappingPrefix == null)
servletMappingPrefix = "";
servletMappingPrefix = servletMappingPrefix.trim();
}
}
} else {
servletMappingPrefix = bootstrap.getParameter(ResteasyContextParameters.RESTEASY_SERVLET_MAPPING_PREFIX);
if (servletMappingPrefix == null)
servletMappingPrefix = "";
servletMappingPrefix = servletMappingPrefix.trim();
deployment = bootstrap.createDeployment();
deployment.start();
dispatcher = deployment.getDispatcher();
providerFactory = deployment.getProviderFactory();
}
}
use of org.jboss.resteasy.spi.Dispatcher in project resteasy by resteasy.
the class InternalDispatcher method getResponse.
public Response getResponse(MockHttpRequest request, Object entity) {
try {
Dispatcher dispatcher = ResteasyContext.getContextData(Dispatcher.class);
if (dispatcher == null) {
return null;
}
enhanceRequest(request);
return dispatcher.internalInvocation(request, new MockHttpResponse(), entity);
} finally {
}
}
Aggregations