org.apache.jena.atlas.web.HttpException:405 - 此URL不支持HTTP方法POST

时间:2017-10-22 17:03:55

标签: java http jena ontology fuseki

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

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

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?

但它并没有帮助我。

1 个答案:

答案 0 :(得分:1)

.add("/data",

然后

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

"数据"在一个," ds"在另一个。

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

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