I use HTTPCLIENT to create or append file with rest component HTTPFS.
exemple cmd curl - working with curl
curl -i -X PUT -s --negotiate -u : "http://httpfsServer:14000/webhdfs/v1/user/a_app_kpi/tmp/testAppend.txt?op=CREATE&data=true" --header "Content-Type:application/octet-stream" --header "Transfer-Encoding:chunked" -T testAppend.txt
return query
HTTP/1.1 100 Continue
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
WWW-Authenticate: Negotiate
Set-Cookie: hadoop.auth=; Path=/; HttpOnly
Content-Type: text/html;charset=utf-8
Content-Length: 997
Date: Tue, 21 Nov 2017 16:07:07 GMT
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Set-Cookie: hadoop.auth="u=a_app_kpi&p=a_app_kpi@Environnement&t=kerberos-dt&e=1511316427865&s=JIJTCZS31D1wphVORe3ygZ1NBuo="; Path=/; HttpOnly
Content-Type: application/json
Content-Length: 0
Date: Tue, 21 Nov 2017 16:07:07 GMT
But when i execute request, the program return ERROR com.vhl.action.WebHdfsAction - null
my code with create :
CloseableHttpClient httpClient = cnxHttp.getHttpClient();
File file = new File(beanActionHttp.getPathLocal());
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1, ContentType.APPLICATION_OCTET_STREAM);
reqEntity.setChunked(true);
HttpUriRequest request = RequestBuilder
.put(action_http)
.setEntity(reqEntity)
.build();
request.addHeader(HttpHeaders.TRANSFER_ENCODING, "chunked");
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
// HERE EXECUTE RETURN NULL
CloseableHttpResponse response = httpClient.execute(request);
I find my trouble. First i change method execute request to catch a wonderful error - thanks error
CloseableHttpResponse response = httpClient.execute(request); to HttpResponse response = httpClient.execute(request);
So my trouble it's my request Cannot retry request with a non-repeatable request entity.
I use this follow to solve my trouble Cannot retry request with a non-repeatable request entity
I add my Entity a buffer "BufferedHttpEntity"
Finally the code working :