Browse Source

content-type setable
add examples

Martin Kunz 5 years ago
parent
commit
68612b8044

+ 2 - 1
src/main/java/com/acdp/transceivr/LoadTools.java

@@ -62,7 +62,7 @@ public class LoadTools {
         RequestBody requestBody = new RequestBody() {
             @Override
             public MediaType contentType() {
-                return MEDIA_TYPE_BINARY;
+                return MediaType.get(t.toMime);
             }
 
             @Override
@@ -77,6 +77,7 @@ public class LoadTools {
             requestBuilder.put(requestBody);
         else
             requestBuilder.post(requestBody);
+        requestBuilder.header("Content-Type", t.toMime);
 
         var request=requestBuilder.build();
         client.newCall(request).enqueue(

+ 2 - 2
src/main/java/com/acdp/transceivr/Transfer.java

@@ -31,6 +31,7 @@ public class Transfer {
     public long finishedAT;
     public String toMethod;
     public String body;
+    public String toMime;
     int id;
     public Transfer(int id) {
         this.id = id;
@@ -59,8 +60,7 @@ public class Transfer {
         js.add("finished", finished);
         js.add("finishedAT", finishedAT);
         js.add("toMethod", toMethod);
-
-
+        js.add("toMime", toMime);
         var diff = currentTS - startTS;
         js.add("rate", diff > 0 ? (bytesRead / diff) : 0);
         return js;

+ 2 - 0
src/main/java/com/acdp/transceivr/WebServer.java

@@ -52,6 +52,7 @@ public class WebServer {
             var ba = new byte[BS];
             while (is.read(ba) != -1) ;
             res.status(200);
+            logger.info("Source: {}, Content-Type: {}", req.host(), req.headers("Content-Type"));
             return "";
         });
         put("/null", (req, res) -> {
@@ -110,6 +111,7 @@ public class WebServer {
             t.cpeeCallback = req.headers("CPEE-CALLBACK");
             t.cpeeCallbackId = req.headers("CPEE-CALLBACK-ID");
             t.cpeeInstanceURL = req.headers("CPEE-INSTANCE-URL");
+            t.toMime = req.queryParamOrDefault("toMime", "application/octet-stream");
             if (Boolean.valueOf(req.queryParams("callback"))) {
                 res.header("CPEE-CALLBACK", "true");
                 t.doCpeeCallback = true;

+ 23 - 1
src/main/resources/webroot/index.html

@@ -31,9 +31,15 @@
         <option value="POST">POST</option>
         <option value="PUT">PUT</option>
     </select>
+    <select v-model="toMime">
+        <option value="application/json">application/json</option>
+        <option value="text/plain">text/plain</option>
+        <option value="application/octet-stream">application/octet-stream</option>
+    </select>
     <button @click="send">Send</button>
     <a href="#" @click="example1">example1</a>
     <a href="#" @click="example2">example2</a>
+    <a href="#" @click="example3">example3</a>
     <table>
         <template v-for="(item, index) in transfers">
             <tr>
@@ -87,7 +93,9 @@ cpeeCallbackError: {{ item.cpeeCallbackError}}
             from: '',
             to: '',
             toMethod: 'POST',
-            type: 'xfer'
+            toMime: 'application/octet-stream',
+            type: 'xfer',
+            body: ''
         },
         created: function () {
             setInterval(this.update, 330);
@@ -97,10 +105,23 @@ cpeeCallbackError: {{ item.cpeeCallbackError}}
             example1: function () {
                 this.$data.from='http://localhost:8082/zero?length=1000000';
                 this.$data.to='http://localhost:8082/null';
+                this.$data.type='xfer';
+                this.$data.toMethod='POST';
+                this.$data.toMime='application/octet-stream';
             },
             example2: function () {
                 this.$data.from='http://ftp.debian.org/debian/ls-lR.gz';
                 this.$data.to='http://localhost:8082/null';
+                this.$data.type='xfer';
+                this.$data.toMethod='POST';
+                this.$data.toMime='application/octet-stream';
+            },
+            example3: function () {
+                this.$data.body='[{}]';
+                this.$data.to='http://localhost:8082/null';
+                this.$data.toMethod='POST';
+                this.$data.type='send';
+                this.$data.toMime='application/json';
             },
             send: function (ts) {
                 let data = new URLSearchParams();
@@ -108,6 +129,7 @@ cpeeCallbackError: {{ item.cpeeCallbackError}}
                 data.append('to', this.to);
                 data.append('toMethod', this.toMethod);
                 data.append('body', this.body);
+                data.append('toMime', this.toMime);
                 ep=this.$data.type;
                 fetch('/' + ep, {
                     method: "POST",