1
|
package eu.dnetlib.api.client;
|
2
|
|
3
|
import java.net.URI;
|
4
|
import java.net.URISyntaxException;
|
5
|
|
6
|
import javax.xml.transform.Source;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.apache.http.client.utils.URIBuilder;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.web.client.RestTemplate;
|
13
|
|
14
|
public class ApiClientImpl implements ApiClient {
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(ApiClientImpl.class); // NOPMD by marko on 11/24/08 5:02 PM
|
17
|
|
18
|
@Autowired
|
19
|
private RestTemplate restTemplate;
|
20
|
|
21
|
@Override
|
22
|
public String doRequest(final EntityType entityType, final ApiModel apiModel, final URI requestURI) {
|
23
|
log.debug("Request for entity: " + entityType + ", model: " + apiModel + ", URL: " + requestURI.toString());
|
24
|
URIBuilder builder;
|
25
|
try {
|
26
|
builder = new URIBuilder(requestURI);
|
27
|
if (apiModel != ApiModel.none) {
|
28
|
builder.addParameter("model", apiModel.name());
|
29
|
}
|
30
|
return restTemplate.getForObject(builder.build(), String.class);
|
31
|
} catch (URISyntaxException e) {
|
32
|
throw new IllegalArgumentException(e);
|
33
|
}
|
34
|
|
35
|
}
|
36
|
|
37
|
@Override
|
38
|
public Source doRequestAsSource(final EntityType entityType, final ApiModel apiModel, final URI requestURI) {
|
39
|
log.debug("Request for entity: " + entityType + ", model: " + apiModel + ", URL: " + requestURI.toString());
|
40
|
URIBuilder builder;
|
41
|
try {
|
42
|
builder = new URIBuilder(requestURI);
|
43
|
if (apiModel != ApiModel.none) {
|
44
|
builder.addParameter("model", apiModel.name());
|
45
|
}
|
46
|
return restTemplate.getForObject(builder.build(), Source.class);
|
47
|
} catch (URISyntaxException e) {
|
48
|
throw new IllegalArgumentException(e);
|
49
|
}
|
50
|
}
|
51
|
}
|