Example usage for org.apache.commons.httpclient.methods PutMethod getName

List of usage examples for org.apache.commons.httpclient.methods PutMethod getName

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PutMethod getName.

Prototype

public String getName() 

Source Link

Usage

From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java

@Override
public void storeItem(ProxyRepository repository, StorageItem item)
        throws UnsupportedStorageOperationException, RemoteStorageException {
    if (!(item instanceof StorageFileItem)) {
        throw new UnsupportedStorageOperationException("Storing of non-files remotely is not supported!");
    }/*from ww w .  j  a  v a 2 s .c  om*/

    StorageFileItem fItem = (StorageFileItem) item;

    ResourceStoreRequest request = new ResourceStoreRequest(item);

    URL remoteURL = getAbsoluteUrlFromBase(repository, request);

    PutMethod method = new PutMethod(remoteURL.toString());

    try {
        method.setRequestEntity(
                new InputStreamRequestEntity(fItem.getInputStream(), fItem.getLength(), fItem.getMimeType()));

        int response = executeMethod(repository, request, method, remoteURL);

        if (response != HttpStatus.SC_OK && response != HttpStatus.SC_CREATED
                && response != HttpStatus.SC_NO_CONTENT && response != HttpStatus.SC_ACCEPTED) {
            throw new RemoteStorageException("Unexpected response code while executing " + method.getName()
                    + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\""
                    + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString()
                    + "\"]. Expected: \"any success (2xx)\". Received: " + response + " : "
                    + HttpStatus.getStatusText(response));
        }
    } catch (IOException e) {
        throw new RemoteStorageException(
                e.getMessage() + " [repositoryId=\"" + repository.getId() + "\", requestPath=\""
                        + request.getRequestPath() + "\", remoteUrl=\"" + remoteURL.toString() + "\"]",
                e);
    } finally {
        method.releaseConnection();
    }
}