use of io.helidon.media.common.MessageBodyReadableContent in project helidon by oracle.
the class MultiPartDecoder method createPart.
private ReadableBodyPart createPart() {
ReadableBodyPartHeaders headers = bodyPartHeaderBuilder.build();
// create a reader context for the part
MessageBodyReaderContext partContext = MessageBodyReaderContext.create(context, /* eventListener */
null, headers, Optional.of(headers.contentType()));
// create a readable content for the part
MessageBodyReadableContent partContent = MessageBodyReadableContent.create(bodyPartPublisher, partContext);
return bodyPartBuilder.headers(headers).content(partContent).build();
}
use of io.helidon.media.common.MessageBodyReadableContent in project helidon by oracle.
the class TestClient method callServiceAndGetString.
/**
* Call remote service method and return its raw data as JSON object.
* No response content check is done. No query parameters are passed.
*
* @param service remote service name
* @param method remote test method name
* @return data returned by remote service
*/
public String callServiceAndGetString(final String service, final String method) {
WebClientRequestBuilder rb = clientGetBuilderWithPath(service, method);
final MessageBodyReadableContent content = rb.submit().await(1, TimeUnit.MINUTES).content();
return content.as(String.class).await(1, TimeUnit.MINUTES);
}
use of io.helidon.media.common.MessageBodyReadableContent in project helidon by oracle.
the class HealthServerTest method checkResponse.
private static void checkResponse(Supplier<WebClientRequestBuilder> requestFactory, String requestPath, boolean expectContent) {
WebClientResponse response = null;
try {
response = requestFactory.get().path(requestPath).accept(MediaType.APPLICATION_JSON).request().await();
int expectedStatus = expectContent ? Http.Status.OK_200.code() : Http.Status.NO_CONTENT_204.code();
assertThat("health response status", response.status().code(), is(expectedStatus));
MessageBodyReadableContent content = response.content();
String textContent = null;
try {
textContent = content.as(String.class).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
assertThat("content length", textContent.length(), expectContent ? greaterThan(0) : equalTo(0));
if (expectContent) {
JsonObject health = Json.createReader(new StringReader(textContent)).readObject();
assertThat("health status", health.getString("status"), is("UP"));
}
} finally {
if (response != null) {
response.close();
}
}
}
use of io.helidon.media.common.MessageBodyReadableContent in project helidon by oracle.
the class TestClient method callService.
JsonObject callService(WebClientRequestBuilder rb, Map<String, String> params) {
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
rb = rb.queryParam(entry.getKey(), encode(entry.getValue()));
}
}
final MessageBodyReadableContent content = rb.submit().await(1, TimeUnit.MINUTES).content();
final String response = content.as(String.class).await(1, TimeUnit.MINUTES);
try {
final JsonReader jsonReader = Json.createReader(new StringReader(response));
final JsonValue jsonContent = jsonReader.read();
switch(jsonContent.getValueType()) {
case OBJECT:
return jsonContent.asJsonObject();
default:
throw new HelidonTestException(String.format("Expected JSON object, but got JSON %s", jsonContent.getValueType().name().toLowerCase()));
}
} catch (JsonException t) {
LOGGER.log(Level.WARNING, t, () -> String.format("Caught %s when parsing response: %s", t.getClass().getSimpleName(), response));
throw new HelidonTestException(String.format("Caught %s when parsing response: %s", t.getClass().getSimpleName(), response), t);
}
}
use of io.helidon.media.common.MessageBodyReadableContent in project helidon by oracle.
the class TestServiceClient method callServiceAndGetString.
/**
* Call remote service method and return its raw data as JSON object.
* No response content check is done. No query parameters are passed.
*
* @param method remote test method name
* @return data returned by remote service
*/
public String callServiceAndGetString(final String method) {
WebClientRequestBuilder rb = clientGetBuilderWithPath(service, method);
final MessageBodyReadableContent content = rb.submit().await(1, TimeUnit.MINUTES).content();
return content.as(String.class).await(1, TimeUnit.MINUTES);
}
Aggregations