X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.rest%2Fsrc%2Forg%2Fsimantics%2Fscl%2Frest%2FHttpClientUtils.java;h=f99b8c47f7e8673755ff1441c19a7695ab2004e8;hp=ef42cc8595c3d9c6c4ba30e4edb8682e50c827f3;hb=fd0240aa431974075a4053c763994310cebcb342;hpb=8daf1d98d61e83fc6450ddac8e800476a9d52ab3 diff --git a/bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/HttpClientUtils.java b/bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/HttpClientUtils.java index ef42cc859..f99b8c47f 100644 --- a/bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/HttpClientUtils.java +++ b/bundles/org.simantics.scl.rest/src/org/simantics/scl/rest/HttpClientUtils.java @@ -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 callback) { + target.register(new WriteProgressInterceptor(callback)); + } + + public static void onReadProgress(WebTarget target, Function1 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; + } + } + }