List of usage examples for org.apache.http.client.methods HttpPut getMethod
@Override
public String getMethod()
From source file:de.unioninvestment.eai.portal.portlet.crud.scripting.domain.container.rest.ReSTDelegateImpl.java
private void sendPutRequest(GenericItem item, ReSTChangeConfig changeConfig) throws ClientProtocolException, IOException { byte[] content = creator.create(item, changeConfig.getValue(), config.getCharset()); URI uri = createURI(item, changeConfig.getUrl()); HttpPut request = new HttpPut(uri); ContentType contentType = createContentType(); request.setEntity(new ByteArrayEntity(content, contentType)); try {//w w w . j a va2 s . c o m HttpResponse response = httpClient.execute(request); auditLogger.auditReSTRequest(request.getMethod(), uri.toString(), new String(content, config.getCharset()), response.getStatusLine().toString()); expectAnyStatusCode(response, HttpStatus.SC_OK, HttpStatus.SC_NO_CONTENT); } finally { request.releaseConnection(); } }
From source file:org.sahli.asciidoc.confluence.publisher.client.http.HttpRequestFactoryTest.java
@Test public void updatePageRequest_withValidParameters_returnsValidHttpPutRequest() throws Exception { // arrange// ww w . jav a2 s .co m String contentId = "1234"; String ancestorId = "1"; String title = "title"; String content = "content"; Integer version = 2; // act HttpPut updatePageRequest = this.httpRequestFactory.updatePageRequest(contentId, ancestorId, title, content, version); // assert assertThat(updatePageRequest.getMethod(), is("PUT")); assertThat(updatePageRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId)); assertThat(updatePageRequest.getFirstHeader("Content-Type").getValue(), is(APPLICATION_JSON_UTF8)); String jsonPayload = inputStreamAsString(updatePageRequest.getEntity().getContent()); String expectedJsonPayload = fileContent(Paths.get(CLASS_LOCATION, "update-page-request.json").toString()); assertThat(jsonPayload, SameJsonAsMatcher.isSameJsonAs(expectedJsonPayload)); }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientRemoteStorage.java
@Override public void storeItem(final ProxyRepository repository, final StorageItem item) throws UnsupportedStorageOperationException, RemoteStorageException { if (!(item instanceof StorageFileItem)) { throw new UnsupportedStorageOperationException("Storing of non-files remotely is not supported!"); }/*from www. j a va2 s. c o m*/ final StorageFileItem fileItem = (StorageFileItem) item; final ResourceStoreRequest request = new ResourceStoreRequest(item); final URL remoteUrl = appendQueryString(getAbsoluteUrlFromBase(repository, request), repository); final HttpPut method = new HttpPut(remoteUrl.toExternalForm()); final InputStreamEntity entity; try { entity = new InputStreamEntity(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); 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()); } }