代码之家  ›  专栏  ›  技术社区  ›  Evgenii

webhdfs使用kerberos rest模板创建HttpServerErrorException:500内部服务器错误

  •  0
  • Evgenii  · 技术社区  · 6 年前

    KerberosRestTemplate .

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

    在我的服务课上

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

    /showFileContent 但每次我尝试 /createFile Error running rest call; nested exception is org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error . 我在调用create之前删除了文件。

    错误的原因是什么?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Evgenii    6 年前

    我设法写入一个文件,而不是创建一个。这已经足够满足我的需要,可能会帮助其他人,所以我会把它贴在这里。

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