use of io.helidon.webserver.ServerRequest in project helidon by oracle.
the class StaticContentHandlerTest method classpathHandleSpaces.
@Test
void classpathHandleSpaces() {
ServerRequest request = mockRequestWithPath("foo/I have spaces.txt");
ServerResponse response = mock(ServerResponse.class);
TestClassPathContentHandler handler = TestClassPathContentHandler.create();
handler.handle(Http.Method.GET, request, response);
verify(request, never()).next();
assertThat(handler.counter.get(), is(1));
}
use of io.helidon.webserver.ServerRequest in project helidon by oracle.
the class TodosHandler method getAll.
/**
* Handler for {@code GET /todo}.
*
* @param req the server request
* @param res the server response
*/
private void getAll(final ServerRequest req, final ServerResponse res) {
AtomicReference<Span> createdSpan = new AtomicReference<>();
SpanContext spanContext = req.spanContext().orElseGet(() -> {
Span mySpan = req.tracer().buildSpan("getAll").start();
createdSpan.set(mySpan);
return mySpan.context();
});
secure(req, res, sc -> {
bsc.getAll(spanContext).thenAccept(res::send).exceptionally(t -> sendError(t, res)).whenComplete((noting, throwable) -> {
Span mySpan = createdSpan.get();
if (null != mySpan) {
mySpan.finish();
}
});
});
}
use of io.helidon.webserver.ServerRequest in project helidon by oracle.
the class OidcSupport method processJsonResponse.
private String processJsonResponse(ServerRequest req, ServerResponse res, JsonObject json) {
String tokenValue = json.getString("access_token");
String idToken = json.getString("id_token", null);
// redirect to "state"
String state = req.queryParams().first(STATE_PARAM_NAME).orElse(DEFAULT_REDIRECT);
res.status(Http.Status.TEMPORARY_REDIRECT_307);
if (oidcConfig.useParam()) {
state = (state.contains("?") ? "&" : "?") + oidcConfig.paramName() + "=" + tokenValue;
}
state = increaseRedirectCounter(state);
res.headers().add(Http.Header.LOCATION, state);
if (oidcConfig.useCookie()) {
ResponseHeaders headers = res.headers();
tokenCookieHandler.createCookie(tokenValue).forSingle(builder -> {
headers.addCookie(builder.build());
if (idToken != null && oidcConfig.logoutEnabled()) {
idTokenCookieHandler.createCookie(idToken).forSingle(it -> {
headers.addCookie(it.build());
res.send();
}).exceptionallyAccept(t -> sendError(res, t));
} else {
res.send();
}
}).exceptionallyAccept(t -> sendError(res, t));
} else {
res.send();
}
return "done";
}
use of io.helidon.webserver.ServerRequest in project helidon by oracle.
the class OidcSupport method processCode.
private void processCode(String code, ServerRequest req, ServerResponse res) {
WebClient webClient = oidcConfig.appWebClient();
FormParams.Builder form = FormParams.builder().add("grant_type", "authorization_code").add("code", code).add("redirect_uri", redirectUri(req));
WebClientRequestBuilder post = webClient.post().uri(oidcConfig.tokenEndpointUri()).accept(io.helidon.common.http.MediaType.APPLICATION_JSON);
oidcConfig.updateRequest(OidcConfig.RequestType.CODE_TO_TOKEN, post, form);
OidcConfig.postJsonResponse(post, form.build(), json -> processJsonResponse(req, res, json), (status, errorEntity) -> processError(res, status, errorEntity), (t, message) -> processError(res, t, message)).ignoreElement();
}
use of io.helidon.webserver.ServerRequest in project helidon by oracle.
the class StaticContentHandlerTest method mockRequestWithPath.
private ServerRequest mockRequestWithPath(String path) {
ServerRequest.Path p = mock(ServerRequest.Path.class);
Mockito.doReturn(path).when(p).toString();
ServerRequest request = mock(ServerRequest.class);
Mockito.doReturn(p).when(request).path();
return request;
}
Aggregations