Java Code Examples for org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#INTERNAL_SERVER_ERROR

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus#INTERNAL_SERVER_ERROR . 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: MultipartUploadResource.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
static void verifyFileUpload(Collection<Path> expectedFiles, Collection<Path> uploadedFiles) throws RestHandlerException {
	try {
		assertEquals(expectedFiles.size(), uploadedFiles.size());

		List<Path> expectedList = new ArrayList<>(expectedFiles);
		List<Path> actualList = new ArrayList<>(uploadedFiles);
		expectedList.sort(Comparator.comparing(Path::toString));
		actualList.sort(Comparator.comparing(Path::toString));

		for (int x = 0; x < expectedList.size(); x++) {
			Path expected = expectedList.get(x);
			Path actual = actualList.get(x);

			assertEquals(expected.getFileName().toString(), actual.getFileName().toString());

			byte[] originalContent = Files.readAllBytes(expected);
			byte[] receivedContent = Files.readAllBytes(actual);
			assertArrayEquals(originalContent, receivedContent);
		}
	} catch (Exception e) {
		// return 505 to differentiate from common BAD_REQUEST responses in this test
		throw new RestHandlerException("Test verification failed.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
}
 
Example 2
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 6 votes vote down vote up
static void verifyFileUpload(Collection<Path> expectedFiles, Collection<Path> uploadedFiles) throws RestHandlerException {
	try {
		assertEquals(expectedFiles.size(), uploadedFiles.size());

		List<Path> expectedList = new ArrayList<>(expectedFiles);
		List<Path> actualList = new ArrayList<>(uploadedFiles);
		expectedList.sort(Comparator.comparing(Path::toString));
		actualList.sort(Comparator.comparing(Path::toString));

		for (int x = 0; x < expectedList.size(); x++) {
			Path expected = expectedList.get(x);
			Path actual = actualList.get(x);

			assertEquals(expected.getFileName().toString(), actual.getFileName().toString());

			byte[] originalContent = Files.readAllBytes(expected);
			byte[] receivedContent = Files.readAllBytes(actual);
			assertArrayEquals(originalContent, receivedContent);
		}
	} catch (Exception e) {
		// return 505 to differentiate from common BAD_REQUEST responses in this test
		throw new RestHandlerException("Test verification failed.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
}
 
Example 3
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 6 votes vote down vote up
static void verifyFileUpload(Collection<Path> expectedFiles, Collection<Path> uploadedFiles) throws RestHandlerException {
	try {
		assertEquals(expectedFiles.size(), uploadedFiles.size());

		List<Path> expectedList = new ArrayList<>(expectedFiles);
		List<Path> actualList = new ArrayList<>(uploadedFiles);
		expectedList.sort(Comparator.comparing(Path::toString));
		actualList.sort(Comparator.comparing(Path::toString));

		for (int x = 0; x < expectedList.size(); x++) {
			Path expected = expectedList.get(x);
			Path actual = actualList.get(x);

			assertEquals(expected.getFileName().toString(), actual.getFileName().toString());

			byte[] originalContent = Files.readAllBytes(expected);
			byte[] receivedContent = Files.readAllBytes(actual);
			assertArrayEquals(originalContent, receivedContent);
		}
	} catch (Exception e) {
		// return 505 to differentiate from common BAD_REQUEST responses in this test
		throw new RestHandlerException("Test verification failed.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
}
 
Example 4
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 5
Source File: MultipartUploadResource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<TestRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (!uploadedFiles.isEmpty()) {
		throw new RestHandlerException("This handler should not have received file uploads.", HttpResponseStatus.INTERNAL_SERVER_ERROR);
	}
	this.lastReceivedRequest = request.getRequestBody();
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 6
Source File: RestServerEndpointITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (uploadedFiles.size() != 1) {
		throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
	}

	try {
		lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
	} catch (IOException e) {
		throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 7
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 8
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<TestRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (!uploadedFiles.isEmpty()) {
		throw new RestHandlerException("This handler should not have received file uploads.", HttpResponseStatus.INTERNAL_SERVER_ERROR);
	}
	this.lastReceivedRequest = request.getRequestBody();
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 9
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (uploadedFiles.size() != 1) {
		throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
	}

	try {
		lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
	} catch (IOException e) {
		throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 10
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 11
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<TestRequestBody, EmptyMessageParameters> request, @Nonnull RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (!uploadedFiles.isEmpty()) {
		throw new RestHandlerException("This handler should not have received file uploads.", HttpResponseStatus.INTERNAL_SERVER_ERROR);
	}
	this.lastReceivedRequest = request.getRequestBody();
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 12
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull final HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull final RestfulGateway gateway) throws RestHandlerException {
	Collection<Path> uploadedFiles = request.getUploadedFiles().stream().map(File::toPath).collect(Collectors.toList());
	if (uploadedFiles.size() != 1) {
		throw new RestHandlerException("Expected 1 file, received " + uploadedFiles.size() + '.', HttpResponseStatus.BAD_REQUEST);
	}

	try {
		lastUploadedFileContents = Files.readAllBytes(uploadedFiles.iterator().next());
	} catch (IOException e) {
		throw new RestHandlerException("Could not read contents of uploaded file.", HttpResponseStatus.INTERNAL_SERVER_ERROR, e);
	}
	return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
}
 
Example 13
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
 
Example 14
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
 
Example 15
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected CompletableFuture<JobSubmitResponseBody> handleRequest(
		@Nonnull HandlerRequest<JobSubmitRequestBody, EmptyMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	throw new RestHandlerException("expected", HttpResponseStatus.INTERNAL_SERVER_ERROR);
}