/** * Read a RemoteInvocation from the given HTTP request. * <p>Delegates to {@link #readRemoteInvocation(HttpExchange, InputStream)} * with the {@link HttpExchange#getRequestBody()} request's input stream}. * @param exchange current HTTP request/response * @return the RemoteInvocation object * @throws java.io.IOException in case of I/O failure * @throws ClassNotFoundException if thrown by deserialization */ protected RemoteInvocation readRemoteInvocation(HttpExchange exchange) throws IOException, ClassNotFoundException { return readRemoteInvocation(exchange, exchange.getRequestBody()); }
/** * Read a RemoteInvocation from the given HTTP request. * <p>Delegates to {@link #readRemoteInvocation(HttpExchange, InputStream)} * with the {@link HttpExchange#getRequestBody()} request's input stream}. * @param exchange current HTTP request/response * @return the RemoteInvocation object * @throws java.io.IOException in case of I/O failure * @throws ClassNotFoundException if thrown by deserialization */ protected RemoteInvocation readRemoteInvocation(HttpExchange exchange) throws IOException, ClassNotFoundException { return readRemoteInvocation(exchange, exchange.getRequestBody()); }
private void handleAppsPost(HttpExchange httpExchange) throws IOException { EurekaHttpResponse<?> httpResponse; String path = httpExchange.getRequestURI().getPath(); if (path.matches("/v2/apps/([^/]+)(/)?")) { InstanceInfo instance = decoder.decode(httpExchange.getRequestBody(), InstanceInfo.class); httpResponse = requestHandler.register(instance); } else { httpExchange.sendResponseHeaders(HttpServletResponse.SC_NOT_FOUND, 0); return; } mapResponse(httpExchange, httpResponse); }
@Override protected void handleImpl(HttpExchange exchange) throws IOException { exchange.sendResponseHeaders(200, 0); ByteStreams.copy(exchange.getRequestBody(), exchange.getResponseBody()); exchange.close(); } }
/** * Processes the incoming Hessian request and creates a Hessian response. */ @Override public void handle(HttpExchange exchange) throws IOException { if (!"POST".equals(exchange.getRequestMethod())) { exchange.getResponseHeaders().set("Allow", "POST"); exchange.sendResponseHeaders(405, -1); return; } ByteArrayOutputStream output = new ByteArrayOutputStream(1024); try { invoke(exchange.getRequestBody(), output); } catch (Throwable ex) { exchange.sendResponseHeaders(500, -1); logger.error("Hessian skeleton invocation failed", ex); return; } exchange.getResponseHeaders().set("Content-Type", CONTENT_TYPE_HESSIAN); exchange.sendResponseHeaders(200, output.size()); FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody()); }
String text = IOUtils.slurpReader(IOUtils.encodedInputStreamReader(httpExchange.getRequestBody(), encoding)); String inputSerializerName = props.getProperty("inputSerializer", ProtobufAnnotationSerializer.class.getName()); AnnotationSerializer serializer = MetaClass.create(inputSerializerName).createInstance(); Pair<Annotation, InputStream> pair = serializer.read(httpExchange.getRequestBody()); return pair.first; default:
/** * Processes the incoming Hessian request and creates a Hessian response. */ @Override public void handle(HttpExchange exchange) throws IOException { if (!"POST".equals(exchange.getRequestMethod())) { exchange.getResponseHeaders().set("Allow", "POST"); exchange.sendResponseHeaders(405, -1); return; } ByteArrayOutputStream output = new ByteArrayOutputStream(1024); try { invoke(exchange.getRequestBody(), output); } catch (Throwable ex) { exchange.sendResponseHeaders(500, -1); logger.error("Hessian skeleton invocation failed", ex); return; } exchange.getResponseHeaders().set("Content-Type", CONTENT_TYPE_HESSIAN); exchange.sendResponseHeaders(200, output.size()); FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody()); }
} else if (httpExchange.getRequestMethod().equals("HEAD")) { httpExchange.getRequestBody().close(); httpExchange.getResponseHeaders().add("Transfer-encoding", "chunked"); httpExchange.sendResponseHeaders(200, -1);
@Override public void handle( HttpExchange httpExchange ) throws IOException { Headers h = httpExchange.getResponseHeaders(); h.add( "Content-Type", "application/octet-stream" ); httpExchange.sendResponseHeaders( 200, 0 ); InputStream is = httpExchange.getRequestBody(); OutputStream os = httpExchange.getResponseBody(); int inputChar = -1; while ( ( inputChar = is.read() ) >= 0 ) { os.write( inputChar ); } is.close(); os.flush(); os.close(); httpExchange.close(); } } );
requestUri, getHeaders(exchange), exchange.getRequestBody() );
case "PUT": String requestBody = decodeContent(exchange.getRequestHeaders(), exchange.getRequestBody()); response = replace(projectIdFromUri(path), jsonFactory.fromString(requestBody, Project.class));
@Override public void handle(HttpExchange httpExchange) throws IOException { Headers requestHeaders = httpExchange.getRequestHeaders(); String uploadTypeStr = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.UPLOAD_TYPE); FileUploadType uploadType = FileUploadType.valueOf(uploadTypeStr); String downloadUri = null; if (uploadType == FileUploadType.JSON) { InputStream bodyStream = httpExchange.getRequestBody(); downloadUri = JsonUtils.stringToJsonNode(IOUtils.toString(bodyStream, "UTF-8")) .get(CommonConstants.Segment.Offline.DOWNLOAD_URL).asText(); } else if (uploadType == FileUploadType.URI) { downloadUri = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.DOWNLOAD_URI); String crypter = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.CRYPTER); Assert.assertEquals(crypter, TEST_CRYPTER); } else { Assert.fail(); } Assert.assertEquals(downloadUri, TEST_URI); sendResponse(httpExchange, HttpStatus.SC_OK, "OK"); }
exchange.getRequestMethod(), getSecurityContext(exchange.getPrincipal(), isSecure), new MapPropertiesDelegate()); requestContext.setEntityStream(exchange.getRequestBody()); requestContext.getHeaders().putAll(exchange.getRequestHeaders()); requestContext.setWriter(responseWriter);
@Override public InputStream getInputStream() { return exchange.getRequestBody(); }
InputStream is = null; try { is = getHttpExchange().getRequestBody(); bodyBytes = IO.readBytes(is); } finally {
@Override public void handle(HttpExchange exchange) throws IOException { CountingInputStream input = new CountingInputStream(exchange.getRequestBody()); CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody()); exchange.setStreams(input, output); Stopwatch stopwatch = latency.start(); try { handleImpl(exchange); } finally { stopwatch.stop(); bytesReceived.increment(input.getCount()); bytesSent.increment(output.getCount()); } }
private Response handlePost(HttpExchange exchange, String path) throws IOException { String requestBody = decodeContent(exchange.getRequestHeaders(), exchange.getRequestBody()); if (!path.contains(":")) { return create(jsonFactory.fromString(requestBody, Project.class)); } else { switch (path.split(":", 2)[1]) { case "undelete": return undelete(projectIdFromUri(path)); case "getIamPolicy": return getPolicy(projectIdFromUri(path)); case "setIamPolicy": return replacePolicy( projectIdFromUri(path), jsonFactory.fromString(requestBody, SetIamPolicyRequest.class).getPolicy()); case "testIamPermissions": return testPermissions( projectIdFromUri(path), jsonFactory .fromString(requestBody, TestIamPermissionsRequest.class) .getPermissions()); default: return Error.BAD_REQUEST.response( "The server could not understand the following request URI: POST " + path); } } }
byte[] responseBytes; try { InputStream request = httpExchange.getRequestBody(); byte[] requestBytes = new byte[10000]; request.read(requestBytes);
private JSONAware executePostRequest(HttpExchange pExchange, ParsedUri pUri) throws MalformedObjectNameException, IOException { String encoding = null; Headers headers = pExchange.getRequestHeaders(); String cType = headers.getFirst("Content-Type"); if (cType != null) { Matcher matcher = contentTypePattern.matcher(cType); if (matcher.matches()) { encoding = matcher.group(1); } } InputStream is = pExchange.getRequestBody(); return requestHandler.handlePostRequest(pUri.toString(),is, encoding, pUri.getParameterMap()); }
public HttpMessage(HttpExchange httpExchange) { this.body = IOUtils.toByteArray(httpExchange.getRequestBody()); ImmutableMultimap.Builder<String, String> headersBuilder = ImmutableMultimap.builder(); Set<String> headerNames = httpExchange.getRequestHeaders().keySet(); headerNames.stream() .forEach(headerName -> headersBuilder.putAll(headerName, httpExchange.getRequestHeaders().get(headerName))); this.headers = headersBuilder.build(); uri = httpExchange.getRequestURI().getPath(); queryParams = queryToMap(httpExchange.getRequestURI().getQuery()); }