1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.client;
20
21 import fr.cnes.httpclient.HttpClient;
22 import java.util.logging.Level;
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.restlet.Client;
26 import org.restlet.Context;
27 import org.restlet.data.Parameter;
28 import org.restlet.data.Protocol;
29 import org.restlet.resource.ClientResource;
30 import org.restlet.util.Series;
31
32
33
34
35
36
37 public class BaseClient {
38
39
40
41
42 public static final int DATACITE_MOCKSERVER_PORT = 1080;
43
44
45
46
47 private static final Logger LOG = LogManager.getLogger(BaseClient.class.getName());
48
49
50
51
52 private static final int NB_RETRY = 10;
53
54
55
56
57 private static final int NB_DELAY = 1000;
58
59
60
61
62 private volatile ClientResource client;
63
64
65
66
67
68
69 public BaseClient(final String uri) {
70 this.client = new ClientResource(uri);
71 this.client.getLogger().setLevel(Level.OFF);
72 this.client.setLoggable(false);
73 this.client.setRetryOnError(true);
74 this.client.setRetryAttempts(NB_RETRY);
75 this.client.setRetryDelay(NB_DELAY);
76 final Client configureClient = new Client(new Context(), Protocol.HTTPS);
77 final Series<Parameter> parameters = configureClient.getContext().getParameters();
78 parameters.add(HttpClient.MAX_RETRY, String.valueOf(this.client.getRetryAttempts()));
79 parameters.add(HttpClient.RETRY_DELAY, String.valueOf(this.client.getRetryDelay()));
80 this.client.setNext(configureClient);
81 }
82
83
84
85
86
87
88 public final ClientResource getClient() {
89 return client;
90 }
91
92
93
94
95
96
97 public Logger getLog() {
98 return LOG;
99 }
100
101 }