Search code examples
javahttpjenaontologyfuseki

org.apache.jena.atlas.web.HttpException: 405 - HTTP method POST is not supported by this URL


I tried to built Fuseki server, and add some data to it. There is my function to build Fuseki

(according to example3 of https://jena.apache.org/documentation/fuseki2/fuseki-embedded.html):

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;
    }

After creating it, I want to add some data to it.

    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);
            }}

My error message is :

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)

I've seen these issues :

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?

but it didn't help me.


Solution

  • .add("/data",

    then

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

    "data" in one, "ds" in the other.

    You need to use the same service name.

    The error is Jetty rejecting the request. It didn't get to Fuseki.