首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Assembler.ttl在POST HTTP请求上构建Fuseki TDB?(如何通过POST请求发送文件)

如何使用Assembler.ttl在POST HTTP请求上构建Fuseki TDB?(如何通过POST请求发送文件)
EN

Stack Overflow用户
提问于 2020-02-11 23:09:20
回答 1查看 187关注 0票数 1

https://jena.apache.org/documentation/fuseki2/fuseki-server-protocol.html阅读文档,我们看到我们能够向Fuseki端点发送一个包含汇编程序.ttl定义的POST请求。尽管在尝试时,我的应用程序没有从服务器得到任何响应。

我正在尝试用Java编写以下代码:

代码语言:javascript
复制
/**
     * 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客户端将文件正确地发布到服务器。

EN

回答 1

Stack Overflow用户

发布于 2020-02-12 21:17:29

我的错误是在文章格式上。我用这个问题Upload files from Java client to a HTTP server解决了我的问题

通过发布Assembler.ttl,我们可以使用Reasoner编程实例化Fuseki数据集。这使得服务器能够在执行时对包含的数据进行推理。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60171943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档