org.slf4j.api,
org.jvnet.mimepull;bundle-version="1.9.6",
org.glassfish.jersey.core.jersey-client,
- org.glassfish.jersey.core.jersey-common;bundle-version="2.25.1"
+ org.glassfish.jersey.core.jersey-common;bundle-version="2.25.1",
+ org.simantics.scl.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
@Private
@JavaName readEntity
readEntity_ :: Response -> Class a -> <Proc, Exception> a
+ @JavaName getHeaderString
+ possibleHeaderOf :: Response -> String -> <Proc> Maybe String
readEntity :: VecComp a => Response -> <Proc, Exception> a
readEntity response = readEntity_ response classObject
clientBuilder :: <Proc> ClientBuilder
importJava "org.simantics.scl.rest.HttpClientUtils" where
- buildClient :: ClientBuilder -> Client
+ buildClient :: ClientBuilder -> <Proc> Client
statusMessageOf :: Response -> <Proc> String
asyncInvoke :: Invocation -> ResponseHandler -> FailureHandler -> <Proc> Future Response
trustAllClientBuilder :: <Proc> ClientBuilder
+ onReadProgress :: WebTarget -> (Long -> <Proc> ()) -> <Proc> ()
+ onWriteProgress :: WebTarget -> (Long -> <Proc> ()) -> <Proc> ()
+ possibleContentLengthOf :: Response -> <Proc> Maybe Long
importJava "javax.ws.rs.client.Entity" where
data Entity
webTarget = target httpClient uri
builder = request webTarget
acceptMediaType builder [WILDCARD_TYPE]
- mp = formDataMultiPart
invocation = buildPost builder $ entity f APPLICATION_OCTET_STREAM_TYPE
response = syncInvoke invocation
print $ statusCodeOf response
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;
}
});
}
+
+ 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;
+ }
+ }
+
}
--- /dev/null
+package org.simantics.scl.rest;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple0;
+
+public class ReadProgressInterceptor implements ReaderInterceptor {
+
+ private Function1<Long, Tuple0> callback;
+
+ public ReadProgressInterceptor(Function1<Long, Tuple0> callback) {
+ this.callback = callback;
+ }
+
+ @Override
+ public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
+
+ final InputStream is = context.getInputStream();
+
+ context.setInputStream(new FilterInputStream(is) {
+
+ private long count;
+
+ @Override
+ public int read(byte b[], int off, int len) throws IOException {
+ int read = in.read(b, off, len);
+ if (read > 0) {
+ count += read;
+ callback.apply(count);
+ }
+ return read;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int read = in.read();
+ if (read > 0) {
+ count++;
+ callback.apply(count);
+ }
+ return read;
+ }
+ });
+
+ return context.proceed();
+ }
+
+}
--- /dev/null
+package org.simantics.scl.rest;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple0;
+
+public class WriteProgressInterceptor implements WriterInterceptor {
+
+ private Function1<Long, Tuple0> callback;
+
+ public WriteProgressInterceptor(Function1<Long, Tuple0> callback) {
+ this.callback = callback;
+ }
+
+ @Override
+ public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
+
+ final OutputStream os = context.getOutputStream();
+
+ context.setOutputStream(new FilterOutputStream(os) {
+ private long count;
+
+ @Override public void write(byte[] b, int off, int len) throws IOException {
+ out.write(b, off, len);
+ count += len;
+ callback.apply(count);
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ out.write(b);
+ count++;
+ callback.apply(count);
+ }
+ });
+
+ context.proceed();
+ }
+
+}