/** Returns the status code. Throws an exception if handleResponse is not called prior to calling this */ public int getStatus() { return response.getStatus(); }
@Override public void handleTimeout(Request request, ResponseHandler responseHandler) { Response.dispatchTimeout(responseHandler); }
private void setResponse(Response jdiscResponse) { synchronized (monitor) { if (responseCommitted) { log.log(Level.FINE, jdiscResponse.getError(), () -> "Response already committed, can't change response code. " + "From: " + servletResponse.getStatus() + ", To: " + jdiscResponse.getStatus()); //TODO: should throw an exception here, but this breaks unit tests. //The failures will now instead happen when writing buffers. servletOutputStreamWriter.close(); return; } setStatus_holdingLock(jdiscResponse, servletResponse); setHeaders_holdingLock(jdiscResponse, servletResponse); } }
/** * <p>Factory method for creating a ResponseDispatch with a {@link Response} that has the given status code, and * ByteBuffer content.</p> * * @param responseStatus The status code of the Response to dispatch. * @param content The ByteBuffer content of the Response, may be empty. * @return The created ResponseDispatch. */ public static ResponseDispatch newInstance(int responseStatus, ByteBuffer... content) { return newInstance(new Response(responseStatus), Arrays.asList(content)); }
/** * The response headers. * * @return a mutable, thread-unsafe view of the response headers */ public HeaderFields headers() { return parentResponse.headers(); }
/** * Sets the numeric HTTP status code this will return. */ public void setStatus(int status) { parentResponse.setStatus(status); }
private static Optional<String> getErrorMessage(Response jdiscResponse) { return Optional.ofNullable(jdiscResponse.getError()).flatMap( error -> Optional.ofNullable(error.getMessage())); }
/** * <p>Factory method for creating a ResponseDispatch with a {@link Response} that has the given status code, and * collection of ByteBuffer content. * Because this method uses the Iterable interface, you can create the ByteBuffers lazily, or * provide them as they become available.</p> * * @param responseStatus The status code of the Response to dispatch. * @param content The provider of the Response's ByteBuffer content. * @return The created ResponseDispatch. */ public static ResponseDispatch newInstance(int responseStatus, Iterable<ByteBuffer> content) { return newInstance(new Response(responseStatus), content); }
private static void setHeaders_holdingLock(Response jdiscResponse, HttpServletResponse servletResponse) { for (final Map.Entry<String, String> entry : jdiscResponse.headers().entries()) { servletResponse.addHeader(entry.getKey(), entry.getValue()); } if (servletResponse.getContentType() == null) { servletResponse.setContentType("text/plain;charset=utf-8"); } }
@Override public ContentChannel handle(Request request, ResponseHandler handler) { ContentChannel out = handler.handleResponse(new Response(Response.Status.OK)); out.close(EXCEPTION_COMPLETION_HANDLER); return null; } });
@Override protected com.yahoo.jdisc.Response newResponse() { com.yahoo.jdisc.Response response = new com.yahoo.jdisc.Response(com.yahoo.jdisc.Response.Status.OK); response.headers().add("Content-Type", Arrays.asList(new String[]{"application/json"})); return response; } }.connect(handler));
/** * The numeric HTTP status code, e.g. 200, 404 and so on. * * @return the numeric HTTP status code */ public int getStatus() { return parentResponse.getStatus(); }
private static void copyResponseHeaders(Response response, com.yahoo.jdisc.Response discResponse) { for (Map.Entry<String, List<String>> entry : discResponse.headers().entrySet()) { response.getHeaders().put(entry.getKey(), entry.getValue()); } }
protected void respondNoContent(final ResponseHandler handler) { final ContentChannel out = handler.handleResponse(new Response(Response.Status.OK)); closeResponse(out); }
@Override protected com.yahoo.jdisc.Response newResponse() { com.yahoo.jdisc.Response response = new com.yahoo.jdisc.Response(statusToReturn); response.headers().add("Content-Type", Arrays.asList(new String[]{"application/json"})); return response; } }.connect(handler));
@Override public ContentChannel handle(Request request, ResponseHandler handler) { ContentChannel out = handler.handleResponse(new Response(Response.Status.OK)); writeResponse(out); out.close(EXCEPTION_COMPLETION_HANDLER); return null; } });
private static void setStatus_holdingLock(Response jdiscResponse, HttpServletResponse servletResponse) { if (jdiscResponse instanceof HttpResponse) { setStatus(servletResponse, jdiscResponse.getStatus(), Optional.ofNullable(((HttpResponse) jdiscResponse).getMessage())); } else { setStatus(servletResponse, jdiscResponse.getStatus(), getErrorMessage(jdiscResponse)); } }