]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/HttpClientUtils.java
Improvements to SCL HTTP client
[simantics/platform.git] / bundles / org.simantics.scl.rest / src / org / simantics / scl / rest / HttpClientUtils.java
index ef42cc8595c3d9c6c4ba30e4edb8682e50c827f3..f99b8c47f7e8673755ff1441c19a7695ab2004e8 100644 (file)
@@ -14,6 +14,7 @@ import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.InvocationCallback;
+import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Response;
 
@@ -85,4 +86,26 @@ public class HttpClientUtils {
             }
         });
     }
+    
+    public static void onWriteProgress(WebTarget target, Function1<Long, Tuple0> callback) {
+        target.register(new WriteProgressInterceptor(callback));
+    }
+    
+    public static void onReadProgress(WebTarget target, Function1<Long, Tuple0> callback) {
+        target.register(new ReadProgressInterceptor(callback));
+    }
+    
+    public static Long possibleContentLengthOf(Response response) {
+        String lengthStr = response.getHeaderString("Content-Length");
+        if (lengthStr != null) {
+            try {
+                return Long.parseLong(lengthStr);
+            } catch (NumberFormatException e) {
+                return null;
+            }
+        } else {
+            return null;
+        }
+    }
+
 }