Code Review
/
so.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
split single and plural graph inventory uris
[so.git]
/
common
/
src
/
main
/
java
/
org
/
onap
/
so
/
client
/
RestClient.java
diff --git
a/common/src/main/java/org/onap/so/client/RestClient.java
b/common/src/main/java/org/onap/so/client/RestClient.java
index
0b3aa65
..
077ba24
100644
(file)
--- a/
common/src/main/java/org/onap/so/client/RestClient.java
+++ b/
common/src/main/java/org/onap/so/client/RestClient.java
@@
-26,6
+26,7
@@
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.net.URI;
import java.net.URL;
import java.security.GeneralSecurityException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
@@
-33,7
+34,6
@@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
-import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import java.util.function.Predicate;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@
-44,11
+44,12
@@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
+import org.onap.logging.filter.base.MDCSetup;
+import org.onap.logging.filter.base.ONAPComponentsList;
+import org.onap.logging.filter.base.PayloadLoggingClientFilter;
import org.onap.so.client.policy.CommonObjectMapperProvider;
import org.onap.so.client.policy.CommonObjectMapperProvider;
-import org.onap.so.logging.jaxrs.filter.JaxRsClientLogging;
-import org.onap.so.logging.jaxrs.filter.PayloadLoggingFilter;
+import org.onap.so.logging.jaxrs.filter.SOMetricLogClientFilter;
import org.onap.so.utils.CryptoUtils;
import org.onap.so.utils.CryptoUtils;
-import org.onap.so.utils.TargetEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
@@
-71,7
+72,8
@@
public abstract class RestClient {
protected String accept;
protected String contentType;
protected String requestId = "";
protected String accept;
protected String contentType;
protected String requestId = "";
- protected JaxRsClientLogging jaxRsClientLogging;
+ protected SOMetricLogClientFilter metricLogClientFilter;
+ protected MDCSetup mdcSetup = new MDCSetup();
protected RestProperties props;
protected RestClient(RestProperties props, Optional<URI> path) {
protected RestProperties props;
protected RestClient(RestProperties props, Optional<URI> path) {
@@
-179,18
+181,18
@@
public abstract class RestClient {
return ClientBuilder.newBuilder().build();
}
return ClientBuilder.newBuilder().build();
}
- protected abstract
TargetEntity
getTargetEntity();
+ protected abstract
ONAPComponentsList
getTargetEntity();
protected void initializeClient(Client client) {
if (this.enableLogging()) {
protected void initializeClient(Client client) {
if (this.enableLogging()) {
- client.register(new PayloadLoggingFilter(this.getMaxPayloadSize()));
+ client.register(new PayloadLogging
Client
Filter(this.getMaxPayloadSize()));
}
CommonObjectMapperProvider provider = this.getCommonObjectMapperProvider();
client.register(new JacksonJsonProvider(provider.getMapper()));
}
CommonObjectMapperProvider provider = this.getCommonObjectMapperProvider();
client.register(new JacksonJsonProvider(provider.getMapper()));
-
jaxRsClientLogging = new JaxRsClientLogging
();
-
jaxRsClientLogging.setTargetService
(getTargetEntity());
- client.register(
jaxRsClientLogging
);
+
metricLogClientFilter = new SOMetricLogClientFilter
();
+
mdcSetup.setTargetEntity
(getTargetEntity());
+ client.register(
metricLogClientFilter
);
if (!path.isPresent()) {
webTarget = client.target(host.toString());
if (!path.isPresent()) {
webTarget = client.target(host.toString());
@@
-275,22
+277,20
@@
public abstract class RestClient {
}
public Response method(String method, Object entity) {
}
public Response method(String method, Object entity) {
- RetryPolicy policy = new RetryPolicy();
List<Predicate<Throwable>> items = retryOn();
Predicate<Throwable> pred = items.stream().reduce(Predicate::or).orElse(x -> false);
List<Predicate<Throwable>> items = retryOn();
Predicate<Throwable> pred = items.stream().reduce(Predicate::or).orElse(x -> false);
- policy.retryOn(error -> pred.test(error));
+ RetryPolicy<Object> policy =
+ new RetryPolicy<>().handleIf(pred).withDelay(Duration.ofMillis(this.props.getDelayBetweenRetries()))
+ .withMaxRetries(this.props.getRetries());
- policy.withDelay(this.props.getDelayBetweenRetries(), TimeUnit.MILLISECONDS)
- .withMaxRetries(this.props.getRetries());
-
- return Failsafe.with(policy).get(buildRequest(method, entity));
+ return Failsafe.with(policy).get(() -> buildRequest(method, entity));
}
}
- protected Res
tRequest buildRequest(String method, Object entity)
{
- return new RestRequest(this, method, entity);
+ protected Res
ponse buildRequest(String method, Object entity) throws Exception
{
+ return new RestRequest(this, method, entity)
.get()
;
}
private <T> Optional<T> format(Response response, Class<T> resultClass) {
}
private <T> Optional<T> format(Response response, Class<T> resultClass) {