List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:tools.devnull.boteco.client.rest.impl.DefaultRestClient.java
@Override public RestConfiguration put(URI uri) { return execute(new HttpPut(uri)); }
From source file:v2.service.generic.library.utils.HttpClientUtil.java
public static ResponsePOJO nativeRequest(String url, String json, String requestType, Map<String, String> headers) throws Exception { HttpClient httpclient = createHttpClient(); // HttpEntityEnclosingRequestBase request=null; HttpRequestBase request = null;/*from www .java 2 s. c o m*/ if ("POST".equalsIgnoreCase(requestType)) { request = new HttpPost(url); } else if ("PUT".equalsIgnoreCase(requestType)) { request = new HttpPut(url); } else if ("GET".equalsIgnoreCase(requestType)) { request = new HttpGet(url); } else if ("DELETE".equalsIgnoreCase(requestType)) { request = new HttpDelete(url); } if (json != null) { if (!"GET".equalsIgnoreCase(requestType) && (!"DELETE".equalsIgnoreCase(requestType))) { StringEntity params = new StringEntity(json, "UTF-8"); // StringEntity s = new StringEntity(jsonString, "UTF-8"); ((HttpEntityEnclosingRequestBase) request).setEntity(params); } } if (headers == null) { request.addHeader("content-type", "application/json"); } else { Set<String> keySet_header = headers.keySet(); for (String key : keySet_header) { request.setHeader(key, headers.get(key)); } } ResponsePOJO result = nativeInvoke(httpclient, request); return result; }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationUpdateAction.java
private HttpRequestBase onExecute(String preparationId, String stepId, AppendStep updatedStep) { try {/*from w ww. j a va 2 s .co m*/ final String url = preparationServiceUrl + "/preparations/" + preparationId + "/actions/" + stepId; final List<StepDiff> diff = objectMapper.readValue(getInput(), new TypeReference<List<StepDiff>>() { }); updatedStep.setDiff(diff.get(0)); final String stepAsString = objectMapper.writeValueAsString(updatedStep); final HttpPut actionAppend = new HttpPut(url); final InputStream stepInputStream = new ByteArrayInputStream(stepAsString.getBytes()); actionAppend.setHeader(new BasicHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)); actionAppend.setEntity(new InputStreamEntity(stepInputStream)); return actionAppend; } catch (IOException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:com.arrow.acn.client.api.SoftwareReleaseTransApi.java
public StatusModel received(String hid) { String method = "received"; try {/*from w w w.j a v a 2s . c o m*/ URI uri = buildUri(String.format(RECEIVED_URL, hid)); StatusModel result = execute(new HttpPut(uri), StatusModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:com.mber.client.HTTParty.java
public static Call put(final String url, final File file, final LoggingOutputStream.Listener listener) throws IOException { LoggingFileEntity entity = new LoggingFileEntity(file, listener); entity.setContentType("application/octet-stream"); HttpPut request = new HttpPut(url); request.setEntity(entity);/*w w w . java 2 s . c o m*/ return execute(request); }
From source file:com.scut.easyfe.network.kjFrame.http.HttpClientStack.java
static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) { switch (request.getMethod()) { case Request.HttpMethod.GET: return new HttpGet(request.getUrl()); case Request.HttpMethod.DELETE: return new HttpDelete(request.getUrl()); case Request.HttpMethod.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; }//from ww w. j a va2 s .co m case Request.HttpMethod.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case Request.HttpMethod.HEAD: return new HttpHead(request.getUrl()); case Request.HttpMethod.OPTIONS: return new HttpOptions(request.getUrl()); case Request.HttpMethod.TRACE: return new HttpTrace(request.getUrl()); case Request.HttpMethod.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:com.zekke.services.http.RequestBuilder.java
public RequestBuilder setMethod(RequestMethod type) { switch (type) { case GET://from ww w . j av a2 s.c o m request = new HttpGet(url); break; case POST: request = new HttpPost(url); break; case PUT: request = new HttpPut(url); break; case DELETE: request = new HttpDelete(url); break; default: //TODO: complete switch request = new HttpGet(url); break; } return this; }
From source file:com.aliyun.android.oss.task.PostObjectGroupTask.java
/** * HttpPut// www. j a v a 2s . c o m */ protected HttpUriRequest generateHttpRequest() { // ?Http String requestUri = this.getOSSEndPoint() + httpTool.generateCanonicalizedResource("/" + objectGroup.getName()); ; HttpPut httpPut = new HttpPut(requestUri); // HttpPut String resource = httpTool .generateCanonicalizedResource("/" + objectGroup.getBucketName() + "/" + objectGroup.getName()); String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, httpMethod.toString(), "", objectGroupMetaData.getContentType(), Helper.getGMTDate(), OSSHttpTool.generateCanonicalizedHeader(objectGroupMetaData.getAttrs()), resource); httpPut.setHeader(AUTHORIZATION, authorization); httpPut.setHeader(DATE, Helper.getGMTDate()); httpPut.setHeader(HOST, OSS_HOST); try { httpPut.setEntity(new StringEntity(generateHttpEntity())); } catch (UnsupportedEncodingException e) { Log.e(this.getClass().getName(), e.getMessage()); } return httpPut; }
From source file:org.kymjs.kjframe.http.HttpClientStack.java
static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) { switch (request.getMethod()) { case HttpMethod.GET: return new HttpGet(request.getUrl()); case HttpMethod.DELETE: return new HttpDelete(request.getUrl()); case HttpMethod.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; }//from w w w . j a v a 2 s .c o m case HttpMethod.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } case HttpMethod.HEAD: return new HttpHead(request.getUrl()); case HttpMethod.OPTIONS: return new HttpOptions(request.getUrl()); case HttpMethod.TRACE: return new HttpTrace(request.getUrl()); case HttpMethod.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:playn.http.HttpAndroid.java
@Override protected void doSend(final HttpRequest request, final Callback<HttpResponse> callback) { platform.invokeAsync(new Runnable() { public void run() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8); HttpClient httpclient = new DefaultHttpClient(params); HttpRequestBase req;//ww w.j ava2 s . co m HttpMethod method = request.getMethod(); String url = request.getUrl(); switch (method) { case GET: req = new HttpGet(url); break; case POST: req = new HttpPost(url); break; case PUT: req = new HttpPut(url); break; default: throw new UnsupportedOperationException(method.toString()); } String requestBody = request.getBody(); if (requestBody != null && req instanceof HttpEntityEnclosingRequestBase) { try { HttpEntityEnclosingRequestBase op = (HttpEntityEnclosingRequestBase) req; op.setEntity(new StringEntity(requestBody)); } catch (UnsupportedEncodingException e) { platform.notifyFailure(callback, e); } } for (Map.Entry<String, String> header : request.getHeaders()) { req.setHeader(header.getKey(), header.getValue()); } int statusCode = -1; String statusLineMessage = null; Map<String, String> responseHeaders = new HashMap<String, String>(); String responseBody = null; try { org.apache.http.HttpResponse response = httpclient.execute(req); StatusLine statusLine = response.getStatusLine(); statusCode = statusLine.getStatusCode(); statusLineMessage = statusLine.getReasonPhrase(); for (Header header : response.getAllHeaders()) { responseHeaders.put(header.getName(), header.getValue()); } responseBody = EntityUtils.toString(response.getEntity()); HttpResponse httpResponse = new HttpResponse(statusCode, statusLineMessage, responseHeaders, responseBody); platform.notifySuccess(callback, httpResponse); } catch (Throwable cause) { HttpErrorType errorType = cause instanceof ConnectTimeoutException || cause instanceof HttpHostConnectException || cause instanceof ConnectionPoolTimeoutException || cause instanceof UnknownHostException ? HttpErrorType.NETWORK_FAILURE : HttpErrorType.SERVER_ERROR; HttpException reason = new HttpException(statusCode, statusLineMessage, responseBody, cause, errorType); platform.notifyFailure(callback, reason); } } }); }