Search in sources :

Example 36 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class VaultService method deleteSecret.

private void deleteSecret(ServerRequest req, ServerResponse res) {
    // has to be for quite a long period of time - did not work with less than 30 days
    Instant deleteTime = Instant.now().plus(30, ChronoUnit.DAYS);
    vault.deleteSecret(DeleteSecret.Request.builder().secretId(req.path().param("id")).timeOfDeletion(deleteTime)).forSingle(it -> res.status(it.status()).send()).exceptionally(res::send);
}
Also used : Encrypt(io.helidon.integrations.oci.vault.Encrypt) OciVaultRx(io.helidon.integrations.oci.vault.OciVaultRx) Instant(java.time.Instant) Sign(io.helidon.integrations.oci.vault.Sign) ServerRequest(io.helidon.webserver.ServerRequest) ChronoUnit(java.time.temporal.ChronoUnit) DeleteSecret(io.helidon.integrations.oci.vault.DeleteSecret) Verify(io.helidon.integrations.oci.vault.Verify) Base64Value(io.helidon.common.Base64Value) Handler(io.helidon.webserver.Handler) ServerResponse(io.helidon.webserver.ServerResponse) Optional(java.util.Optional) Secret(io.helidon.integrations.oci.vault.Secret) GetSecretBundle(io.helidon.integrations.oci.vault.GetSecretBundle) CreateSecret(io.helidon.integrations.oci.vault.CreateSecret) Service(io.helidon.webserver.Service) Http(io.helidon.common.http.Http) Routing(io.helidon.webserver.Routing) Decrypt(io.helidon.integrations.oci.vault.Decrypt) Instant(java.time.Instant)

Example 37 with ServerRequest

use of io.helidon.webserver.ServerRequest in project helidon by oracle.

the class MockZipkinService method mockZipkin.

private void mockZipkin(final ServerRequest request, final ServerResponse response) {
    request.queryParams().all("serviceName").forEach(s -> System.out.println(">>>" + s));
    request.content().registerReader(new MessageBodyStreamReader<JsonValue>() {

        @Override
        public PredicateResult accept(final GenericType<?> type, final MessageBodyReaderContext context) {
            return PredicateResult.COMPATIBLE;
        }

        @Override
        @SuppressWarnings("unchecked")
        public <U extends JsonValue> Flow.Publisher<U> read(final Flow.Publisher<DataChunk> publisher, final GenericType<U> type, final MessageBodyReaderContext context) {
            return (Flow.Publisher<U>) Multi.create(publisher).map(d -> ByteBuffer.wrap(d.bytes())).reduce((buf, buf2) -> ByteBuffer.allocate(buf.capacity() + buf2.capacity()).put(buf.array()).put(buf2.array())).flatMap(b -> {
                try (ByteArrayInputStream bais = new ByteArrayInputStream(b.array());
                    GZIPInputStream gzipInputStream = new GZIPInputStream(bais)) {
                    return Single.just(Json.createReader(new StringReader(new String(gzipInputStream.readAllBytes()))).readArray());
                } catch (EOFException e) {
                    // ignore
                    return Multi.empty();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }).flatMap(a -> Multi.create(a.stream()));
        }
    }).asStream(JsonValue.class).map(JsonValue::asJsonObject).filter(json -> TAGS_POINTER.containsValue(json) && COMPONENT_POINTER.containsValue(json) && filteredComponents.stream().anyMatch(s -> s.equals(((JsonString) COMPONENT_POINTER.getValue(json)).getString()))).onError(Throwable::printStackTrace).onError(t -> response.status(500).send(t)).onComplete(response::send).peek(json -> LOGGER.info(json.toString())).forEach(e -> next.getAndSet(new CompletableFuture<>()).complete(e));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JsonValue(jakarta.json.JsonValue) DataChunk(io.helidon.common.http.DataChunk) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuffer(java.nio.ByteBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) Flow(java.util.concurrent.Flow) MessageBodyStreamReader(io.helidon.media.common.MessageBodyStreamReader) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) Service(io.helidon.webserver.Service) Multi(io.helidon.common.reactive.Multi) JsonPointer(jakarta.json.JsonPointer) Set(java.util.Set) IOException(java.io.IOException) Logger(java.util.logging.Logger) GenericType(io.helidon.common.GenericType) EOFException(java.io.EOFException) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) CompletionStage(java.util.concurrent.CompletionStage) StringReader(java.io.StringReader) Routing(io.helidon.webserver.Routing) JsonString(jakarta.json.JsonString) JsonValue(jakarta.json.JsonValue) JsonString(jakarta.json.JsonString) IOException(java.io.IOException) Flow(java.util.concurrent.Flow) GZIPInputStream(java.util.zip.GZIPInputStream) MessageBodyReaderContext(io.helidon.media.common.MessageBodyReaderContext) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader) EOFException(java.io.EOFException) DataChunk(io.helidon.common.http.DataChunk)

Example 38 with ServerRequest

use of io.helidon.webserver.ServerRequest in project metro-jax-ws by eclipse-ee4j.

the class HelidonAdapter method addSatellites.

@Override
protected void addSatellites(Packet packet) {
    ServerRequest req = (ServerRequest) packet.get(HelidonProperties.REQUEST);
    ServerResponse res = (ServerResponse) packet.get(HelidonProperties.RESPONSE);
    packet.addSatellite(APISupport.createPropertySet(req, res));
}
Also used : ServerResponse(io.helidon.webserver.ServerResponse) ServerRequest(io.helidon.webserver.ServerRequest)

Aggregations

ServerRequest (io.helidon.webserver.ServerRequest)38 ServerResponse (io.helidon.webserver.ServerResponse)35 Routing (io.helidon.webserver.Routing)23 Logger (java.util.logging.Logger)17 JsonObject (jakarta.json.JsonObject)13 Config (io.helidon.config.Config)12 Map (java.util.Map)12 Service (io.helidon.webserver.Service)11 Json (jakarta.json.Json)11 Optional (java.util.Optional)11 Test (org.junit.jupiter.api.Test)11 Single (io.helidon.common.reactive.Single)10 DbClient (io.helidon.dbclient.DbClient)10 SecurityContext (io.helidon.security.SecurityContext)9 Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)9 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)9 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)9 List (java.util.List)9 Http (io.helidon.common.http.Http)8 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8