web client throw error on failed
This commit is contained in:
parent
ccf3fa3111
commit
3e155de0d4
|
@ -9,6 +9,7 @@ import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
|
||||||
public class TransformerRepository implements FileTransformerClient {
|
public class TransformerRepository implements FileTransformerClient {
|
||||||
|
@ -21,27 +22,32 @@ public class TransformerRepository implements FileTransformerClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) {
|
public FileEnvelopeModel exportDmp(DmpModel dmpModel, String format) {
|
||||||
return transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(FileEnvelopeModel.class)).block();
|
return transformerClient.post().uri("/export/dmp", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(dmpModel)
|
||||||
|
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DmpModel importDmp(FileEnvelopeModel fileEnvelope) {
|
public DmpModel importDmp(FileEnvelopeModel fileEnvelope) {
|
||||||
return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(DmpModel.class)).block();
|
return transformerClient.post().uri("/import/dmp").bodyValue(fileEnvelope)
|
||||||
|
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DmpModel.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileEnvelopeModel exportDescription(DescriptionModel descriptionModel, String format) {
|
public FileEnvelopeModel exportDescription(DescriptionModel descriptionModel, String format) {
|
||||||
return transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionModel).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(FileEnvelopeModel.class)).block();
|
return transformerClient.post().uri("/export/description", uriBuilder -> uriBuilder.queryParam("format", format).build()).bodyValue(descriptionModel)
|
||||||
|
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(FileEnvelopeModel.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DescriptionModel importDescription(FileEnvelopeModel fileEnvelope) {
|
public DescriptionModel importDescription(FileEnvelopeModel fileEnvelope) {
|
||||||
return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(DescriptionModel.class)).block();
|
return transformerClient.post().uri("/import/description").bodyValue(fileEnvelope)
|
||||||
|
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(DescriptionModel.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileTransformerConfiguration getConfiguration() {
|
public FileTransformerConfiguration getConfiguration() {
|
||||||
return transformerClient.get().uri("/formats").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<FileTransformerConfiguration>() {})).block();
|
return transformerClient.get().uri("/formats")
|
||||||
|
.exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(new ParameterizedTypeReference<FileTransformerConfiguration>() {})).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package eu.eudat.service.deposit;
|
package eu.eudat.service.deposit;
|
||||||
|
|
||||||
|
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||||
import eu.eudat.depositinterface.repository.DepositClient;
|
import eu.eudat.depositinterface.repository.DepositClient;
|
||||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||||
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatusCode;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public class DepositClientImpl implements DepositClient {
|
public class DepositClientImpl implements DepositClient {
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DepositClientImpl.class));
|
||||||
|
|
||||||
private final WebClient depositClient;
|
private final WebClient depositClient;
|
||||||
|
|
||||||
|
@ -19,21 +26,21 @@ public class DepositClientImpl implements DepositClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deposit(DmpModel dmpDepositModel, String repositoryAccessToken) throws Exception {
|
public String deposit(DmpModel dmpDepositModel, String repositoryAccessToken) throws Exception {
|
||||||
return depositClient.post().uri("", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
|
return depositClient.post().uri("", uriBuilder -> uriBuilder.queryParam("authToken", repositoryAccessToken).build()).bodyValue(dmpDepositModel).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String authenticate(String code) {
|
public String authenticate(String code) {
|
||||||
return depositClient.get().uri("/authenticate/", uriBuilder -> uriBuilder.queryParam("authToken", code).build()).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
|
return depositClient.get().uri("/authenticate/", uriBuilder -> uriBuilder.queryParam("authToken", code).build()).exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DepositConfiguration getConfiguration() {
|
public DepositConfiguration getConfiguration() {
|
||||||
return depositClient.get().uri("/configuration").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON).exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<DepositConfiguration>() {})).block();
|
return depositClient.get().uri("/configuration").exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(new ParameterizedTypeReference<DepositConfiguration>() {})).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLogo() {
|
public String getLogo() {
|
||||||
return depositClient.get().uri("/logo").exchangeToMono(mono -> mono.bodyToMono(String.class)).block();
|
return depositClient.get().uri("/logo").exchangeToMono(mono -> mono.statusCode().isError() ? mono.createException().flatMap(Mono::error) : mono.bodyToMono(String.class)).block();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue