org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: RouterHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: ConstantTextHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, RoutedRequest routed) throws Exception {
	HttpResponse response = new DefaultFullHttpResponse(
		HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(encodedText));

	response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, encodedText.length);
	response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");

	KeepAliveWrite.flush(ctx, routed.getRequest(), response);
}
 
Example #5
Source File: AbstractHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileCleanup() throws Exception {
	final Path dir = temporaryFolder.newFolder().toPath();
	final Path file = dir.resolve("file");
	Files.createFile(file);

	RestfulGateway mockRestfulGateway = new TestingRestfulGateway.Builder()
		.build();

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	CompletableFuture<Void> requestProcessingCompleteFuture = new CompletableFuture<>();
	TestHandler handler = new TestHandler(requestProcessingCompleteFuture, mockGatewayRetriever);

	RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(), Collections.emptyMap(), "");
	HttpRequest request = new DefaultFullHttpRequest(
		HttpVersion.HTTP_1_1,
		HttpMethod.GET,
		TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(),
		Unpooled.wrappedBuffer(new byte[0]));
	RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);

	Attribute<FileUploads> attribute = new SimpleAttribute();
	attribute.set(new FileUploads(dir));
	Channel channel = mock(Channel.class);
	when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);

	ChannelHandlerContext context = mock(ChannelHandlerContext.class);
	when(context.channel()).thenReturn(channel);

	handler.respondAsLeader(context, routerRequest, mockRestfulGateway);

	// the (asynchronous) request processing is not yet complete so the files should still exist
	Assert.assertTrue(Files.exists(file));
	requestProcessingCompleteFuture.complete(null);
	Assert.assertFalse(Files.exists(file));
}
 
Example #6
Source File: HandlerRedirectUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getResponse(HttpResponseStatus status, @Nullable String message) {
	ByteBuf messageByteBuf = message == null ? Unpooled.buffer(0)
		: Unpooled.wrappedBuffer(message.getBytes(ENCODING));
	FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, messageByteBuf);
	response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=" + ENCODING.name());
	response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

	return response;
}
 
Example #7
Source File: HandlerRedirectUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getRedirectResponse(String redirectAddress, String path, HttpResponseStatus code) {
	checkNotNull(redirectAddress, "Redirect address");
	checkNotNull(path, "Path");

	String newLocation = String.format("%s%s", redirectAddress, path);

	HttpResponse redirectResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, code);
	redirectResponse.headers().set(HttpHeaders.Names.LOCATION, newLocation);
	redirectResponse.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);

	return redirectResponse;
}
 
Example #8
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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, Duration 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);
}
 
Example #9
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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, Duration 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);
}
 
Example #10
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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, Duration 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);
}
 
Example #11
Source File: PipelineErrorHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
private void sendError(ChannelHandlerContext ctx, String error) {
	if (ctx.channel().isActive()) {
		DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
			HttpResponseStatus.INTERNAL_SERVER_ERROR,
			Unpooled.wrappedBuffer(error.getBytes(ConfigConstants.DEFAULT_CHARSET)));

		response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
		response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

		ctx.writeAndFlush(response);
	}
}
 
Example #12
Source File: AbstractHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileCleanup() throws Exception {
	final Path dir = temporaryFolder.newFolder().toPath();
	final Path file = dir.resolve("file");
	Files.createFile(file);

	RestfulGateway mockRestfulGateway = TestingRestfulGateway.newBuilder()
		.build();

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	CompletableFuture<Void> requestProcessingCompleteFuture = new CompletableFuture<>();
	TestHandler handler = new TestHandler(requestProcessingCompleteFuture, mockGatewayRetriever);

	RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(), Collections.emptyMap(), "");
	HttpRequest request = new DefaultFullHttpRequest(
		HttpVersion.HTTP_1_1,
		HttpMethod.GET,
		TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(),
		Unpooled.wrappedBuffer(new byte[0]));
	RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);

	Attribute<FileUploads> attribute = new SimpleAttribute();
	attribute.set(new FileUploads(dir));
	Channel channel = mock(Channel.class);
	when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);

	ChannelHandlerContext context = mock(ChannelHandlerContext.class);
	when(context.channel()).thenReturn(channel);

	handler.respondAsLeader(context, routerRequest, mockRestfulGateway);

	// the (asynchronous) request processing is not yet complete so the files should still exist
	Assert.assertTrue(Files.exists(file));
	requestProcessingCompleteFuture.complete(null);
	Assert.assertFalse(Files.exists(file));
}
 
