Uploaded image for project: 'Blazegraph (by SYSTAP)'
  1. Blazegraph (by SYSTAP)
  2. BLZG-3169

Expecting Content-Type of application/xml, not application/rdf+xml

    XMLWordPrintable

    Details

      Description

      Hello,

      I’m trying to connect to Blazegraph using SESAME API with Eclipse IDE for JAVA Developers (NEON 4.6.1), to do this, I'm following a tutorial that Blazegraph provides:
      https://wiki.blazegraph.com/wiki/index.php/Sesame_API_remote_mode
      The problem is that when the program is executed, In Eclipse's console appears :
      Exception in thread "main" java.lang.RuntimeException: Expecting Content-Type of application/xml, not application/rdf+xml
      at com.bigdata.rdf.sail.webapp.client.RemoteRepositoryBase.mutationResults(RemoteRepositoryBase.java:183)
      at com.bigdata.rdf.sail.webapp.client.RemoteRepository.add(RemoteRepository.java:738)
      at com.bigdata.rdf.sail.webapp.client.RemoteRepository.add(RemoteRepository.java:684)
      at prueba.blazegraph.SampleBlazegraphSesameRemote.loadDataFromResource(SampleBlazegraphSesameRemote.java:147)
      at prueba.blazegraph.SampleBlazegraphSesameRemote.main(SampleBlazegraphSesameRemote.java:64)

      My code is simple, only contains the Blazegraph Tutorial says, with a little modification in the file path, and in the file format Turtle instead of N3.
      For execute this code, I am using bigdata-client dependency in 2.1.4, and sesame-rio-api in 2.8.10.

      This is it:
      package prueba.blazegraph;

      import java.io.IOException;
      import java.io.InputStream;
      import java.util.HashSet;
      import java.util.Map;
      import java.util.Properties;
      import java.util.Set;

      import com.bigdata.rdf.sail.webapp.SD;
      import com.bigdata.rdf.sail.webapp.client.ConnectOptions;
      import com.bigdata.rdf.sail.webapp.client.JettyResponseListener;
      import com.bigdata.rdf.sail.webapp.client.RemoteRepository;
      import com.bigdata.rdf.sail.webapp.client.RemoteRepositoryManager;

      import org.apache.log4j.Logger;
      import org.openrdf.model.Statement;
      import org.openrdf.query.BindingSet;
      import org.openrdf.query.GraphQueryResult;
      import org.openrdf.query.TupleQueryResult;
      import org.openrdf.rio.RDFFormat;

      public class SampleBlazegraphSesameRemote {

      protected static final Logger log = Logger
      .getLogger(SampleBlazegraphSesameRemote.class);
      private static final String serviceURL = "http://localhost:9999/bigdata";

      public static void main(String[] args) throws Exception {

      final RemoteRepositoryManager repo = new RemoteRepositoryManager(
      serviceURL, false /* useLBS */);

      try {

      JettyResponseListener response = getStatus(repo);
      log.info(response.getResponseBody());

      // create a new namespace if not exists
      final String namespace = "nuevoNamespace";
      final Properties properties = new Properties();
      properties.setProperty("com.bigdata.rdf.sail.namespace", namespace);
      if (!namespaceExists(repo, namespace))

      { log.info(String.format("Create namespace %s...", namespace)); repo.createRepository(namespace, properties); log.info(String.format("Create namespace %s done", namespace)); }

      else

      { log.info(String.format("Namespace %s already exists", namespace)); System.out.println("El namespace existe"); }

      //get properties for namespace
      log.info(String.format("Property list for namespace %s", namespace));
      response = getNamespaceProperties(repo, namespace);
      log.info(response.getResponseBody());

      /*

      • Load data from file located in the resource folder
      • src/main/resources/data.n3
        */
        final String resource = "/datos.ttl";
        loadDataFromResource(repo, namespace, resource);

      // execute query
      final TupleQueryResult result = repo.getRepositoryForNamespace(namespace)
      .prepareTupleQuery("SELECT * where {?s ?p ?o} LIMIT 100")
      .evaluate();

      //result processing
      try {
      while (result.hasNext())

      { final BindingSet bs = result.next(); log.info(bs); }

      } finally

      { result.close(); }

      } finally

      { repo.close(); }

      }

      /*

      • Status request.
        */
        private static JettyResponseListener getStatus(final RemoteRepositoryManager repo)
        throws Exception { final ConnectOptions opts = new ConnectOptions(serviceURL + "/status"); opts.method = "GET"; return repo.doConnect(opts); }

      /*

      • Check namespace already exists.
        */
        private static boolean namespaceExists(final RemoteRepositoryManager repo,
        final String namespace) throws Exception {

      final GraphQueryResult res = repo.getRepositoryDescriptions();
      try {
      while (res.hasNext()) {
      final Statement stmt = res.next();
      if (stmt.getPredicate()
      .toString()
      .equals(SD.KB_NAMESPACE.stringValue())) {
      if (namespace.equals(stmt.getObject().stringValue()))

      { return true; }

      }
      }
      } finally

      { res.close(); }

      return false;
      }

      /*

      • Get namespace properties.
        */
        private static JettyResponseListener getNamespaceProperties(
        final RemoteRepositoryManager repo, final String namespace) throws Exception { final ConnectOptions opts = new ConnectOptions(serviceURL + "/namespace/" + namespace + "/properties"); opts.method = "GET"; return repo.doConnect(opts); }

      /*

      • Load data into a namespace.
        */
        private static void loadDataFromResource(final RemoteRepositoryManager repo,
        final String namespace, final String resource) throws Exception
        Unknown macro: { final InputStream is = SampleBlazegraphSesameRemote.class .getResourceAsStream(resource); if (is == null) { throw new IOException("Could not locate resource: " + resource); } try { repo.getRepositoryForNamespace(namespace).add( new RemoteRepository.AddOp(is, RDFFormat.TURTLE)); } finally { is.close(); } }

      }

        Attachments

          Activity

            People

            Assignee:
            beebs Brad Bebee
            Reporter:
            DMUCHUARI Mishel Uchuari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: