public VertxHttpResponse(final HttpServerResponse response, final ResteasyProviderFactory providerFactory, final HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }
public boolean requestHasBody() { // https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/ // also see: // https://www.owasp.org/index.php/Test_HTTP_Methods_(OTG-CONFIG-006) return HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method) || HttpMethod.PATCH.equals(method) || HttpMethod.TRACE.equals(method); }
private R fetchBody(RoutingContext routingContext, HttpMethod method) { R requestBody; if (HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method) || HttpMethod.PATCH.equals(method)) { requestBody = getRequestBody(routingContext); } else { requestBody = makeNewRequest(); } return requestBody; }
/** * initialize default REST implementation for vxms * * @param vxmsShared the vxmsShared instance, containing the Vertx instance and other shared * objects per instance * @param router the Router instance * @param service the Vxms service object itself * @param routes the routes defined by the developer with the fluent API */ static void initRESTHandler( VxmsShared vxmsShared, Router router, Object service, VxmsRoutes routes) { if (VxmsRESTRoutes.class.isAssignableFrom(routes.getClass())) { VxmsRESTRoutes userRoutes = VxmsRESTRoutes.class.cast(routes); userRoutes .getDescriptors() .stream() .filter(desc -> desc.httpMethod.equals(HttpMethod.GET)) .forEach(descriptor -> initHttpGet(vxmsShared, router, descriptor)); } }
@Override public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) { String token = request.get(key); // generate CSRF token if (token == null) { token = UUID.randomUUID().toString(); request.put(key, token); } // ignore these methods if (HttpMethod.GET.equals(request.method()) || HttpMethod.HEAD.equals(request.method()) || HttpMethod.OPTIONS.equals(request.method())) { next.handle(null); return; } // expect multipart request.setExpectMultipart(true); // determine value String val = valueHandler.handle(request); // check if (!token.equals(val)) { next.handle(403); return; } // OK next.handle(null); }
public VertxHttpResponse(HttpServerResponse response, ResteasyProviderFactory providerFactory, HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }
private void cache(RestClientResponse restClientResponse) { if (HttpMethod.GET.equals(method) && requestCacheOptions != null && requestCacheOptions.getCachedStatusCodes().contains(restClientResponse.statusCode())) { log.debug("Caching entry with key {}", cacheKey); cancelOutstandingEvictionTimer(cacheKey); restClient.getRequestCache().put(cacheKey, restClientResponse); createEvictionTimer(cacheKey, requestCacheOptions.getExpiresAfterWriteMillis()); } }
/** * If we have a zip resource with a given path, * we will handle the request, otherwise not. * * @param req * @return true if request is handled, otherwise false */ public boolean handle(final HttpServerRequest req) { if ( req.method().equals(HttpMethod.GET) && req.uri().contains(ZIP_RESOURCE_FLAG) ) { // zip resource and path int seperationIndex = req.uri().lastIndexOf(ZIP_RESOURCE_FLAG) + ZIP_RESOURCE_FLAG.length() - 1; String zipUrl = req.uri().substring(0, seperationIndex); String insidePath = req.uri().substring(seperationIndex + 1); // perform the get of the zip performGETRequest(req, zipUrl, insidePath); return true; } else { return false; } }
private void handleResponse(RestClientResponse<T> restClientResponse) { if (HttpMethod.GET.equals(method) && requestCacheOptions != null) { final RestClientRequestSlice<T> restClientRequestSlice = getRestClientRequestSlice();
if (request.method().equals(HttpMethod.PUT) && propertyUrls.containsKey(request.uri())) {
String token = null; if (HttpMethod.OPTIONS.equals(request.method()) && request.getHeader("access-control-request-headers") != null) { for (String ctrlReq : request.getHeader("access-control-request-headers").split(",")) { if (ctrlReq.contains("authorization")) {
if (HttpMethod.GET.equals(method) && requestCacheOptions != null) { try { if (isEvicting(requestCacheOptions)) {
@Override public void handle(@NotNull final YokeRequest request, @NotNull final Handler<Object> next) { if (request.path().equals(loginURI)) { if (HttpMethod.GET.equals(request.method())) { if (loginTemplate != null) { if (HttpMethod.POST.equals(request.method())) { if (forceSSL && !request.isSSL()) { if (HttpMethod.GET.equals(request.method())) {
/** * Can be a PATCH or a POST request (with query parameter '_HttpMethod=PATCH'). * * @return */ private Handler<RoutingContext> handleUpdateRequest() { return handleAsync(routingContext -> { final String sObjectName = routingContext.request().getParam("sObjectName"); final String sObjectId = routingContext.request().getParam("sObjectId"); final JsonObject sObject = routingContext.getBodyAsJson(); // SFDC work-around for HTTP clients that don't support PATCH if (!HttpMethod.PATCH.equals(routingContext.request().method()) && !"PATCH".equals(routingContext.request().getParam("_HttpMethod"))) { routingContext.fail(HttpUtil.HTTP_BAD_METHOD); return; } LOGGER.info("Received update request for {} with ID: {}: {}", sObjectName, sObjectId, sObject); routingContext.response() .putHeader(CONTENT_TYPE, CONTENT_TYPE_JSON) .setStatusCode(HttpUtil.HTTP_NO_CONTENT) .end(); }); }
/** * Write a file into the response body * * @param request * @param file * @param props */ private void sendFile(final YokeRequest request, final String file, final FileProps props) { // write content type String contentType = MimeType.getMime(file); String charset = MimeType.getCharset(contentType); request.response().setContentType(contentType, charset); request.response().putHeader("Content-Length", Long.toString(props.size())); // head support if (HttpMethod.HEAD.equals(request.method())) { request.response().end(); } else { request.response().sendFile(file); } }
private void myStreamHandle(RoutingContext ctx) { if (HttpMethod.DELETE.equals(ctx.request().method())) { ctx.request().endHandler(x -> HttpResponse.responseText(ctx, 204).end()); return;
private void response(String msg, boolean xmlConversion, RoutingContext ctx) { ctx.request().resume(); if (ctx.request().method().equals(HttpMethod.GET)) { ctx.request().endHandler(x -> ctx.response().end("It works" + msg)); } else { ctx.response().setChunked(true); if (xmlConversion) { ctx.response().write("<test>"); } ctx.response().write(helloGreeting + " " + msg); ctx.request().handler(x -> { ctx.response().write(x); if (xmlConversion) { ctx.response().write("</test>"); } }); ctx.request().endHandler(x -> ctx.response().end()); } }
+ " for tenant " + tenant); tenantParameters = null; if (ctx.request().method().equals(HttpMethod.DELETE)) { ctx.response().setStatusCode(204); ctx.response().end();