if (currentRequest.getMethod() == HttpMethod.GET || currentRequest.getMethod() == HttpMethod.DELETE) { else if (currentRequest.getMethod() == HttpMethod.POST) { currentRequestPath = new QueryStringDecoder(currentRequest.getUri(), ENCODING).path(); currentDecoder = new HttpPostRequestDecoder(DATA_FACTORY, currentRequest, ENCODING); throw new IOException("Unsupported HTTP method: " + currentRequest.getMethod().name()); encoder.addParam("filename", name); currentRequest.setUri(encoder.toString());
/** * Sends a simple DELETE request to the given path. You only specify the $path part of * http://$host:$host/$path. * * @param path The $path to DELETE (http://$host:$host/$path) */ public void sendDeleteRequest(String path, FiniteDuration timeout) throws TimeoutException, InterruptedException { if (!path.startsWith("/")) { path = "/" + path; } HttpRequest getRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, path); getRequest.headers().set(HttpHeaders.Names.HOST, host); getRequest.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); sendRequest(getRequest, timeout); }
if (msg instanceof HttpRequest) { final HttpRequest httpRequest = (HttpRequest) msg; LOG.trace("Received request. URL:{} Method:{}", httpRequest.getUri(), httpRequest.getMethod()); if (httpRequest.getMethod().equals(HttpMethod.POST)) { if (HttpPostRequestDecoder.isMultipart(httpRequest)) { LOG.trace("Initializing multipart file upload."); ctx.channel().attr(UPLOADED_FILES).set(new FileUploads(currentUploadDir)); if (currentJsonPayload != null) { currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, currentJsonPayload.length); currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, RestConstants.REST_CONTENT_TYPE); ctx.fireChannelRead(currentHttpRequest); ctx.fireChannelRead(httpContent.replace(Unpooled.wrappedBuffer(currentJsonPayload))); } else { currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0); currentHttpRequest.headers().remove(HttpHeaders.Names.CONTENT_TYPE); ctx.fireChannelRead(currentHttpRequest); ctx.fireChannelRead(LastHttpContent.EMPTY_LAST_CONTENT);
private void respondNotFound(ChannelHandlerContext channelHandlerContext, HttpRequest request) { LOG.trace("Request could not be routed to any handler. Uri:{} Method:{}", request.getUri(), request.getMethod()); HandlerUtils.sendErrorResponse( channelHandlerContext, request, new ErrorResponseBody("Not found."), HttpResponseStatus.NOT_FOUND, responseHeaders); } }
@Override protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) { if (HttpHeaders.is100ContinueExpected(httpRequest)) { channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); return; } // Route HttpMethod method = httpRequest.getMethod(); QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri()); RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters()); if (routeResult == null) { respondNotFound(channelHandlerContext, httpRequest); return; } routed(channelHandlerContext, routeResult, httpRequest); }
@Override protected void respondAsLeader(ChannelHandlerContext ctx, Routed routed, T gateway) throws Exception { if (log.isTraceEnabled()) { log.trace("Received request " + routed.request().getUri() + '.');
public RoutedRequest(RouteResult<T> result, HttpRequest request) { this.result = checkNotNull(result); this.request = checkNotNull(request); this.requestAsReferenceCounted = Optional.ofNullable((request instanceof ReferenceCounted) ? (ReferenceCounted) request : null); this.queryStringDecoder = new QueryStringDecoder(request.uri()); }
if (msg instanceof HttpRequest) { final HttpRequest httpRequest = (HttpRequest) msg; LOG.trace("Received request. URL:{} Method:{}", httpRequest.getUri(), httpRequest.getMethod()); if (httpRequest.getMethod().equals(HttpMethod.POST)) { if (HttpPostRequestDecoder.isMultipart(httpRequest)) { LOG.trace("Initializing multipart file upload."); ctx.channel().attr(UPLOADED_FILES).set(new FileUploads(currentUploadDir)); if (currentJsonPayload != null) { currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, currentJsonPayload.length); currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, RestConstants.REST_CONTENT_TYPE); ctx.fireChannelRead(currentHttpRequest); ctx.fireChannelRead(httpContent.replace(Unpooled.wrappedBuffer(currentJsonPayload))); } else { currentHttpRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0); currentHttpRequest.headers().remove(HttpHeaders.Names.CONTENT_TYPE); ctx.fireChannelRead(currentHttpRequest); ctx.fireChannelRead(LastHttpContent.EMPTY_LAST_CONTENT);
private void respondNotFound(ChannelHandlerContext channelHandlerContext, HttpRequest request) { LOG.trace("Request could not be routed to any handler. Uri:{} Method:{}", request.getUri(), request.getMethod()); HandlerUtils.sendErrorResponse( channelHandlerContext, request, new ErrorResponseBody("Not found."), HttpResponseStatus.NOT_FOUND, responseHeaders); } }
@Override protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) { if (HttpHeaders.is100ContinueExpected(httpRequest)) { channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); return; } // Route HttpMethod method = httpRequest.getMethod(); QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri()); RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters()); if (routeResult == null) { respondNotFound(channelHandlerContext, httpRequest); return; } routed(channelHandlerContext, routeResult, httpRequest); }
public RoutedRequest(RouteResult<T> result, HttpRequest request) { this.result = checkNotNull(result); this.request = checkNotNull(request); this.requestAsReferenceCounted = Optional.ofNullable((request instanceof ReferenceCounted) ? (ReferenceCounted) request : null); this.queryStringDecoder = new QueryStringDecoder(request.uri()); }
if (currentRequest.getMethod() == HttpMethod.GET || currentRequest.getMethod() == HttpMethod.DELETE) { else if (currentRequest.getMethod() == HttpMethod.POST) { currentRequestPath = new QueryStringDecoder(currentRequest.getUri(), ENCODING).path(); currentDecoder = new HttpPostRequestDecoder(DATA_FACTORY, currentRequest, ENCODING); throw new IOException("Unsupported HTTP method: " + currentRequest.getMethod().name()); encoder.addParam("filename", name); currentRequest.setUri(encoder.toString());
/** * Sends a simple GET request to the given path. You only specify the $path part of * http://$host:$host/$path. * * @param path The $path to GET (http://$host:$host/$path) */ public void sendGetRequest(String path, FiniteDuration timeout) throws TimeoutException, InterruptedException { if (!path.startsWith("/")) { path = "/" + path; } HttpRequest getRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path); getRequest.headers().set(HttpHeaders.Names.HOST, host); getRequest.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); sendRequest(getRequest, timeout); }
currentRequestFailed = false; final HttpRequest httpRequest = (HttpRequest) msg; LOG.trace("Received request. URL:{} Method:{}", httpRequest.getUri(), httpRequest.getMethod()); if (httpRequest.getMethod().equals(HttpMethod.POST)) { if (HttpPostRequestDecoder.isMultipart(httpRequest)) { currentHttpPostRequestDecoder = new HttpPostRequestDecoder(DATA_FACTORY, httpRequest);
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { HttpRequest request = msg instanceof HttpRequest ? (HttpRequest) msg : null; String path = request == null ? "" : request.uri(); String redirectAddress = getRedirectAddress(ctx); log.trace("Received non-SSL request, redirecting to {}{}", redirectAddress, path); HttpResponse response = HandlerRedirectUtils.getRedirectResponse( redirectAddress, path, HttpResponseStatus.MOVED_PERMANENTLY); if (request != null) { KeepAliveWrite.flush(ctx, request, response); } else { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } }
if (currentRequest.getMethod() == HttpMethod.GET || currentRequest.getMethod() == HttpMethod.DELETE) { else if (currentRequest.getMethod() == HttpMethod.POST) { currentRequestPath = new QueryStringDecoder(currentRequest.getUri(), ENCODING).path(); currentDecoder = new HttpPostRequestDecoder(DATA_FACTORY, currentRequest, ENCODING); throw new IOException("Unsupported HTTP method: " + currentRequest.getMethod().name()); encoder.addParam("filename", name); currentRequest.setUri(encoder.toString());
/** * Sends a simple PATCH request to the given path. You only specify the $path part of * http://$host:$host/$path. * * @param path The $path to PATCH (http://$host:$host/$path) */ public void sendPatchRequest(String path, FiniteDuration timeout) throws TimeoutException, InterruptedException { if (!path.startsWith("/")) { path = "/" + path; } HttpRequest getRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PATCH, path); getRequest.headers().set(HttpHeaders.Names.HOST, host); getRequest.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); sendRequest(getRequest, timeout); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { HttpRequest request = msg instanceof HttpRequest ? (HttpRequest) msg : null; String path = request == null ? "" : request.uri(); String redirectAddress = getRedirectAddress(ctx); log.trace("Received non-SSL request, redirecting to {}{}", redirectAddress, path); HttpResponse response = HandlerRedirectUtils.getRedirectResponse( redirectAddress, path, HttpResponseStatus.MOVED_PERMANENTLY); if (request != null) { KeepAliveWrite.flush(ctx, request, response); } else { ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } }
final String ifModifiedSince = request.headers().get(IF_MODIFIED_SINCE); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { SimpleDateFormat dateFormatter = new SimpleDateFormat(StaticFileServerHandler.HTTP_DATE_FORMAT, Locale.US);