try {
validatePath(repository, request);
}
catch (ItemNotFoundException e) {
throw new RemoteStorageException("Invalid path to store", e);
}
final URL remoteUrl = appendQueryString(repository, request, getAbsoluteUrlFromBase(repository, request));
final HttpPut method = new HttpPut(remoteUrl.toExternalForm());
final InputStreamEntity entity;
try {
entity =
new InputStreamEntity(new InterruptableInputStream(fileItem.getInputStream()), fileItem.getLength());
}
catch (IOException e) {
throw new RemoteStorageException(e.getMessage() + " [repositoryId=\"" + repository.getId()
+ "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + remoteUrl.toString() + "\"]",
e);
}
entity.setContentType(fileItem.getMimeType());
method.setEntity(entity);
final HttpResponse httpResponse = executeRequestAndRelease(repository, request, method, repository.getRemoteUrl());
final int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_CREATED
&& statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_ACCEPTED) {
throw new RemoteStorageException("Unexpected response code while executing " + method.getMethod()
+ " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath()
+ "\", remoteUrl=\"" + remoteUrl.toString() + "\"]. Expected: \"any success (2xx)\". Received: "
+ statusCode + " : " + httpResponse.getStatusLine().getReasonPhrase());
}
}