List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:se.svt.helios.serviceregistration.consul.ConsulClient.java
public Future<HttpResponse> register(final Service record) throws JsonProcessingException { final String value = OBJECT_MAPPER.writeValueAsString(record); final URI uri = URI.create(baseUri + REGISTER_ENDPOINT); final HttpPut request = new HttpPut(uri); request.setEntity(new StringEntity(value, "UTF-8")); return httpClient.execute(request, new RequestCallback("register service " + record.getId())); }
From source file:com.hoccer.tools.HttpHelper.java
public static String putAsString(String pUri, String pData) throws IOException, HttpClientException, HttpServerException { HttpPut put = new HttpPut(pUri); insert(pData, "text/plain", "text/plain", put); StatusLine statusLine = executeHTTPMethod(put, PUT_TIMEOUT).getStatusLine(); return statusLine.getStatusCode() + " " + statusLine.getReasonPhrase(); }
From source file:net.fizzl.redditengine.impl.SimpleHttpClient.java
/** * Calls HTTP PUT with the Request-URI. Returns an InputStream of the response entity. * /*from w w w. j a v a 2 s . c o m*/ * @param url HTTP PUT URL * @param params PUT parameters * @return InputStream * @throws ClientProtocolException * @throws IOException * @throws UnexpectedHttpResponseException */ public InputStream put(String url, List<NameValuePair> params) throws ClientProtocolException, IOException, UnexpectedHttpResponseException { HttpPut put = new HttpPut(url); put.setEntity(new UrlEncodedFormEntity(params)); return execute(put); }
From source file:org.sonatype.nexus.testsuite.security.SimpleSessionCookieIT.java
@Test public void authenticatedContentCRUDActionsShouldNotCreateSession() throws Exception { final String target = resolveUrl(nexusUrl, "content/repositories/releases/test.txt").toExternalForm(); final HttpPut put = new HttpPut(target); put.setEntity(new StringEntity("text content")); try (CloseableHttpClient client = clientBuilder().setDefaultCredentialsProvider(credentialsProvider()) .build()) {/* w w w .j ava2 s . co m*/ try (CloseableHttpResponse response = client.execute(put, clientContext())) { assertThat(response.getStatusLine().getStatusCode(), is(201)); assertResponseHasNoSessionCookies(response); } } final HttpHead head = new HttpHead(target); try (CloseableHttpClient client = clientBuilder().setDefaultCredentialsProvider(credentialsProvider()) .build()) { try (CloseableHttpResponse response = client.execute(head, clientContext())) { assertThat(response.getStatusLine().getStatusCode(), is(200)); assertResponseHasNoSessionCookies(response); } } final HttpGet get = new HttpGet(target); try (CloseableHttpClient client = clientBuilder().setDefaultCredentialsProvider(credentialsProvider()) .build()) { try (CloseableHttpResponse response = client.execute(get, clientContext())) { assertThat(response.getStatusLine().getStatusCode(), is(200)); assertResponseHasNoSessionCookies(response); } } final HttpDelete delete = new HttpDelete(target); try (CloseableHttpClient client = clientBuilder().setDefaultCredentialsProvider(credentialsProvider()) .build()) { try (CloseableHttpResponse response = client.execute(delete, clientContext())) { assertThat(response.getStatusLine().getStatusCode(), is(204)); assertResponseHasNoSessionCookies(response); } } }
From source file:at.ac.tuwien.dsg.depic.dataassetfunctionmanagement.util.TavernaRestAPI.java
public int callPutMethodRC(String xmlString) { int statusCode = 0; try {/* ww w. j av a2 s . co m*/ //HttpGet method = new HttpGet(url); StringEntity inputKeyspace = new StringEntity(xmlString); Logger.getLogger(TavernaRestAPI.class.getName()).log(Level.INFO, "Connection .. " + url); HttpPut request = new HttpPut(url); request.addHeader("content-type", "application/xml; charset=utf-8"); request.addHeader("Accept", "application/xml, multipart/related"); request.setEntity(inputKeyspace); HttpResponse methodResponse = this.getHttpClient().execute(request); statusCode = methodResponse.getStatusLine().getStatusCode(); Logger.getLogger(TavernaRestAPI.class.getName()).log(Level.INFO, "Status Code: " + statusCode); // System.out.println("Response String: " + result.toString()); } catch (Exception ex) { } return statusCode; }
From source file:com.floragunn.searchguard.test.helper.rest.RestHelper.java
public HttpResponse executePutRequest(final String request, String body, Header... header) throws Exception { HttpPut uriRequest = new HttpPut(getHttpServerUri() + "/" + request); if (!Strings.isNullOrEmpty(body)) { uriRequest.setEntity(new StringEntity(body)); }/* ww w . j a v a 2 s.com*/ return executeRequest(uriRequest, header); }
From source file:org.eclipse.lyo.testsuite.server.trsutils.SendUtil.java
/** * /*from www.j a va 2s.com*/ * @param uri resource uri for update * @param httpClient client used to put data to the uri * @param httpContext http context to use for the call * @param content content to be used in the updation * @throws SendException if an error occurs in putting data to the uri */ public static boolean updateResource(String uri, HttpClient httpClient, HttpContext httpContext, String contentType, String content) throws SendException { boolean resourceUpdated = false; if (uri == null) throw new IllegalArgumentException(Messages.getServerString("send.util.uri.null")); //$NON-NLS-1$ if (httpClient == null) throw new IllegalArgumentException(Messages.getServerString("send.util.httpclient.null")); //$NON-NLS-1$ try { new URL(uri); // Make sure URL is valid HttpPut put = new HttpPut(uri); StringEntity entity = new StringEntity(content); put.setEntity(entity); put.setHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML); put.addHeader(HttpConstants.CONTENT_TYPE, contentType); put.addHeader(HttpConstants.CACHE_CONTROL, "max-age=0"); //$NON-NLS-1$ HttpResponse resp = httpClient.execute(put); try { if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { HttpErrorHandler.responseToException(resp); } resourceUpdated = true; HttpResponseUtil.finalize(resp); } finally { try { if (entity != null) { EntityUtils.consume(entity); } } catch (IOException e) { // ignore } } } catch (Exception e) { String uriLocation = Messages.getServerString("send.util.uri.unidentifiable"); //$NON-NLS-1$ if (uri != null && !uri.isEmpty()) { uriLocation = uri; } throw new SendException(MessageFormat.format(Messages.getServerString("send.util.retrieve.error"), //$NON-NLS-1$ uriLocation)); } return resourceUpdated; }
From source file:com.lovebridge.library.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *///from w w w . j a va 2s . com @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case Method.DEPRECATED_GET_OR_POST: { // This is the deprecated way that needs to be handled for // backwards compatibility. // If the request's post body is null, then the assumption is // that the request is // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != null) { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getPostBodyContentType()); HttpEntity entity; entity = new ByteArrayEntity(postBody); postRequest.setEntity(entity); return postRequest; } else { return new HttpGet(request.getUrl()); } } case Method.GET: return new HttpGet(request.getUrl()); case Method.DELETE: return new HttpDelete(request.getUrl()); case Method.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case Method.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Method.HEAD: return new HttpHead(request.getUrl()); case Method.OPTIONS: return new HttpOptions(request.getUrl()); case Method.TRACE: return new HttpTrace(request.getUrl()); case Method.PATCH: { HttpPatch patchRequest = new HttpPatch(request.getUrl()); patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(patchRequest, request); return patchRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:org.opensuse.android.HttpCoreRestClient.java
public Resource put(String uri, String xml) { return execute(add(new HttpPut(buildUri(uri)), xml)); }
From source file:com.arrow.acn.client.api.DeviceTypeApi.java
/** * Sends PUT request to update existing device type according to * {@code model} passed//from w ww. ja v a2 s .c o m * * @param hid * {@link String} representing {@code hid} of device type to be * updated * @param model * {@link DeviceTypeModel} representing device type parameters to * be updated * * @return {@link HidModel} containing {@code hid} of device type updated * * @throws AcnClientException * if request failed */ public HidModel updateDeviceType(String hid, DeviceTypeModel model) { String method = "updateDeviceAction"; try { URI uri = buildUri(SPECIFIC_DEVICE_TYPE_URL.replace("{hid}", hid)); HidModel result = execute(new HttpPut(uri), JsonUtils.toJson(model), HidModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }