webhdfs create using kerberos rest template HttpServerErrorE



我正在尝试使用webhdfs在hdfs中创建一个文件。Kerberos 用于集群的安全性,所以我使用KerberosRestTemplate

在我的控制器中,我有 2 种方法

@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。我在调用创建之前删除了该文件。

错误的原因是什么?

我设法写入了一个文件,而不是创建一个文件。这足以满足我的需求,并且可能会帮助其他人,所以我会在这里发布它。

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

最新更新