org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler. 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: RestAPIDocGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(CompletableFuture<String> localAddressFuture) {
	return Arrays.asList(
		Tuple2.of(
			new TestEmptyMessageHeaders(
				"/test/empty1",
				"This is a testing REST API."), null),
		Tuple2.of(
			new TestEmptyMessageHeaders(
				"/test/empty2",
				"This is another testing REST API."), null),
		Tuple2.of(
			new TestExcludeMessageHeaders(
				"/test/exclude1",
				"This REST API should not appear in the generated documentation."), null),
		Tuple2.of(
			new TestExcludeMessageHeaders(
				"/test/exclude2",
				"This REST API should also not appear in the generated documentation."), null));
}
 
Example #2
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private void routed(
		ChannelHandlerContext channelHandlerContext,
		RouteResult<?> routeResult,
		HttpRequest httpRequest) {
	ChannelInboundHandler handler = (ChannelInboundHandler) routeResult.target();

	// The handler may have been added (keep alive)
	ChannelPipeline pipeline     = channelHandlerContext.pipeline();
	ChannelHandler addedHandler = pipeline.get(ROUTED_HANDLER_NAME);
	if (handler != addedHandler) {
		if (addedHandler == null) {
			pipeline.addAfter(ROUTER_HANDLER_NAME, ROUTED_HANDLER_NAME, handler);
		} else {
			pipeline.replace(addedHandler, ROUTED_HANDLER_NAME, handler);
		}
	}

	RoutedRequest<?> request = new RoutedRequest<>(routeResult, httpRequest);
	channelHandlerContext.fireChannelRead(request.retain());
}
 
Example #3
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicateHandlerRegistrationIsForbidden() throws Exception {
	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(TestUploadHeaders.INSTANCE, testHandler)
	);

	assertThrows("Duplicate REST handler",
		FlinkRuntimeException.class,
		() -> {
			try (TestRestServerEndpoint restServerEndpoint =  new TestRestServerEndpoint(serverConfig, handlers)) {
				restServerEndpoint.start();
				return null;
			}
		});
}
 
Example #4
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndpointsMustBeUnique() throws Exception {
	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(new TestHeaders(), testUploadHandler)
	);

	assertThrows("REST handler registration",
		FlinkRuntimeException.class,
		() -> {
			try (TestRestServerEndpoint restServerEndpoint =  new TestRestServerEndpoint(serverConfig, handlers)) {
				restServerEndpoint.start();
				return null;
			}
		});
}
 
Example #5
Source File: WebMonitorEndpoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private ChannelInboundHandler createStaticFileHandler(
		Time timeout,
		File fileToServe) {

	if (fileToServe == null) {
		return new ConstantTextHandler("(file unavailable)");
	} else {
		try {
			return new StaticFileServerHandler<>(
				leaderRetriever,
				timeout,
				fileToServe);
		} catch (IOException e) {
			log.info("Cannot load log file handler.", e);
			return new ConstantTextHandler("(log file unavailable)");
		}
	}
}
 
Example #6
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private void routed(
		ChannelHandlerContext channelHandlerContext,
		RouteResult<?> routeResult,
		HttpRequest httpRequest) {
	ChannelInboundHandler handler = (ChannelInboundHandler) routeResult.target();

	// The handler may have been added (keep alive)
	ChannelPipeline pipeline     = channelHandlerContext.pipeline();
	ChannelHandler addedHandler = pipeline.get(ROUTED_HANDLER_NAME);
	if (handler != addedHandler) {
		if (addedHandler == null) {
			pipeline.addAfter(ROUTER_HANDLER_NAME, ROUTED_HANDLER_NAME, handler);
		} else {
			pipeline.replace(addedHandler, ROUTED_HANDLER_NAME, handler);
		}
	}

	RoutedRequest<?> request = new RoutedRequest<>(routeResult, httpRequest);
	channelHandlerContext.fireChannelRead(request.retain());
}
 
Example #7
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example #8
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example #9
Source File: RouterHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void routed(
		ChannelHandlerContext channelHandlerContext,
		RouteResult<?> routeResult,
		HttpRequest httpRequest) {
	ChannelInboundHandler handler = (ChannelInboundHandler) routeResult.target();

	// The handler may have been added (keep alive)
	ChannelPipeline pipeline     = channelHandlerContext.pipeline();
	ChannelHandler addedHandler = pipeline.get(ROUTED_HANDLER_NAME);
	if (handler != addedHandler) {
		if (addedHandler == null) {
			pipeline.addAfter(ROUTER_HANDLER_NAME, ROUTED_HANDLER_NAME, handler);
		} else {
			pipeline.replace(addedHandler, ROUTED_HANDLER_NAME, handler);
		}
	}

	RoutedRequest<?> request = new RoutedRequest<>(routeResult, httpRequest);
	channelHandlerContext.fireChannelRead(request.retain());
}
 
