1

https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html Reading the documentation, we see that we are able to send a POST request containing assembler .ttl definitions to Fuseki Endpoint. Although, when trying that, my application does not get any answer from server.

I'm trying this code in Java:

/**
     * This Method creates a persistent TDB2 in Fuseki Server by a POST request
     * @param name Name of the DataSet to be Created
     * @throws MalformedURLException 
     * @throws ProtocolException 
     * @throws UnsupportedEncodingException 
     */
    public void createDatasetInFuseki(String name) throws Exception{
        try {
            HttpURLConnection conn = (HttpURLConnection) new URL(server_location + "/$/datasets").openConnection();
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            OutputStream os = conn.getOutputStream();

            File assembler_file = new File("C:\\Users\\Carlos\\Desktop\\fuseki-assembler.ttl");

            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));

            try {
                    InputStream fis = new FileInputStream(assembler_file);
                    int content;
                    //Read .ttl content by InputStream
                    while ((content = fis.read()) != -1) {
                            writer.write((char) content); //Write the readed content in http OutPutStream
                    }
            } catch (IOException e) {
                    e.printStackTrace();
            }

            writer.flush();
            writer.close();
            os.close();
            String fuseki_response = conn.getResponseMessage();
            conn.connect();
        }finally {}
    }

I would like to know how to POST a file correctly to a server over a Java Client, if possible.

1 Answers1

0

My mistake was in the post format. I solved my problem using this question Upload files from Java client to a HTTP server

Posting an Assembler.ttl allow us to programatically instantiate Fuseki Dataset with Reasoner. This enables Server Reasoning in execution time over included data.