コード例 #1
0
  // @Test
  public void test2() throws Exception {
    int port = 7533;
    Server server =
        ServerUtils.startServer(port, WebAppInitializerSparqlService.create(ConfigApp.class));
    server.join();

    //      ResourceHandler resHandler = new ResourceHandler();
    //      resHandler.setBaseResource(Resource.newClassPathResource("/snorql/"));
    //      server.setHandler(resHandler);

    // http://stackoverflow.com/questions/29658240/spring-boot-jersey-allow-jersey-to-serve-static-content
    // SpringApplication.run(MySpringBootServletInitializer.class);

    //        AnnotationConfigApplicationContext ctx = new
    // AnnotationConfigApplicationContext(ConfigApp.class);
    //        SparqlServiceFactory ssf = (SparqlServiceFactory) ctx.getBean("sparqlServiceFactory");

    // SparqlService ssDBpedia =
    // ssf.createSparqlService("http://akswnc3.informatik.uni-leipzig.de/data/jassa/sparql", new
    // DatasetDescription(Collections.singletonList("http://dbpedia.org"),
    // Collections.<String>emptyList()), null);
    // String s = "Construct { ?s ?p ?o } { ?s ?p ?o { Select Distinct ?s { ?s a
    // <http://dbpedia.org/ontology/Person> } Limit 10 } }";

    // SparqlService ssLocal = ssf.createSparqlService("http://localhost:8890/sparql", new
    // DatasetDescription(Collections.singletonList("http://jsa.aksw.org/test/data/"),
    // Collections.<String>emptyList()), null);
    // UpdateExecutionUtils.copyByConstruct(ssLocal, ssDBpedia, s, 1000);

  }
コード例 #2
0
  // TODO Make this test work in offline mode
  // @Test
  public void test1() throws Exception {
    int port = 7533;

    AnnotationConfigApplicationContext ctx =
        new AnnotationConfigApplicationContext(ConfigApp.class);
    SparqlServiceFactory ssf = (SparqlServiceFactory) ctx.getBean("sparqlServiceFactory");

    SparqlService ssDBpedia =
        ssf.createSparqlService(
            "http://dbpedia.org/sparql",
            new DatasetDescription(
                Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()),
            null);
    String s =
        "Construct { ?s ?p ?o } { ?s ?p ?o { Select Distinct ?s { ?s a <http://dbpedia.org/ontology/Person> } Limit 10 } }";

    SparqlService ssLocal =
        ssf.createSparqlService(
            "http://localhost:8890/sparql",
            new DatasetDescription(
                Collections.singletonList("http://jsa.aksw.org/test/data/"),
                Collections.<String>emptyList()),
            null);
    UpdateExecutionUtils.copyByConstruct(ssLocal, ssDBpedia, s, 1000);

    Server server =
        ServerUtils.startServer(port, WebAppInitializerSparqlService.create(ConfigApp.class));

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://localhost:" + port + "/sparql");

    // Request parameters and other properties.
    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair("service-uri", "http://localhost:8890/sparql"));
    params.add(new BasicNameValuePair("using-graph-uri", "http://jsa.aksw.org/test/data/"));
    // params.add(new BasicNameValuePair("update", "Prefix ex: <http://example.org/> Delete Data{
    // ex:s ex:p ex:o }"));
    params.add(
        new BasicNameValuePair(
            "update",
            "Prefix ex: <http://example.org/> Delete { ?s ?p ?o } Where { ?s ?x <http://dbpedia.org/class/yago/Creator109614315> ; ?p ?o }"));
    httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

    HttpResponse response = httpClient.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), 200);
    HttpEntity respEntity = response.getEntity();

    if (respEntity != null) {
      // EntityUtils to get the response content
      String content = EntityUtils.toString(respEntity);
      System.out.println("Response: " + content);
    }

    server.stop();
    server.join();
  }