Thanks for checking! At least I know that POST node works in another machine.
The webservice test code is dead simple and it can receive over 4kB data for sure (posted below), and I was able to send large data using KNIME's java snippet (also posted below).
If you can send > 4kB data in your POST node, maybe:
1. I could be misconfiguring the node, or
2. using a different version of KNIME, or
3. There may a difference in which POST request is being sent by POST request node and the Java snippet node.
I'm thinking it's 3. Like you said, I'll check what server is receiving.
=====================================================
Here's the webservice test code in python Flask:
from flask import Flask
@app.route('/testinput', methods=['POST'])
def testinput:
binary_data = request.get_data()
return "inputlen_"+str(len(binary_data))+"_end"
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8000)
=====================================================
Here's KNIME Java snippet code.
- Input
- flowvar "url" is the URL of the web service
- input table is single row with a BLOB column named "body"
- Output
- Single row table with column "abc" which has the output of the webservice
- from this snippet:
-
// system imports
import org.knime.base.node.jsnippet.expression.AbstractJSnippet;
import org.knime.base.node.jsnippet.expression.Abort;
import org.knime.base.node.jsnippet.expression.Cell;
import org.knime.base.node.jsnippet.expression.ColumnException;
import org.knime.base.node.jsnippet.expression.TypeException;
import static org.knime.base.node.jsnippet.expression.Type.*;
import java.util.Date;
import java.util.Calendar;
import org.w3c.dom.Document;
// imports for input and output fields
import java.io.InputStream;
// Your custom imports:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
//import java.io.IOUtils;
// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: "body" */
public InputStream c_body;
// Fields for input flow variables
/** Input flow variable: "url" */
public String v_url;
// Fields for output columns
/** Output column: "abc" */
public String out_abc;
// Your custom variables:
// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
try {
URL url = new URL(v_url);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
List<Byte> cBodArry = new ArrayList<Byte>();
Reader r = new BufferedReader(new InputStreamReader(c_body));
for(int c; (c = r.read()) >= 0;)
cBodArry.add((byte)c);
byte[] postDataBytes = new byte[cBodArry.size()];
int i=0;
for(byte b: cBodArry)
postDataBytes[i++] = b;
InputStreamReader reader = new InputStreamReader(c_body);
conn.setRequestMethod("POST");
conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
out_abc = in.lines().collect(Collectors.joining(""));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// expression end
}
}