use of io.helidon.common.http.FormParams in project helidon by oracle.
the class FormParamsBodyReader method create.
private FormParams create(String paramAssignments, MediaType mediaType, Function<String, String> decoder) {
FormParams.Builder builder = FormParams.builder();
Matcher m = PATTERNS.get(mediaType).matcher(paramAssignments);
while (m.find()) {
final String key = m.group(1);
final String value = m.group(2);
if (value == null) {
builder.add(decoder.apply(key));
} else {
builder.add(decoder.apply(key), decoder.apply(value));
}
}
return builder.build();
}
use of io.helidon.common.http.FormParams in project helidon by oracle.
the class FormParamsBodyReader method read.
@Override
@SuppressWarnings("unchecked")
public <U extends FormParams> Single<U> read(Flow.Publisher<DataChunk> publisher, GenericType<U> type, MessageBodyReaderContext context) {
MediaType mediaType = context.contentType().orElseThrow();
Charset charset = mediaType.charset().map(Charset::forName).orElse(StandardCharsets.UTF_8);
Function<String, String> decoder = decoder(mediaType, charset);
return (Single<U>) ContentReaders.readString(publisher, charset).map(formStr -> create(formStr, mediaType, decoder));
}
use of io.helidon.common.http.FormParams in project helidon by oracle.
the class IdcsSupport method signJwk.
// load signature jwk with a token, blocking operation
static JwkKeys signJwk(WebClient appWebClient, WebClient generalClient, URI tokenEndpointUri, URI signJwkUri, Duration clientTimeout) {
// need to get token to be able to request this endpoint
FormParams form = FormParams.builder().add("grant_type", "client_credentials").add("scope", "urn:opc:idm:__myscopes__").build();
try {
WebClientResponse response = appWebClient.post().uri(tokenEndpointUri).accept(MediaType.APPLICATION_JSON).submit(form).await(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
if (response.status().family() == Http.ResponseStatus.Family.SUCCESSFUL) {
JsonObject json = response.content().as(JsonObject.class).await(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
String accessToken = json.getString("access_token");
// get the jwk from server
JsonObject jwkJson = generalClient.get().uri(signJwkUri).headers(it -> {
it.add(Http.Header.AUTHORIZATION, "Bearer " + accessToken);
return it;
}).request(JsonObject.class).await(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
return JwkKeys.create(jwkJson);
} else {
String errorEntity = response.content().as(String.class).await(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
throw new SecurityException("Failed to read JWK from IDCS. Status: " + response.status() + ", entity: " + errorEntity);
}
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
throw new SecurityException("Failed to read JWK from IDCS", e);
}
}
use of io.helidon.common.http.FormParams in project helidon by oracle.
the class FormTest method testFormContent.
@Test
public void testFormContent() {
FormParams received = webClient.post().path("/form/content").submit(ADVANCED_TEST_FORM, FormParams.class).await();
assertThat(received.all(SPECIAL), is(ADVANCED_TEST_FORM.all(SPECIAL)));
assertThat(received.all(MULTIPLE), is(ADVANCED_TEST_FORM.all(MULTIPLE)));
assertThat(received.all(NO_VALUE).size(), is(0));
}
Aggregations