Skip to content

Commit

Permalink
LRA replace reactive webclient with nima helidon-io#7055
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkec committed Jun 27, 2023
1 parent 6da19c2 commit 57051db
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 315 deletions.
8 changes: 4 additions & 4 deletions lra/coordinator/client/narayana-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webclient</groupId>
<artifactId>helidon-reactive-webclient</artifactId>
<groupId>io.helidon.nima.webclient</groupId>
<artifactId>helidon-nima-webclient</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.fault-tolerance</groupId>
<artifactId>helidon-reactive-fault-tolerance</artifactId>
<groupId>io.helidon.nima.fault-tolerance</groupId>
<artifactId>helidon-nima-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.config</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.lra.coordinator.client.narayana;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import io.helidon.common.GenericType;
import io.helidon.common.http.Headers;
import io.helidon.common.http.HttpMediaType;
import io.helidon.nima.http.media.EntityReader;
import io.helidon.nima.http.media.MediaSupport;

import org.eclipse.microprofile.lra.annotation.LRAStatus;

class LraStatusSupport implements MediaSupport {

private static final GenericType<LRAStatus> LRA_STATUS_TYPE = GenericType.create(LRAStatus.class);
private final EntityReader reader = new LRAStatusReader();

@Override
public <T> ReaderResponse<T> reader(GenericType<T> type, Headers headers) {
if (type.equals(LRA_STATUS_TYPE)) {
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
}
return ReaderResponse.unsupported();
}

@Override
public <T> ReaderResponse<T> reader(GenericType<T> type, Headers requestHeaders, Headers responseHeaders) {
if (type.equals(LRA_STATUS_TYPE)) {
return new ReaderResponse<>(SupportLevel.SUPPORTED, this::reader);
}
return ReaderResponse.unsupported();
}

private <T> EntityReader<T> reader(){
return reader;
}

private static class LRAStatusReader implements EntityReader<LRAStatus> {
@Override
public LRAStatus read(GenericType<LRAStatus> type, InputStream stream, Headers headers) {
return read(stream, headers.contentType());
}

@Override
public LRAStatus read(GenericType<LRAStatus> type, InputStream stream, Headers requestHeaders, Headers responseHeaders) {
return read(stream, responseHeaders.contentType());
}

private LRAStatus read(InputStream stream, Optional<HttpMediaType> contentType) {
Charset charset = contentType
.flatMap(HttpMediaType::charset)
.map(Charset::forName)
.orElse(StandardCharsets.UTF_8);
try (stream) {
String stringStatus = new String(stream.readAllBytes(), charset);
return LRAStatus.valueOf(stringStatus);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
}
Loading

0 comments on commit 57051db

Please sign in to comment.