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;
@SuppressWarnings(value = { "unchecked" })
public <T> T callServiceSafe(String path, Map<String, String> parameters,
Condition<T> 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) {
+ " 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(
try {
if (parameters != null && parameters.size() != 0) {
buf.append('?');
- Iterator<String> 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);
+ }
}
}
}
}
+ public Long timeout(Long timeout) {
+ if (timeout == null)
+ timeout = getDefaultTimeout();
+ return timeout;
+ }
+
public void setUnmarshaller(Unmarshaller unmarshaller) {
this.unmarshaller = unmarshaller;
}
this.encoding = encoding;
}
- /** Default is 30s*/
+ /** Default is 30s */
public void setDefaultTimeout(Long defaultTimeout) {
this.defaultTimeout = defaultTimeout;
}
+ public Long getDefaultTimeout() {
+ return defaultTimeout;
+ }
+
}