3

I am trying to write a ttl file to a graph in virtuoso using HTTP post call to the graph endpoint,

resource = new ClassPathResource("beil0.ttl").getFile();
        String text = new String(Files.readAllBytes(resource.toPath()));
        WebClient webClient = webConfig.webClientBuilder().build();
        WebClient.ResponseSpec responseSpec = webClient.post()
                .uri("?graph-uri=http://data.else.com/voca/comp/")
                .header("Content-Type", "text/turtle")
                .bodyValue(text)
                .retrieve();
        String responseBody = responseSpec.bodyToMono(String.class).block();

Here i am reading the file first in variable 'text' and then passing it to the post call which eventually gives me an error as follows :-

java.lang.IndexOutOfBoundsException: writerIndex(0) + minWritableBytes(-1932256561) exceeds maxCapacity(2147483647): PooledUnsafeDirectByteBuf(ridx: 0, widx: 0, cap: 2147483647)

I am assuming its a big file so this error is being thrown from the virtuoso endpoint, if my assumption is right then what i want to do is stream this file content to the endpoint rather than sending it all together. Does anyone has an idea how can i achieve such functionality here. FYI - I tried to use INPUTSTREAM, MULTIPART and many other ways that i can find online but i am still not able to achieve it because of one reason or another.

  • 1
    The error is a java error from the local JVM. Seems like the file is over 2Gbytes (2147483647 = 2^31 − 1). That exceeds a java int. – AndyS Jul 13 '22 at 09:25
  • The file i am trying to upload is actually around 800MB in size, converting it to string and then passing it to POST call is definitely not a good option thats why i am trying to search a method where i can pass it as a Input Stream – Naman Sharma Jul 13 '22 at 11:16
  • InputStreamResource resource = new InputStreamResource(new FileInputStream("filePath")); WebClient webClient = webConfig.webClientBuilder().build(); HttpStatus responseSpec = webClient.post() .uri("?graph-uri=http://data.com/voca/c/") .header("Content-Type", "text/turtle") .body(BodyInserters.fromResource(resource)) .exchangeToMono(response -> { if (response.statusCode().equals(HttpStatus.OK)) { return response.bodyToMono(HttpStatus.class).thenReturn(response.statusCode()); } else {throw new IllegalStateException("Error uploading file");}}).block(); – Naman Sharma Jul 13 '22 at 11:20
  • Currently this is what i am trying right now but it throws an error as follows :- An established connection was aborted by the software in your host machine – Naman Sharma Jul 13 '22 at 11:21

1 Answers1

1

You could use these Virtuoso samples for loading RDF data to Virtuoso via TCP connection. (The samples are in Gradle project format.)

  1. RDFLoader via Jena API uses the Virtuoso Jena Provider
  2. RDFLoader via RDF4J API uses the Virtuoso RDF4J Provider
TallTed
  • 9,069
  • 2
  • 22
  • 37