我尝试构建Fuseki服务器,并向其中添加一些数据。我有建立Fuseki的功能

(根据https://jena.apache.org/documentation/fuseki2/fuseki-embedded.html的example3):

public static FusekiServer createFusekiServer() {
        DatasetGraph ds = DatasetGraphFactory.createTxnMem();
        DataService dataService = new DataService(ds);
        dataService.addEndpoint(OperationName.Update, "");
        FusekiServer server = FusekiServer.create().setPort(3332).add("/data", dataService).build() ;

        server.start();
        return server;
    }


创建它之后,我想向其中添加一些数据。

    public static void main(String[] args) {
        FusekiSrv fusekiSrv = new FusekiSrv();
        String uri = "http://host:3332/ds";
        DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(uri);

        Model model = ontology.loadOntology(pathName);
        FusekiServer fusekiServer = fusekiSrv.createFusekiServer();

        fusekiSrv.sendOntologyToFuseki(accessor, model);
        fusekiServer.stop();

}

    public static void sendOntologyToFuseki(DatasetAccessor accessor, Model model) {
            if (accessor != null) {
                accessor.add(model);
            }}


我的错误信息是:

Exception in thread "main" org.apache.jena.atlas.web.HttpException: 405 - HTTP method POST is not supported by this URL
    at org.apache.jena.riot.web.HttpOp.exec(HttpOp.java:1084)
    at org.apache.jena.riot.web.HttpOp.execHttpPost(HttpOp.java:711)
    at org.apache.jena.riot.web.HttpOp.execHttpPost(HttpOp.java:655)
    at org.apache.jena.web.DatasetGraphAccessorHTTP.doPost(DatasetGraphAccessorHTTP.java:192)
    at org.apache.jena.web.DatasetGraphAccessorHTTP.httpPost(DatasetGraphAccessorHTTP.java:182)
    at org.apache.jena.web.DatasetAdapter.add(DatasetAdapter.java:91)


我看过这些问题:

405 HTTP method PUT is not supported by this URL

getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever?

但这对我没有帮助。

最佳答案

.add("/data",

然后

uri = "http://host:3332/ds"

一个是“数据”,另一个是“ ds”。

您需要使用相同的服务名称。

错误是Jetty拒绝了请求。没到Fuseki。

关于java - org.apache.jena.atlas.web.HttpException:405-此URL不支持HTTP方法POST,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46876859/

10-08 23:01