javaspringrestkerberoswebhdfs

webhdfs create using kerberos rest template HttpServerErrorException: 500 Internal Server Error


I am trying to create a file in hdfs using webhdfs. Kerberos is used for security on cluster, so I use KerberosRestTemplate.

In my controller I have 2 methods

  @RequestMapping("/showFileContent")
  public ResponseEntity<String> showContent() throws URISyntaxException {
    return new ResponseEntity<>(taxonService.getTaxonJSON(), HttpStatus.OK);
  }

  @RequestMapping("/createFile")
  public ResponseEntity<URI> createFile() throws URISyntaxException {
    return new ResponseEntity<>(taxonService.createFile(), HttpStatus.OK);
  }

And in my service class I have

  public String getTaxonJSON() throws URISyntaxException {
    URI uri = new URI(path + "?op=OPEN");
    String json = restTemplate.getForObject(uri, String.class);
    return json;
  }

  public URI createFile() throws URISyntaxException {
    URI uri = new URI(path + "?op=CREATE");
    return restTemplate.postForLocation(uri, String.class);
  }

I can see file content just fine using /showFileContent, but every time I try /createFile, I get Error running rest call; nested exception is org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error. I remove the file before calling create.

What is the reason for the error?


Solution

  • I managed to write to a file, not create one. This is enough for my needs and might help someone else, so I'll post it here.

    public boolean writeFile(File file) throws URISyntaxException {
        URI uri = new URI(path + "?op=CREATE" + "&overwrite=true&data=true");
        ResponseEntity e =kerberosRestTemplate.exchange(uri, HttpMethod.PUT, new HttpEntity<Resource>(new FileSystemResource(file)), Map.class);
        return e.getStatusCodeValue() == 201;
      }