Example #10
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example #11
Source File: WebMonitorEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private ChannelInboundHandler createStaticFileHandler(
		Time timeout,
		File fileToServe) {

	if (fileToServe == null) {
		return new ConstantTextHandler("(file unavailable)");
	} else {
		try {
			return new StaticFileServerHandler<>(
				leaderRetriever,
				timeout,
				fileToServe);
		} catch (IOException e) {
			log.info("Cannot load log file handler.", e);
			return new ConstantTextHandler("(log file unavailable)");
		}
	}
}
 
Example #12
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #13
Source File: TestRestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #14
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void checkAllEndpointsAndHandlersAreUnique(final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) {
	// check for all handlers that
	// 1) the instance is only registered once
	// 2) only 1 handler is registered for each endpoint (defined by (version, method, url))
	// technically the first check is redundant since a duplicate instance also returns the same headers which
	// should fail the second check, but we get a better error message
	final Set<String> uniqueEndpoints = new HashSet<>();
	final Set<ChannelInboundHandler> distinctHandlers = Collections.newSetFromMap(new IdentityHashMap<>());
	for (Tuple2<RestHandlerSpecification, ChannelInboundHandler> handler : handlers) {
		boolean isNewHandler = distinctHandlers.add(handler.f1);
		if (!isNewHandler) {
			throw new FlinkRuntimeException("Duplicate REST handler instance found."
				+ " Please ensure each instance is registered only once.");
		}

		final RestHandlerSpecification headers = handler.f0;
		for (RestAPIVersion supportedAPIVersion : headers.getSupportedAPIVersions()) {
			final String parameterizedEndpoint = supportedAPIVersion.toString() + headers.getHttpMethod() + headers.getTargetRestEndpointURL();
			// normalize path parameters; distinct path parameters still clash at runtime
			final String normalizedEndpoint = parameterizedEndpoint.replaceAll(":[\\w-]+", ":param");
			boolean isNewEndpoint = uniqueEndpoints.add(normalizedEndpoint);
			if (!isNewEndpoint) {
				throw new FlinkRuntimeException(
					String.format(
						"REST handler registration overlaps with another registration for: version=%s, method=%s, url=%s.",
						supportedAPIVersion, headers.getHttpMethod(), headers.getTargetRestEndpointURL()));
			}
		}
	}
}
 
Example #15
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #16
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #17
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #18
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

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

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #19
Source File: TestRestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #20
Source File: TestRestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #21
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

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

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #22
Source File: MultipartUploadResource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

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

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #23
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #24
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #25
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 4 votes vote down vote up
TestRestServerEndpoint(
	RestServerEndpointConfiguration configuration,
	List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) throws IOException {
	super(configuration);
	this.handlers = requireNonNull(handlers);
}
 
Example #26
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return handlers;
}
 
Example #27
Source File: DocumentingDispatcherRestEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return super.initializeHandlers(localAddressFuture);
}
 
Example #28
Source File: WebMonitorExtension.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> getHandlers() {
	return Collections.emptyList();
}
 
Example #29
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
	config.setString(WebOptions.UPLOAD_DIR, temporaryFolder.newFolder().getCanonicalPath());

	defaultSSLContext = SSLContext.getDefault();
	defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
	final SSLContext sslClientContext = SSLUtils.createRestSSLContext(config, true);
	if (sslClientContext != null) {
		SSLContext.setDefault(sslClientContext);
		HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getSocketFactory());
	}

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);
	RestClientConfiguration clientConfig = RestClientConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

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

	testHandler = new TestHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionHandler testVersionHandler = new TestVersionHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionSelectionHandler1 testVersionSelectionHandler1 = new TestVersionSelectionHandler1(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionSelectionHandler2 testVersionSelectionHandler2 = new TestVersionSelectionHandler2(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	testUploadHandler = new TestUploadHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	final StaticFileServerHandler<RestfulGateway> staticFileServerHandler = new StaticFileServerHandler<>(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT,
		temporaryFolder.getRoot());

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(TestUploadHeaders.INSTANCE, testUploadHandler),
		Tuple2.of(testVersionHandler.getMessageHeaders(), testVersionHandler),
		Tuple2.of(testVersionSelectionHandler1.getMessageHeaders(), testVersionSelectionHandler1),
		Tuple2.of(testVersionSelectionHandler2.getMessageHeaders(), testVersionSelectionHandler2),
		Tuple2.of(WebContentHandlerSpecification.getInstance(), staticFileServerHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);
	restClient = new TestRestClient(clientConfig);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getServerAddress();
}
 
Example #30
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
TestRestServerEndpoint(
		RestServerEndpointConfiguration configuration,
		List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) throws IOException {
	super(configuration);
	this.handlers = requireNonNull(handlers);
}