@Override public Buffer getBody() { return decoratedContext.getBody(); }
private void doRegisterDeviceJson(final RoutingContext ctx) { try { JsonObject payload = null; if (ctx.getBody().length() > 0) { payload = ctx.getBodyAsJson(); } registerDevice(ctx, payload); } catch (final DecodeException e) { HttpUtils.badRequest(ctx, "body does not contain a valid JSON object"); } }
@Override public Buffer getBody() { return inner.getBody(); }
@Override public ServletInputStream getInputStream() { if (inputStream == null) { inputStream = new BufferInputStream(context.getBody().getByteBuf()); } return inputStream; }
public VertxServerRequestToHttpServletRequest(RoutingContext context) { this.context = context; this.vertxRequest = context.request(); this.socketAddress = this.vertxRequest.remoteAddress(); super.setBodyBuffer(context.getBody()); }
private void handleSend(RoutingContext rc, SockJSSession session) { Buffer body = rc.getBody(); if (body != null) { handleSendMessage(rc, session, body); } else if (rc.request().isEnded()) { log.error("Request ended before SockJS handler could read the body. Do you have an asynchronous request " + "handler before the SockJS handler? If so, add a BodyHandler before the SockJS handler " + "(see the docs)."); rc.fail(500); } else { rc.request().bodyHandler(buff -> handleSendMessage(rc, session, buff)); } }
@Test public void testHEADWithBody() throws Exception { router.route().handler(rc -> { assertNotNull(rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.HEAD, "/", 200, "OK"); }
@Test public void testGETWithBody() throws Exception { router.route().handler(rc -> { assertNotNull(rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.GET, "/", 200, "OK"); }
@Override public HttpServerRequest handler(Handler<Buffer> handler) { handler.handle(context.getBody()); return this; }
@Test public void testBodyBuffer() throws Exception { Buffer buff = TestUtils.randomBuffer(1000); router.route().handler(rc -> { assertEquals(buff, rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 200, "OK", null); }
/** * @return Get the entire HTTP request body as a . The context must have first been routed to a {@link io.vertx.rxjava.ext.web.handler.BodyHandler} for this to be populated. */ public io.vertx.rxjava.core.buffer.Buffer getBody() { io.vertx.rxjava.core.buffer.Buffer ret = io.vertx.rxjava.core.buffer.Buffer.newInstance(delegate.getBody()); return ret; }
private void testFileUpload(String uploadsDir, int size) throws Exception { String name = "somename"; String fileName = "somefile.dat"; String contentType = "application/octet-stream"; Buffer fileData = TestUtils.randomBuffer(size); router.route().handler(rc -> { Set<FileUpload> fileUploads = rc.fileUploads(); assertNotNull(fileUploads); assertEquals(1, fileUploads.size()); FileUpload upload = fileUploads.iterator().next(); assertEquals(name, upload.name()); assertEquals(fileName, upload.fileName()); assertEquals(contentType, upload.contentType()); assertEquals("binary", upload.contentTransferEncoding()); assertEquals(fileData.length(), upload.size()); String uploadedFileName = upload.uploadedFileName(); assertTrue(uploadedFileName.startsWith(uploadsDir + File.separator)); Buffer uploaded = vertx.fileSystem().readFileBlocking(uploadedFileName); assertEquals(fileData, uploaded); // the data is upload as HTML form, so the body should be empty Buffer rawBody = rc.getBody(); assertEquals(0, rawBody.length()); rc.response().end(); }); sendFileUploadRequest(fileData, 200, "OK"); }
.setUploadsDirectory(uploadsDirectory)); router.route().handler(ctx -> { assertEquals(0, ctx.getBody().length()); assertEquals(1, ctx.fileUploads().size()); ctx.response().end();
@Override public ServletInputStream getInputStream() throws IOException { if (inputStream == null) { inputStream = new BufferInputStream(context.getBody().getByteBuf()); } return inputStream; }
public VertxServerRequestToHttpServletRequest(RoutingContext context) { this.context = context; this.vertxRequest = context.request(); this.socketAddress = this.vertxRequest.remoteAddress(); super.setBodyBuffer(context.getBody()); }
private Object unmarshalRequestBody(RoutingContext event) throws java.io.IOException { Object result; byte[] body = event.getBody().getBytes(); List<String> contentTypeHeaders = event.request().headers().getAll(CONTENT_TYPE); result = marshaller.unmarshal(endpointComponent.getRequestBodyType(), new Message(body, contentTypeHeaders)); return result; }
@Test public void testHEADWithBody() throws Exception { router.route().handler(rc -> { assertNotNull(rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.HEAD, "/", 200, "OK"); }
@Test public void testGETWithBody() throws Exception { router.route().handler(rc -> { assertNotNull(rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.GET, "/", 200, "OK"); }
@Test public void testBodyBuffer() throws Exception { Buffer buff = TestUtils.randomBuffer(1000); router.route().handler(rc -> { assertEquals(buff, rc.getBody()); rc.response().end(); }); testRequest(HttpMethod.POST, "/", req -> { req.setChunked(true); req.write(buff); }, 200, "OK", null); }
private Request<byte[]> buildRequest(RoutingContext routingContext) { HttpServerRequest vertxRequest = routingContext.request(); return new Request<>( vertxRequest.method().name(), vertxRequest.uri(), VertxTypeConverter.toGuavaMultimap(vertxRequest.params()), VertxTypeConverter.toGuavaMultimap(vertxRequest.headers()), routingContext.getBody().getBytes(), vertxRequest.remoteAddress().host(), vertxRequest.version().name()); } }