org.apache.flink.runtime.rest.messages.RequestBody Java Examples
The following examples show how to use
org.apache.flink.runtime.rest.messages.RequestBody.
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: HandlerRequestUtils.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass, final X defaultValue) throws RestHandlerException { final List<X> values = request.getQueryParameter(queryParameterClass); final X value; if (values.size() > 1) { throw new RestHandlerException( String.format("Expected only one value %s.", values), HttpResponseStatus.BAD_REQUEST); } else if (values.size() == 1) { value = values.get(0); } else { value = defaultValue; } return value; }
Example #2
Source File: HandlerRequestUtils.java From flink with Apache License 2.0 | 6 votes |
public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass, final X defaultValue) throws RestHandlerException { final List<X> values = request.getQueryParameter(queryParameterClass); final X value; if (values.size() > 1) { throw new RestHandlerException( String.format("Expected only one value %s.", values), HttpResponseStatus.BAD_REQUEST); } else if (values.size() == 1) { value = values.get(0); } else { value = defaultValue; } return value; }
Example #3
Source File: RestClient.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads) throws IOException { return sendRequest( targetAddress, targetPort, messageHeaders, messageParameters, request, fileUploads, RestAPIVersion.getLatestVersion(messageHeaders.getSupportedAPIVersions())); }
Example #4
Source File: RestClusterClientTest.java From flink with Apache License 2.0 | 6 votes |
@Nonnull private RestClient createRestClient() throws ConfigurationException { return new RestClient(RestClientConfiguration.fromConfiguration(restConfig), executor) { @Override public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( final String targetAddress, final int targetPort, final M messageHeaders, final U messageParameters, final R request, final Collection<FileUpload> files) throws IOException { if (failHttpRequest.test(messageHeaders, messageParameters, request)) { return FutureUtils.completedExceptionally(new IOException("expected")); } else { return super.sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, files); } } }; }
Example #5
Source File: RestClusterClientTest.java From flink with Apache License 2.0 | 6 votes |
@Nonnull private RestClient createRestClient() throws ConfigurationException { return new RestClient(RestClientConfiguration.fromConfiguration(restConfig), executor) { @Override public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( final String targetAddress, final int targetPort, final M messageHeaders, final U messageParameters, final R request, final Collection<FileUpload> files) throws IOException { if (failHttpRequest.test(messageHeaders, messageParameters, request)) { return FutureUtils.completedExceptionally(new IOException("expected")); } else { return super.sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, files); } } }; }
Example #6
Source File: RestClient.java From flink with Apache License 2.0 | 6 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads) throws IOException { return sendRequest( targetAddress, targetPort, messageHeaders, messageParameters, request, fileUploads, RestAPIVersion.getLatestVersion(messageHeaders.getSupportedAPIVersions())); }
Example #7
Source File: RestClusterClientTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Nonnull private RestClient createRestClient() throws ConfigurationException { return new RestClient(RestClientConfiguration.fromConfiguration(restConfig), executor) { @Override public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( final String targetAddress, final int targetPort, final M messageHeaders, final U messageParameters, final R request, final Collection<FileUpload> files) throws IOException { if (failHttpRequest.test(messageHeaders, messageParameters, request)) { return FutureUtils.completedExceptionally(new IOException("expected")); } else { return super.sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, files); } } }; }
Example #8
Source File: RestClient.java From flink with Apache License 2.0 | 6 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads) throws IOException { return sendRequest( targetAddress, targetPort, messageHeaders, messageParameters, request, fileUploads, RestAPIVersion.getLatestVersion(messageHeaders.getSupportedAPIVersions())); }
Example #9
Source File: HandlerRequestUtils.java From flink with Apache License 2.0 | 6 votes |
public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass, final X defaultValue) throws RestHandlerException { final List<X> values = request.getQueryParameter(queryParameterClass); final X value; if (values.size() > 1) { throw new RestHandlerException( String.format("Expected only one value %s.", values), HttpResponseStatus.BAD_REQUEST); } else if (values.size() == 1) { value = values.get(0); } else { value = defaultValue; } return value; }
Example #10
Source File: HandlerRequestUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Returns the value of a query parameter, or {@code null} if the query parameter is not set. * @throws RestHandlerException If the query parameter is repeated. */ public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass) throws RestHandlerException { return getQueryParameter(request, queryParameterClass, null); }
Example #11
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Collection<FileUpload> filesToUpload, Predicate<Throwable> retryPredicate) { return retry(() -> getWebMonitorBaseUrl().thenCompose(webMonitorBaseUrl -> { try { return restClient.sendRequest(webMonitorBaseUrl.getHost(), webMonitorBaseUrl.getPort(), messageHeaders, messageParameters, request, filesToUpload); } catch (IOException e) { throw new CompletionException(e); } }), retryPredicate); }
Example #12
Source File: RestClient.java From flink with Apache License 2.0 | 5 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request) throws IOException { return sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, Collections.emptyList()); }
Example #13
Source File: HandlerRequestUtils.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Returns the value of a query parameter, or {@code null} if the query parameter is not set. * @throws RestHandlerException If the query parameter is repeated. */ public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass) throws RestHandlerException { return getQueryParameter(request, queryParameterClass, null); }
Example #14
Source File: RestClient.java From flink with Apache License 2.0 | 5 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request) throws IOException { return sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, Collections.emptyList()); }
Example #15
Source File: HandlerRequestUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Returns the value of a query parameter, or {@code null} if the query parameter is not set. * @throws RestHandlerException If the query parameter is repeated. */ public static <X, P extends MessageQueryParameter<X>, R extends RequestBody, M extends MessageParameters> X getQueryParameter( final HandlerRequest<R, M> request, final Class<P> queryParameterClass) throws RestHandlerException { return getQueryParameter(request, queryParameterClass, null); }
Example #16
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Collection<FileUpload> filesToUpload, Predicate<Throwable> retryPredicate) { return retry(() -> getWebMonitorBaseUrl().thenCompose(webMonitorBaseUrl -> { try { return restClient.sendRequest(webMonitorBaseUrl.getHost(), webMonitorBaseUrl.getPort(), messageHeaders, messageParameters, request, filesToUpload); } catch (IOException e) { throw new CompletionException(e); } }), retryPredicate); }
Example #17
Source File: RestClusterClient.java From flink with Apache License 2.0 | 5 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Collection<FileUpload> filesToUpload, Predicate<Throwable> retryPredicate) { return retry(() -> getWebMonitorBaseUrl().thenCompose(webMonitorBaseUrl -> { try { return restClient.sendRequest(webMonitorBaseUrl.getHost(), webMonitorBaseUrl.getPort(), messageHeaders, messageParameters, request, filesToUpload); } catch (IOException e) { throw new CompletionException(e); } }), retryPredicate); }
Example #18
Source File: RestClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request) throws IOException { return sendRequest(targetAddress, targetPort, messageHeaders, messageParameters, request, Collections.emptyList()); }
Example #19
Source File: RestClient.java From flink with Apache License 2.0 | 4 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads, RestAPIVersion apiVersion) throws IOException { Preconditions.checkNotNull(targetAddress); Preconditions.checkArgument(NetUtils.isValidHostPort(targetPort), "The target port " + targetPort + " is not in the range [0, 65535]."); Preconditions.checkNotNull(messageHeaders); Preconditions.checkNotNull(request); Preconditions.checkNotNull(messageParameters); Preconditions.checkNotNull(fileUploads); Preconditions.checkState(messageParameters.isResolved(), "Message parameters were not resolved."); if (!messageHeaders.getSupportedAPIVersions().contains(apiVersion)) { throw new IllegalArgumentException(String.format( "The requested version %s is not supported by the request (method=%s URL=%s). Supported versions are: %s.", apiVersion, messageHeaders.getHttpMethod(), messageHeaders.getTargetRestEndpointURL(), messageHeaders.getSupportedAPIVersions().stream().map(RestAPIVersion::getURLVersionPrefix).collect(Collectors.joining(",")))); } String versionedHandlerURL = "/" + apiVersion.getURLVersionPrefix() + messageHeaders.getTargetRestEndpointURL(); String targetUrl = MessageParameters.resolveUrl(versionedHandlerURL, messageParameters); LOG.debug("Sending request of class {} to {}:{}{}", request.getClass(), targetAddress, targetPort, targetUrl); // serialize payload StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, request); ByteBuf payload = Unpooled.wrappedBuffer(sw.toString().getBytes(ConfigConstants.DEFAULT_CHARSET)); Request httpRequest = createRequest(targetAddress + ':' + targetPort, targetUrl, messageHeaders.getHttpMethod().getNettyHttpMethod(), payload, fileUploads); final JavaType responseType; final Collection<Class<?>> typeParameters = messageHeaders.getResponseTypeParameters(); if (typeParameters.isEmpty()) { responseType = objectMapper.constructType(messageHeaders.getResponseClass()); } else { responseType = objectMapper.getTypeFactory().constructParametricType( messageHeaders.getResponseClass(), typeParameters.toArray(new Class<?>[typeParameters.size()])); } return submitRequest(targetAddress, targetPort, httpRequest, responseType); }
Example #20
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, EmptyMessageParameters>, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, R request) { return sendRequest(messageHeaders, EmptyMessageParameters.getInstance(), request); }
Example #21
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
@VisibleForTesting public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, U messageParameters, R request) { return sendRetriableRequest( messageHeaders, messageParameters, request, isConnectionProblemOrServiceUnavailable()); }
Example #22
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Predicate<Throwable> retryPredicate) { return sendRetriableRequest(messageHeaders, messageParameters, request, Collections.emptyList(), retryPredicate); }
Example #23
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, EmptyMessageParameters>, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, R request) { return sendRequest(messageHeaders, EmptyMessageParameters.getInstance(), request); }
Example #24
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Predicate<Throwable> retryPredicate) { return sendRetriableRequest(messageHeaders, messageParameters, request, Collections.emptyList(), retryPredicate); }
Example #25
Source File: RestClusterClient.java From flink with Apache License 2.0 | 4 votes |
@VisibleForTesting public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, U messageParameters, R request) { return sendRetriableRequest( messageHeaders, messageParameters, request, isConnectionProblemOrServiceUnavailable()); }
Example #26
Source File: RestClient.java From flink with Apache License 2.0 | 4 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads, RestAPIVersion apiVersion) throws IOException { Preconditions.checkNotNull(targetAddress); Preconditions.checkArgument(0 <= targetPort && targetPort < 65536, "The target port " + targetPort + " is not in the range (0, 65536]."); Preconditions.checkNotNull(messageHeaders); Preconditions.checkNotNull(request); Preconditions.checkNotNull(messageParameters); Preconditions.checkNotNull(fileUploads); Preconditions.checkState(messageParameters.isResolved(), "Message parameters were not resolved."); if (!messageHeaders.getSupportedAPIVersions().contains(apiVersion)) { throw new IllegalArgumentException(String.format( "The requested version %s is not supported by the request (method=%s URL=%s). Supported versions are: %s.", apiVersion, messageHeaders.getHttpMethod(), messageHeaders.getTargetRestEndpointURL(), messageHeaders.getSupportedAPIVersions().stream().map(RestAPIVersion::getURLVersionPrefix).collect(Collectors.joining(",")))); } String versionedHandlerURL = "/" + apiVersion.getURLVersionPrefix() + messageHeaders.getTargetRestEndpointURL(); String targetUrl = MessageParameters.resolveUrl(versionedHandlerURL, messageParameters); LOG.debug("Sending request of class {} to {}:{}{}", request.getClass(), targetAddress, targetPort, targetUrl); // serialize payload StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, request); ByteBuf payload = Unpooled.wrappedBuffer(sw.toString().getBytes(ConfigConstants.DEFAULT_CHARSET)); Request httpRequest = createRequest(targetAddress + ':' + targetPort, targetUrl, messageHeaders.getHttpMethod().getNettyHttpMethod(), payload, fileUploads); final JavaType responseType; final Collection<Class<?>> typeParameters = messageHeaders.getResponseTypeParameters(); if (typeParameters.isEmpty()) { responseType = objectMapper.constructType(messageHeaders.getResponseClass()); } else { responseType = objectMapper.getTypeFactory().constructParametricType( messageHeaders.getResponseClass(), typeParameters.toArray(new Class<?>[typeParameters.size()])); } return submitRequest(targetAddress, targetPort, httpRequest, responseType); }
Example #27
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRetriableRequest(M messageHeaders, U messageParameters, R request, Predicate<Throwable> retryPredicate) { return sendRetriableRequest(messageHeaders, messageParameters, request, Collections.emptyList(), retryPredicate); }
Example #28
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@VisibleForTesting public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, U messageParameters, R request) { return sendRetriableRequest( messageHeaders, messageParameters, request, isConnectionProblemOrServiceUnavailable()); }
Example #29
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private <M extends MessageHeaders<R, P, EmptyMessageParameters>, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest(M messageHeaders, R request) { return sendRequest(messageHeaders, EmptyMessageParameters.getInstance(), request); }
Example #30
Source File: RestClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
public <M extends MessageHeaders<R, P, U>, U extends MessageParameters, R extends RequestBody, P extends ResponseBody> CompletableFuture<P> sendRequest( String targetAddress, int targetPort, M messageHeaders, U messageParameters, R request, Collection<FileUpload> fileUploads, RestAPIVersion apiVersion) throws IOException { Preconditions.checkNotNull(targetAddress); Preconditions.checkArgument(0 <= targetPort && targetPort < 65536, "The target port " + targetPort + " is not in the range (0, 65536]."); Preconditions.checkNotNull(messageHeaders); Preconditions.checkNotNull(request); Preconditions.checkNotNull(messageParameters); Preconditions.checkNotNull(fileUploads); Preconditions.checkState(messageParameters.isResolved(), "Message parameters were not resolved."); if (!messageHeaders.getSupportedAPIVersions().contains(apiVersion)) { throw new IllegalArgumentException(String.format( "The requested version %s is not supported by the request (method=%s URL=%s). Supported versions are: %s.", apiVersion, messageHeaders.getHttpMethod(), messageHeaders.getTargetRestEndpointURL(), messageHeaders.getSupportedAPIVersions().stream().map(RestAPIVersion::getURLVersionPrefix).collect(Collectors.joining(",")))); } String versionedHandlerURL = "/" + apiVersion.getURLVersionPrefix() + messageHeaders.getTargetRestEndpointURL(); String targetUrl = MessageParameters.resolveUrl(versionedHandlerURL, messageParameters); LOG.debug("Sending request of class {} to {}:{}{}", request.getClass(), targetAddress, targetPort, targetUrl); // serialize payload StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, request); ByteBuf payload = Unpooled.wrappedBuffer(sw.toString().getBytes(ConfigConstants.DEFAULT_CHARSET)); Request httpRequest = createRequest(targetAddress + ':' + targetPort, targetUrl, messageHeaders.getHttpMethod().getNettyHttpMethod(), payload, fileUploads); final JavaType responseType; final Collection<Class<?>> typeParameters = messageHeaders.getResponseTypeParameters(); if (typeParameters.isEmpty()) { responseType = objectMapper.constructType(messageHeaders.getResponseClass()); } else { responseType = objectMapper.getTypeFactory().constructParametricType( messageHeaders.getResponseClass(), typeParameters.toArray(new Class<?>[typeParameters.size()])); } return submitRequest(targetAddress, targetPort, httpRequest, responseType); }