Example #13
Source File: HandlerRedirectUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getResponse(HttpResponseStatus status, @Nullable String message) {
	ByteBuf messageByteBuf = message == null ? Unpooled.buffer(0)
		: Unpooled.wrappedBuffer(message.getBytes(ENCODING));
	FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, messageByteBuf);
	response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=" + ENCODING.name());
	response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

	return response;
}
 
Example #14
Source File: HandlerRedirectUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getRedirectResponse(String redirectAddress, String path, HttpResponseStatus code) {
	checkNotNull(redirectAddress, "Redirect address");
	checkNotNull(path, "Path");

	String newLocation = String.format("%s%s", redirectAddress, path);

	HttpResponse redirectResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, code);
	redirectResponse.headers().set(HttpHeaders.Names.LOCATION, newLocation);
	redirectResponse.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);

	return redirectResponse;
}
 
Example #15
Source File: PipelineErrorHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void sendError(ChannelHandlerContext ctx, String error) {
	if (ctx.channel().isActive()) {
		DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
			HttpResponseStatus.INTERNAL_SERVER_ERROR,
			Unpooled.wrappedBuffer(error.getBytes(ConfigConstants.DEFAULT_CHARSET)));

		response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
		response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

		ctx.writeAndFlush(response);
	}
}
 
Example #16
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #18
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #19
Source File: PipelineErrorHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
private void sendError(ChannelHandlerContext ctx, String error) {
	if (ctx.channel().isActive()) {
		DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
			HttpResponseStatus.INTERNAL_SERVER_ERROR,
			Unpooled.wrappedBuffer(error.getBytes(ConfigConstants.DEFAULT_CHARSET)));

		response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
		response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

		ctx.writeAndFlush(response);
	}
}
 
Example #20
Source File: AbstractHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testFileCleanup() throws Exception {
	final Path dir = temporaryFolder.newFolder().toPath();
	final Path file = dir.resolve("file");
	Files.createFile(file);

	RestfulGateway mockRestfulGateway = TestingRestfulGateway.newBuilder()
		.build();

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	CompletableFuture<Void> requestProcessingCompleteFuture = new CompletableFuture<>();
	TestHandler handler = new TestHandler(requestProcessingCompleteFuture, mockGatewayRetriever);

	RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(), Collections.emptyMap(), "");
	HttpRequest request = new DefaultFullHttpRequest(
		HttpVersion.HTTP_1_1,
		HttpMethod.GET,
		TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(),
		Unpooled.wrappedBuffer(new byte[0]));
	RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);

	Attribute<FileUploads> attribute = new SimpleAttribute();
	attribute.set(new FileUploads(dir));
	Channel channel = mock(Channel.class);
	when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);

	ChannelHandlerContext context = mock(ChannelHandlerContext.class);
	when(context.channel()).thenReturn(channel);

	handler.respondAsLeader(context, routerRequest, mockRestfulGateway);

	// the (asynchronous) request processing is not yet complete so the files should still exist
	Assert.assertTrue(Files.exists(file));
	requestProcessingCompleteFuture.complete(null);
	Assert.assertFalse(Files.exists(file));
}
 
Example #21
Source File: HandlerRedirectUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getResponse(HttpResponseStatus status, @Nullable String message) {
	ByteBuf messageByteBuf = message == null ? Unpooled.buffer(0)
		: Unpooled.wrappedBuffer(message.getBytes(ENCODING));
	FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, messageByteBuf);
	response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=" + ENCODING.name());
	response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());

	return response;
}
 
Example #22
Source File: HandlerRedirectUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static HttpResponse getRedirectResponse(String redirectAddress, String path, HttpResponseStatus code) {
	checkNotNull(redirectAddress, "Redirect address");
	checkNotNull(path, "Path");

	String newLocation = String.format("%s%s", redirectAddress, path);

	HttpResponse redirectResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, code);
	redirectResponse.headers().set(HttpHeaders.Names.LOCATION, newLocation);
	redirectResponse.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);

	return redirectResponse;
}
 
Example #23
Source File: ConstantTextHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, RoutedRequest routed) throws Exception {
	HttpResponse response = new DefaultFullHttpResponse(
		HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(encodedText));

	response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, encodedText.length);
	response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");

	KeepAliveWrite.flush(ctx, routed.getRequest(), response);
}
 
Example #24
Source File: HttpTestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #25
Source File: HttpTestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #26
Source File: HttpTestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}