use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class TranslatorFrontendService method getText.
private void getText(ServerRequest request, ServerResponse response) {
try {
String query = request.queryParams().first("q").orElseThrow(() -> new BadRequestException("missing query parameter 'q'"));
String language = request.queryParams().first("lang").orElseThrow(() -> new BadRequestException("missing query parameter 'lang'"));
try (Response backendResponse = backendTarget.property(ClientTracingFilter.TRACER_PROPERTY_NAME, request.tracer()).property(ClientTracingFilter.CURRENT_SPAN_CONTEXT_PROPERTY_NAME, request.spanContext().orElse(null)).queryParam("q", query).queryParam("lang", language).request().get()) {
final String result;
if (backendResponse.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
result = backendResponse.readEntity(String.class);
} else {
result = "Error: " + backendResponse.readEntity(String.class);
}
response.send(result + "\n");
}
} catch (ProcessingException pe) {
LOGGER.log(Level.WARNING, "Problem to call translator frontend.", pe);
response.status(503).send("Translator backend service isn't available.");
}
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class OutboundOverrideExample method propagate.
private static void propagate(ServerRequest req, ServerResponse res) {
SecurityContext context = getSecurityContext(req);
webTarget(servingPort).request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result + "\n")).exceptionally(throwable -> sendError(throwable, res));
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class OutboundOverrideJwtExample method propagate.
private static void propagate(ServerRequest req, ServerResponse res) {
SecurityContext context = getSecurityContext(req);
webTarget(servingPort).request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result)).exceptionally(throwable -> sendError(throwable, res));
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class OutboundOverrideJwtExample method override.
private static void override(ServerRequest req, ServerResponse res) {
SecurityContext context = getSecurityContext(req);
webTarget(servingPort).property(JwtProvider.EP_PROPERTY_OUTBOUND_USER, "jill").request(String.class).thenAccept(result -> res.send("You are: " + context.userName() + ", backend service returned: " + result)).exceptionally(throwable -> sendError(throwable, res));
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class ObjectStorageService method upload.
private void upload(ServerRequest req, ServerResponse res) {
OptionalLong contentLength = req.headers().contentLength();
if (contentLength.isEmpty()) {
req.content().forEach(DataChunk::release);
res.status(Http.Status.BAD_REQUEST_400).send("Content length must be defined");
return;
}
String objectName = req.path().param("file-name");
PutObject.Request request = PutObject.Request.builder().objectName(objectName).bucket(bucketName).contentLength(contentLength.getAsLong());
req.headers().contentType().ifPresent(request::requestMediaType);
objectStorage.putObject(request, req.content()).forSingle(response -> res.send(response.requestId())).exceptionally(res::send);
}
Aggregations