【问题标题】:How to Build a Fuseki TDB over a POST HTTP Request with Assembler.ttl? (How to send File over POST request)如何使用 Assembler.ttl 通过 POST HTTP 请求构建 Fuseki TDB? (如何通过 POST 请求发送文件)
【发布时间】:2023-03-19 16:40:02
【问题描述】:

https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html 阅读文档,我们看到我们能够向 Fuseki Endpoint 发送包含汇编器 .ttl 定义的 POST 请求。虽然,在尝试这样做时,我的应用程序没有从服务器得到任何答案。

我正在用 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 {}
    }

如果可能,我想知道如何通过 Java 客户端正确地将文件 POST 到服务器。

【问题讨论】:

    标签: http post jena fuseki tdb


    【解决方案1】:

    我的错误在于帖子格式。 我用这个问题解决了我的问题 Upload files from Java client to a HTTP server

    发布 Assembler.ttl 允许我们使用 Reasoner 以编程方式实例化 Fuseki 数据集。这使得服务器推理能够在包含的数据上执行时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      相关资源
      最近更新 更多