Revision 52757
Added by Miriam Baglioni almost 6 years ago
modules/dnet-modular-uis/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/oai/OaiExplorerInternalController.java | ||
---|---|---|
18 | 18 |
import org.apache.commons.logging.Log; |
19 | 19 |
import org.apache.commons.logging.LogFactory; |
20 | 20 |
import org.apache.http.HttpStatus; |
21 |
import org.apache.http.client.config.RequestConfig; |
|
21 | 22 |
import org.apache.http.client.methods.CloseableHttpResponse; |
22 | 23 |
import org.apache.http.client.methods.HttpGet; |
23 | 24 |
import org.apache.http.client.utils.URIBuilder; |
24 | 25 |
import org.apache.http.impl.client.CloseableHttpClient; |
26 |
import org.apache.http.impl.client.HttpClientBuilder; |
|
25 | 27 |
import org.apache.http.impl.client.HttpClients; |
26 | 28 |
import org.apache.http.message.BasicHeader; |
27 | 29 |
import org.dom4j.Document; |
... | ... | |
113 | 115 |
return response; |
114 | 116 |
} |
115 | 117 |
|
118 |
private CloseableHttpResponse initClient(final OaiRequest req) throws Exception{ |
|
119 |
final RequestConfig requestConfig = RequestConfig.custom() |
|
120 |
.setConnectTimeout(360000) |
|
121 |
.setConnectionRequestTimeout(360000) |
|
122 |
.setSocketTimeout(360000) |
|
123 |
.build(); |
|
124 |
|
|
125 |
HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultRequestConfig(requestConfig); |
|
126 |
|
|
127 |
final CloseableHttpClient httpClient = httpClientBuilder.build(); |
|
128 |
|
|
129 |
final URIBuilder builder = new URIBuilder(req.getBaseUrl()); |
|
130 |
builder.addParameters(Lists.newArrayList(req.toQueryParams())); |
|
131 |
final HttpGet method = new HttpGet(builder.build()); |
|
132 |
method.setHeader(new BasicHeader("Content-type", "text/xml; charset=UTF-8")); |
|
133 |
|
|
134 |
final CloseableHttpResponse response = httpClient.execute(method); |
|
135 |
|
|
136 |
|
|
137 |
return response; |
|
138 |
} |
|
139 |
|
|
116 | 140 |
private InputStream callOaiVerb(final OaiRequest req) throws Exception { |
141 |
try { |
|
117 | 142 |
|
118 |
try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
119 |
final URIBuilder builder = new URIBuilder(req.getBaseUrl()); |
|
120 |
builder.addParameters(Lists.newArrayList(req.toQueryParams())); |
|
121 |
final HttpGet method = new HttpGet(builder.build()); |
|
122 | 143 |
|
123 |
method.setHeader(new BasicHeader("Content-type", "text/xml; charset=UTF-8")); |
|
124 |
|
|
125 |
try (final CloseableHttpResponse response = httpClient.execute(method)) { |
|
144 |
final CloseableHttpResponse response =initClient(req); |
|
126 | 145 |
int statusCode = response.getStatusLine().getStatusCode(); |
127 | 146 |
|
128 | 147 |
if (HttpStatus.SC_OK != statusCode) { |
... | ... | |
130 | 149 |
} |
131 | 150 |
|
132 | 151 |
return new BufferedInputStream(response.getEntity().getContent()); |
133 |
} |
|
152 |
|
|
134 | 153 |
} catch (IOException e) { |
135 | 154 |
throw new CollectorServiceException("Error requesting url: " + req.getBaseUrl()); |
136 | 155 |
} |
... | ... | |
140 | 159 |
private Document callOaiVerb(final OaiRequest req, final ResponseDetails details) { |
141 | 160 |
final long start = DateUtils.now(); |
142 | 161 |
Document doc = null; |
143 |
try (final CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
144 |
final URIBuilder builder = new URIBuilder(req.getBaseUrl()); |
|
145 |
builder.addParameters(Lists.newArrayList(req.toQueryParams())); |
|
146 |
final HttpGet method = new HttpGet(builder.build()); |
|
147 | 162 |
|
148 |
method.setHeader(new BasicHeader("Content-type", "text/xml; charset=UTF-8")); |
|
149 |
try (final CloseableHttpResponse response = httpClient.execute(method)) { |
|
163 |
try { |
|
164 |
|
|
165 |
final CloseableHttpResponse response = initClient(req); |
|
150 | 166 |
int statusCode = response.getStatusLine().getStatusCode(); |
151 | 167 |
|
152 | 168 |
if (HttpStatus.SC_OK != statusCode) { |
... | ... | |
156 | 172 |
details.setValid(HttpStatus.SC_OK == statusCode); |
157 | 173 |
|
158 | 174 |
doc = new SAXReader().read(response.getEntity().getContent()); |
159 |
} |
|
175 |
|
|
160 | 176 |
} catch (Exception e) { |
161 | 177 |
details.setValid(false); |
162 | 178 |
details.setError(e.getMessage()); |
Also available in: Unified diff
fixing for java.net.SocketException: Socket closed error