io.micronaut.http.MutableHttpRequest Java Examples
The following examples show how to use
io.micronaut.http.MutableHttpRequest.
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: CommandsTest.java From java-slack-sdk with MIT License | 6 votes |
@Test public void invalidSignature() { MutableHttpRequest<String> request = HttpRequest.POST("/slack/events", ""); request.header("Content-Type", "application/x-www-form-urlencoded"); String timestamp = "" + (System.currentTimeMillis() / 1000 - 30 * 60); request.header(SlackSignature.HeaderNames.X_SLACK_REQUEST_TIMESTAMP, timestamp); String signature = signatureGenerator.generate(timestamp, helloBody); request.header(SlackSignature.HeaderNames.X_SLACK_SIGNATURE, signature); request.body(helloBody); try { client.toBlocking().exchange(request, String.class); Assertions.fail(); } catch (HttpClientResponseException e) { Assertions.assertEquals(401, e.getStatus().getCode()); Assertions.assertEquals("{\"error\":\"invalid request\"}", e.getResponse().getBody().get()); } }
Example #2
Source File: GoogleAuthFilter.java From micronaut-gcp with Apache License 2.0 | 5 votes |
@Override public Publisher<? extends HttpResponse<?>> doFilter(MutableHttpRequest<?> request, ClientFilterChain chain) { Flowable<String> token = Flowable.fromCallable(() -> encodeURI(request)) .flatMap(authURI -> authClient.retrieve(HttpRequest.GET(authURI).header( METADATA_FLAVOR, GOOGLE ))); return token.flatMap(t -> chain.proceed(request.bearerAuth(t))); }
Example #3
Source File: AwsLambdaRuntimeApi.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * * @param requestId Lambda Request Identifier * @param errorMessage Error Message * @param errorType Error Type * @param lambdaFunctionErrorType Lambda Function Error Type * @return A request to the invocation error path to inform in JSON format about the error which was thrown during the function execution. */ default HttpRequest<AwsLambdaRuntimeApiError> invocationErrorRequest(@Nonnull String requestId, @Nullable String errorMessage, @Nullable String errorType, @Nullable String lambdaFunctionErrorType) { AwsLambdaRuntimeApiError error = new AwsLambdaRuntimeApiError(errorMessage, errorType); MutableHttpRequest<AwsLambdaRuntimeApiError> request = HttpRequest.POST(errorUri(requestId), error); if (lambdaFunctionErrorType != null) { return request.header(LAMBDA_RUNTIME_FUNCTION_ERROR_TYPE, lambdaFunctionErrorType); } return request; }
Example #4
Source File: AwsLambdaRuntimeApi.java From micronaut-aws with Apache License 2.0 | 5 votes |
/** * * @param errorMessage Error Message * @param errorType Error Type * @param lambdaFunctionErrorType Lambda Function Error Type * @return A post request which should be send if the runtime encounters an error during initialization to post an error message to the initialization error path. */ default HttpRequest<AwsLambdaRuntimeApiError> initializationErrorRequest(@Nullable String errorMessage, @Nullable String errorType, @Nullable String lambdaFunctionErrorType) { AwsLambdaRuntimeApiError error = new AwsLambdaRuntimeApiError(errorMessage, errorType); MutableHttpRequest<AwsLambdaRuntimeApiError> request = HttpRequest.POST(INIT_ERROR_URI, error); if (lambdaFunctionErrorType != null) { return request.header(LAMBDA_RUNTIME_FUNCTION_ERROR_TYPE, lambdaFunctionErrorType); } return request; }
Example #5
Source File: CommandsTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void command() { MutableHttpRequest<String> request = HttpRequest.POST("/slack/events", ""); request.header("Content-Type", "application/x-www-form-urlencoded"); String timestamp = "" + (System.currentTimeMillis() / 1000); request.header(SlackSignature.HeaderNames.X_SLACK_REQUEST_TIMESTAMP, timestamp); String signature = signatureGenerator.generate(timestamp, helloBody); request.header(SlackSignature.HeaderNames.X_SLACK_SIGNATURE, signature); request.body(helloBody); HttpResponse<String> response = client.toBlocking().exchange(request, String.class); Assertions.assertEquals(200, response.getStatus().getCode()); Assertions.assertEquals("{\"text\":\"Thanks!\"}", response.getBody().get()); }
Example #6
Source File: CommandsTest.java From java-slack-sdk with MIT License | 5 votes |
@Test public void regexp_matching() { MutableHttpRequest<String> request = HttpRequest.POST("/slack/events", ""); request.header("Content-Type", "application/x-www-form-urlencoded"); String timestamp = "" + (System.currentTimeMillis() / 1000); request.header(SlackSignature.HeaderNames.X_SLACK_REQUEST_TIMESTAMP, timestamp); String signature = signatureGenerator.generate(timestamp, submissionBody); request.header(SlackSignature.HeaderNames.X_SLACK_SIGNATURE, signature); request.body(submissionBody); HttpResponse<String> response = client.toBlocking().exchange(request, String.class); Assertions.assertEquals(200, response.getStatus().getCode()); Assertions.assertEquals("{\"text\":\"/submission-no.2019\"}", response.getBody().get()); }
Example #7
Source File: GoogleAuthFilter.java From micronaut-gcp with Apache License 2.0 | 4 votes |
private String encodeURI(MutableHttpRequest<?> request) throws UnsupportedEncodingException { URI fullURI = request.getUri(); String receivingURI = fullURI.getScheme() + "://" + fullURI.getHost(); return AUDIENCE + URLEncoder.encode(receivingURI, "UTF-8"); }