use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.
the class StateHandlerTest method requestAsString.
private String requestAsString(String requestUri) throws Exception {
final BufferedContentChannel content = new BufferedContentChannel();
Response response = driver.dispatchRequest(requestUri, new ResponseHandler() {
@Override
public ContentChannel handleResponse(Response response) {
return content;
}
}).get(60, TimeUnit.SECONDS);
assertNotNull(response);
assertEquals(Response.Status.OK, response.getStatus());
StringBuilder str = new StringBuilder();
Reader in = new InputStreamReader(content.toStream(), StandardCharsets.UTF_8);
for (int c; (c = in.read()) != -1; ) {
str.append((char) c);
}
return str.toString();
}
use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.
the class ProxyRequestHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
try (final ResourceReference requestReference = request.refer()) {
ContentChannel contentChannel;
final ResponseHandler proxyResponseHandler = new ProxyResponseHandler(request, new NullContentResponseHandler(responseHandler));
try {
contentChannel = delegate.handleRequest(request, proxyResponseHandler);
Objects.requireNonNull(contentChannel, "contentChannel");
} catch (Throwable t) {
try {
proxyResponseHandler.handleResponse(new Response(Response.Status.INTERNAL_SERVER_ERROR, t)).close(IGNORED_COMPLETION);
} catch (Throwable ignored) {
// empty
}
throw t;
}
return new ProxyContentChannel(request, contentChannel);
}
}
use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.
the class ServerProviderConformanceTest method testRequestExceptionAfterResponseWriteWithAsyncHandleResponse.
private <T extends ServerProvider, U, V> void testRequestExceptionAfterResponseWriteWithAsyncHandleResponse(final Adapter<T, U, V> adapter, final Module... config) throws Throwable {
runTest(adapter, Modules.combine(config), RequestType.WITHOUT_CONTENT, new TestRequestHandler() {
@Override
public ContentChannel handle(final Request request, final ResponseHandler handler) {
callInOtherThread(new Callable<Void>() {
@Override
public Void call() throws Exception {
final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK));
writeResponse(out);
closeResponse(out);
return null;
}
});
responseWritten.await();
throw new ConformanceException();
}
});
}
use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.
the class JDiscFilterForServletTest method bindings.
private Module bindings(BindingRepository<RequestFilter> requestFilters, BindingRepository<ResponseFilter> responseFilters) {
return Modules.combine(new AbstractModule() {
@Override
protected void configure() {
bind(FilterBindings.class).toInstance(new FilterBindings(requestFilters, responseFilters));
bind(FilterInvoker.class).toInstance(new FilterInvoker() {
@Override
public HttpServletRequest invokeRequestFilterChain(RequestFilter requestFilter, URI uri, HttpServletRequest httpRequest, ResponseHandler responseHandler) {
TestRequestFilter filter = (TestRequestFilter) requestFilter;
filter.runAsSecurityFilter(httpRequest, responseHandler);
return httpRequest;
}
@Override
public void invokeResponseFilterChain(ResponseFilter responseFilter, URI uri, HttpServletRequest request, HttpServletResponse response) {
TestResponseFilter filter = (TestResponseFilter) responseFilter;
filter.runAsSecurityFilter(request, response);
}
});
}
}, guiceModule());
}
use of com.yahoo.jdisc.handler.ResponseHandler in project vespa by vespa-engine.
the class MbusClient method handleReply.
@Override
public void handleReply(final Reply reply) {
reply.getTrace().trace(6, "Reply received by MbusClient.");
final ResponseHandler handler = (ResponseHandler) reply.getContext();
// restore user context
reply.popHandler();
try {
handler.handleResponse(new MbusResponse(StatusCodes.fromMbusReply(reply), reply)).close(IgnoredCompletionHandler.INSTANCE);
} catch (final Exception e) {
log.log(LogLevel.WARNING, "Ignoring exception thrown by ResponseHandler.", e);
}
}
Aggregations