public void setEntity( HttpEntity arg0 ) { responseBase.setEntity( arg0 ); }
public static void fileToHttpResponse(String fullPathFile, HttpResponse response, String contentType, boolean useFileChannels) { int status; final File file = new File(fullPathFile); if (!file.exists()) status = HttpStatus.SC_NOT_FOUND; else if (!file.canRead() || file.isDirectory()) status = HttpStatus.SC_FORBIDDEN; else { status = HttpStatus.SC_OK; NFileEntity entity = new NFileEntity(file, contentType, useFileChannels); response.setEntity(entity); } response.setStatusCode(status); }
public static void fileToHttpResponse(String fullPathFile, HttpResponse response, String contentType, boolean useFileChannels) { int status; final File file = new File(fullPathFile); if (!file.exists()) status = HttpStatus.SC_NOT_FOUND; else if (!file.canRead() || file.isDirectory()) status = HttpStatus.SC_FORBIDDEN; else { status = HttpStatus.SC_OK; NFileEntity entity = new NFileEntity(file, contentType, useFileChannels); response.setEntity(entity); } response.setStatusCode(status); }
public void receiveResponseEntity(final HttpResponse response) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } assertOpen(); HttpEntity entity = this.entitydeserializer.deserialize(this.inbuffer, response); response.setEntity(entity); }
public static void toHttpResponse(InputStream stream, HttpResponse response, String contentType, long streamLength) throws IOException { InputStreamEntity body = new InputStreamEntity(stream, streamLength); body.setContentType(contentType); response.setEntity(body); response.setStatusCode(HttpStatus.SC_OK); }
public static void toHttpResponse(InputStream stream, HttpResponse response, String contentType, long streamLength) throws IOException { InputStreamEntity body = new InputStreamEntity(stream, streamLength); body.setContentType(contentType); response.setEntity(body); response.setStatusCode(HttpStatus.SC_OK); }
public static void errorInternalServerError(HttpResponse response, String message, Throwable exception) { int status = HttpStatus.SC_INTERNAL_SERVER_ERROR; response.setStatusCode(status); StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw, true)); String logMessage = (message != null ? message + "\n" : "") + sw.toString(); logger.debug("Returning HTTP status " + status + ": " + logMessage); try { NStringEntity entity = new NStringEntity("<html><body><h1>Internal server error</h1><p>" + (message != null ? message : "") + "<pre>" + sw.toString() + "</pre></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public void process( final HttpResponse response, final HttpContext context ) throws HttpException, IOException { if ( hasEncoding( response, getContentEncoding() ) ) response.setEntity( wrapResponseEntity( response.getEntity() ) ); }
public static void errorFileNotFound(HttpResponse response, String uri) { int status = HttpStatus.SC_NOT_FOUND; response.setStatusCode(status); String message = "File " + uri + " not found"; logger.debug("Returning HTTP status " + status + ": " + message); try { NStringEntity entity = new NStringEntity("<html><body><h1>File not found</h1><p>" + message + "</p></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public static void errorFileNotFound(HttpResponse response, String uri) { int status = HttpStatus.SC_NOT_FOUND; response.setStatusCode(status); String message = "File " + uri + " not found"; logger.debug("Returning HTTP status " + status + ": " + message); try { NStringEntity entity = new NStringEntity("<html><body><h1>File not found</h1><p>" + message + "</p></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public static void errorMissingQueryParameter(HttpResponse response, String param) { int status = HttpStatus.SC_BAD_REQUEST; response.setStatusCode(status); String message = "Request must contain the parameter " + param; logger.debug("Returning HTTP status " + status + ": " + message); try { NStringEntity entity = new NStringEntity("<html><body><h1>Bad request</h1><p>" + message + ".</h1></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public static void errorMissingQueryParameter(HttpResponse response, String param) { int status = HttpStatus.SC_BAD_REQUEST; response.setStatusCode(status); String message = "Request must contain the parameter " + param; logger.debug("Returning HTTP status " + status + ": " + message); try { NStringEntity entity = new NStringEntity("<html><body><h1>Bad request</h1><p>" + message + ".</h1></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public static void errorWrongQueryParameterValue(HttpResponse response, String paramName, String illegalValue, String explanation) { int status = HttpStatus.SC_BAD_REQUEST; response.setStatusCode(status); String message = "The value '" + illegalValue + "' of parameter '" + paramName + "' is not valid" + (explanation != null ? ": " + explanation : ""); logger.debug("Returning HTTP status " + status + ": " + message); try { NStringEntity entity = new NStringEntity("<html><body><h1>Bad request</h1><p>" + message + ".</h1></body></html>", "UTF-8"); entity.setContentType("text/html; charset=UTF-8"); response.setEntity(entity); } catch (UnsupportedEncodingException e) { } }
public static void toHttpResponse(byte[] byteArray, HttpResponse response, String contentType) throws IOException { NByteArrayEntity body = new NByteArrayEntity(byteArray); body.setContentType(contentType); response.setEntity(body); response.setStatusCode(HttpStatus.SC_OK); }
public static void toHttpResponse(byte[] byteArray, HttpResponse response, String contentType) throws IOException { NByteArrayEntity body = new NByteArrayEntity(byteArray); body.setContentType(contentType); response.setEntity(body); response.setStatusCode(HttpStatus.SC_OK); }
@Override protected String sendAndReturn(final HttpUriRequest request) throws IOException { final HttpResponseFactory factory = new DefaultHttpResponseFactory(); final HttpResponse response = factory.newHttpResponse( new BasicStatusLine(HttpVersion.HTTP_1_1, this.status, null), null); final StringBuilder sb = new StringBuilder(); sb.append(String.format("%s = %s;", "METHOD", request.getMethod())); sb.append(String.format("%s = %s;", "URI", request.getURI())); final HttpEntity entity = ((HttpEntityEnclosingRequestBase) request).getEntity(); sb.append(String.format("%s = %s;", "BODY", EntityUtils.toString(entity))); response.setEntity(new StringEntity(sb.toString())); return parseResponse(response); }
protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); }
@Test public void testCloseQuietlyNullEntity() { HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpURLConnection.HTTP_OK, ""); response.setEntity(null); VoldemortIOUtils.closeQuietly(response); }
@Override public HttpResponse execute(HttpUriRequest request, HttpContext context) { requestExecuted = request; StatusLine statusLine = new BasicStatusLine( new ProtocolVersion("HTTP", 1, 1), mStatusCode, ""); HttpResponse response = new BasicHttpResponse(statusLine); response.setEntity(mResponseEntity); return response; }
@Override public HttpResponse execute(HttpUriRequest request, HttpContext context) { requestExecuted = request; StatusLine statusLine = new BasicStatusLine( new ProtocolVersion("HTTP", 1, 1), mStatusCode, ""); HttpResponse response = new BasicHttpResponse(statusLine); response.setEntity(mResponseEntity); return response; }