X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fserver%2Fclient%2Fimpl%2FAbstractHttpServicesClient.java;h=a7936916ef110b99d8ba84a4e8f53134fbfe4770;hb=171d606f8c2ba89c9bdc518f39aa88662c4d942a;hp=410e8d9afe029d119425a8f0d565bf35750a1013;hpb=986352111d5b552eeb478547df58928b9351025f;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java index 410e8d9af..a7936916e 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/client/impl/AbstractHttpServicesClient.java @@ -8,7 +8,6 @@ import java.io.Writer; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; -import java.util.Iterator; import java.util.Map; import javax.xml.transform.Source; @@ -54,14 +53,11 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { @SuppressWarnings(value = { "unchecked" }) public T callServiceSafe(String path, Map parameters, Condition condition, Long timeout) { - if (timeout == null) - timeout = defaultTimeout; long begin = System.currentTimeMillis(); try { Object obj = null; - long duration = System.currentTimeMillis() - begin; - while (duration < timeout) { + while (System.currentTimeMillis() - begin < timeout(timeout)) { try { obj = callServiceLowLevel(path, parameters, null); } catch (IOException e) { @@ -93,7 +89,7 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { + " on " + baseUrl + " did not return an answer after calling it safely for " - + duration + " ms."); + + timeout(timeout) + " ms."); return (T) obj; } catch (Exception e) { throw new SlcException( @@ -157,16 +153,19 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { try { if (parameters != null && parameters.size() != 0) { buf.append('?'); - Iterator it = parameters.keySet().iterator(); - String key = null; - while (it.hasNext()) { - if (key != null) - buf.append('&'); - key = it.next(); - String keyEncoded = URLEncoder.encode(key, urlEncoding); - String valueEncoded = URLEncoder.encode( - parameters.get(key), urlEncoding); - buf.append(keyEncoded).append('=').append(valueEncoded); + boolean first = true; + for (String key : parameters.keySet()) { + String value = parameters.get(key); + if (value != null) { + if (first) + first = false; + else + buf.append('&'); + String keyEncoded = URLEncoder.encode(key, urlEncoding); + String valueEncoded = URLEncoder.encode(value, + urlEncoding); + buf.append(keyEncoded).append('=').append(valueEncoded); + } } } @@ -176,6 +175,12 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { } } + public Long timeout(Long timeout) { + if (timeout == null) + timeout = getDefaultTimeout(); + return timeout; + } + public void setUnmarshaller(Unmarshaller unmarshaller) { this.unmarshaller = unmarshaller; } @@ -202,9 +207,13 @@ public abstract class AbstractHttpServicesClient implements HttpServicesClient { this.encoding = encoding; } - /** Default is 30s*/ + /** Default is 30s */ public void setDefaultTimeout(Long defaultTimeout) { this.defaultTimeout = defaultTimeout; } + public Long getDefaultTimeout() { + return defaultTimeout; + } + }