- if (obj != null)
- break;
-
- // wait a bit
- try {
- Thread.sleep(retryPeriod);
- } catch (InterruptedException e) {
- // silent
- }
- }
-
- if (obj == null)
- throw new SlcException(
- "Service "
- + path
- + " on "
- + baseUrl
- + " did not return an answer after calling it safely for "
- + duration + " ms.");
- return (T) obj;
- } catch (Exception e) {
- throw new SlcException(
- "Unexpected exception when safely calling service " + path
- + " on " + baseUrl, e);
- }
- }
-
- protected Object callServiceLowLevel(String path,
- Map<String, String> parameters) throws IOException {
- Assert.notNull(baseUrl, "base url");
- InputStream in = null;
- try {
- URL url = new URL(baseUrl + path);
- HttpURLConnection connection = (HttpURLConnection) url
- .openConnection();
- if (parameters != null) {
- for (String key : parameters.keySet()) {
- connection.addRequestProperty(key, parameters.get(key));
- }
- }
-
- connection.connect();
-
- in = connection.getInputStream();
- StreamSource source = new StreamSource(in);
- Object obj = unmarshaller.unmarshal(source);
- return obj;
- } finally {
- IOUtils.closeQuietly(in);
- }
- }
-
- public void setUnmarshaller(Unmarshaller unmarshaller) {
- this.unmarshaller = unmarshaller;
- }
-
- public void setBaseUrl(String baseUrl) {
- this.baseUrl = baseUrl;
- }
-
- public Long getRetryPeriod() {
- return retryPeriod;
- }
-
- /** Retry period in ms when accessing service safely. Default is 1000 ms. */
- public void setRetryPeriod(Long retryPeriod) {
- this.retryPeriod = retryPeriod;
- }