List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:com.wudoumi.batter.volley.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//* ww w . j a va2 s . com*/ @SuppressWarnings("deprecation") /* protected */ static HttpUriRequest createHttpRequest(Request<?> request, Map<String, String> additionalHeaders) throws AuthFailureError { switch (request.getMethod()) { case RequestType.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 RequestType.GET: return new HttpGet(request.getUrl()); case RequestType.DELETE: return new HttpDelete(request.getUrl()); case RequestType.POST: { HttpPost postRequest = new HttpPost(request.getUrl()); postRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(postRequest, request); return postRequest; } case RequestType.PUT: { HttpPut putRequest = new HttpPut(request.getUrl()); putRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody(putRequest, request); return putRequest; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:at.ac.tuwien.dsg.elasticdaasclient.utils.RestfulWSClient.java
public String callPutMethodObj(Object obj) { String rs = ""; String returnObj = null;//from ww w .j av a2s.co m try { String xmlString = ""; xmlString = JAXBUtils.marshal(obj, obj.getClass()); System.out.println(xmlString); Logger.getLogger(RestfulWSClient.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"); HttpEntity entity = new ByteArrayEntity(xmlString.getBytes("UTF-8")); request.setEntity(entity); HttpResponse methodResponse = this.getHttpClient().execute(request); int statusCode = methodResponse.getStatusLine().getStatusCode(); Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Status Code: " + statusCode); BufferedReader rd = new BufferedReader(new InputStreamReader(methodResponse.getEntity().getContent())); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rs = result.toString(); // returnObj = (T) JAXBUtils.unmarshal(rs, returnObj.getClass()); // System.out.println("Response String: " + result.toString()); } catch (Exception ex) { System.out.println("Exception: " + ex.toString()); } return returnObj; }
From source file:org.simple.net.httpstacks.HttpClientStack.java
/** * ???Http/*from w w w. ja v a 2 s. c om*/ * * @param request * @return */ static HttpUriRequest createHttpRequest(Request<?> request) { HttpUriRequest httpUriRequest = null; switch (request.getHttpMethod()) { case GET: httpUriRequest = new HttpGet(request.getUrl()); break; case DELETE: httpUriRequest = new HttpDelete(request.getUrl()); break; case POST: { httpUriRequest = new HttpPost(request.getUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPost) httpUriRequest, request); } break; case PUT: { httpUriRequest = new HttpPut(request.getUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPut) httpUriRequest, request); } break; default: throw new IllegalStateException("Unknown request method."); } return httpUriRequest; }
From source file:bbd.basesimplenet.net.httpstacks.HttpClientStack.java
/** * ???Http//from w ww . j a v a 2 s . c o m * * @param request * @return */ static HttpUriRequest createHttpRequest(Request<?> request) { HttpUriRequest httpUriRequest = null; switch (request.getmHttpMethod()) { case GET: httpUriRequest = new HttpGet(request.getmUrl()); break; case DELETE: httpUriRequest = new HttpDelete(request.getmUrl()); break; case POST: { httpUriRequest = new HttpPost(request.getmUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPost) httpUriRequest, request); } break; case PUT: { httpUriRequest = new HttpPut(request.getmUrl()); httpUriRequest.addHeader(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); setEntityIfNonEmptyBody((HttpPut) httpUriRequest, request); } break; default: throw new IllegalStateException("Unknown request method."); } return httpUriRequest; }
From source file:org.wrml.runtime.service.rest.RestService.java
@Override public Model save(final Model model) { final Document document = (Document) model; final URI uri = document.getUri(); final HttpPut httpPut = new HttpPut(uri); final Context context = model.getContext(); final ModelContentProducer httpWriter = new ModelContentProducer(context, null, model); httpPut.setEntity(new EntityTemplate(httpWriter)); final HttpResponse response = executeRequest(httpPut); final Dimensions responseDimensions = RestUtils.extractResponseDimensions(context, response, model.getDimensions());//from w w w .j a va 2 s .c om return readResponseModel(response, model.getContext(), model.getKeys(), responseDimensions); }
From source file:nl.nn.adapterframework.extensions.cmis.CmisHttpSender.java
@Override public HttpRequestBase getMethod(URIBuilder uri, String message, ParameterValueList pvl, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException { HttpRequestBase method = null;//from ww w . j a v a 2 s. co m try { if (getMethodType().equals("GET")) { method = new HttpGet(uri.build()); } else if (getMethodType().equals("POST")) { HttpPost httpPost = new HttpPost(uri.build()); // send data if (pvl.getParameterValue("writer") != null) { Output writer = (Output) pvl.getParameterValue("writer").getValue(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Object clientCompression = pvl.getParameterValue(SessionParameter.CLIENT_COMPRESSION); if ((clientCompression != null) && Boolean.parseBoolean(clientCompression.toString())) { httpPost.setHeader("Content-Encoding", "gzip"); writer.write(new GZIPOutputStream(out, 4096)); } else { writer.write(out); } HttpEntity entity = new BufferedHttpEntity(new ByteArrayEntity(out.toByteArray())); httpPost.setEntity(entity); out.close(); method = httpPost; } } else if (getMethodType().equals("PUT")) { HttpPut httpPut = new HttpPut(uri.build()); // send data if (pvl.getParameterValue("writer") != null) { Output writer = (Output) pvl.getParameterValue("writer").getValue(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Object clientCompression = pvl.getParameterValue(SessionParameter.CLIENT_COMPRESSION); if ((clientCompression != null) && Boolean.parseBoolean(clientCompression.toString())) { httpPut.setHeader("Content-Encoding", "gzip"); writer.write(new GZIPOutputStream(out, 4096)); } else { writer.write(out); } HttpEntity entity = new BufferedHttpEntity(new ByteArrayEntity(out.toByteArray())); httpPut.setEntity(entity); out.close(); method = httpPut; } } else if (getMethodType().equals("DELETE")) { method = new HttpDelete(uri.build()); } else { throw new MethodNotSupportedException("method [" + getMethodType() + "] not implemented"); } } catch (Exception e) { throw new SenderException(e); } for (Map.Entry<String, String> entry : headers.entrySet()) { log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]"); method.addHeader(entry.getKey(), entry.getValue()); } //Cmis creates it's own contentType depending on the method and bindingType method.setHeader("Content-Type", getContentType()); log.debug(getLogPrefix() + "HttpSender constructed " + getMethodType() + "-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] "); return method; }
From source file:org.commonjava.tensor.maven.plugin.LogProjectBuildroot.java
@Override public void execute() throws MojoExecutionException { if (isThisTheExecutionRoot()) { final ModuleAssociations moduleAssoc = new ModuleAssociations( new ProjectVersionRef(project.getGroupId(), project.getArtifactId(), project.getVersion())); for (final MavenProject p : projects) { moduleAssoc.addModule(new ProjectVersionRef(p.getGroupId(), p.getArtifactId(), p.getVersion())); }//from ww w . j a v a 2s . c om final TensorSerializerProvider prov = new TensorSerializerProvider( new EGraphManager(new JungEGraphDriver()), new GraphWorkspaceHolder()); final JsonSerializer serializer = prov.getTensorSerializer(); final String json = serializer.toString(moduleAssoc); final DefaultHttpClient client = new DefaultHttpClient(); try { final HttpPut request = new HttpPut(getUrl()); request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); request.setEntity(new StringEntity(json)); final HttpResponse response = client.execute(request); final StatusLine sl = response.getStatusLine(); if (sl.getStatusCode() != HttpStatus.SC_CREATED) { throw new MojoExecutionException("Failed to publish module-artifact association data: " + sl.getStatusCode() + " " + sl.getReasonPhrase()); } } catch (final UnsupportedEncodingException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; invalid encoding for JSON: " + e.getMessage(), e); } catch (final ClientProtocolException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; http request failed: " + e.getMessage(), e); } catch (final IOException e) { throw new MojoExecutionException( "Failed to publish module-artifact association data; http request failed: " + e.getMessage(), e); } } }
From source file:com.amazonaws.http.ApacheHttpClient.java
private HttpUriRequest createHttpRequest(HttpRequest request) { HttpUriRequest httpRequest;/*from w ww . j a v a 2 s . com*/ String method = request.getMethod(); if (method.equals("POST")) { HttpPost postRequest = new HttpPost(request.getUri()); if (request.getContent() != null) { postRequest.setEntity(new InputStreamEntity(request.getContent(), request.getContentLength())); } httpRequest = postRequest; } else if (method.equals("GET")) { httpRequest = new HttpGet(request.getUri()); } else if (method.equals("PUT")) { HttpPut putRequest = new HttpPut(request.getUri()); if (request.getContent() != null) { putRequest.setEntity(new InputStreamEntity(request.getContent(), request.getContentLength())); } httpRequest = putRequest; } else if (method.equals("DELETE")) { httpRequest = new HttpDelete(request.getUri()); } else if (method.equals("HEAD")) { httpRequest = new HttpHead(request.getUri()); } else { throw new UnsupportedOperationException("Unsupported method: " + method); } if (request.getHeaders() != null && !request.getHeaders().isEmpty()) { for (Map.Entry<String, String> header : request.getHeaders().entrySet()) { String key = header.getKey(); /* * HttpClient4 fills in the Content-Length header and complains * if it's already present, so we skip it here. We also skip the * Host header to avoid sending it twice, which will interfere * with some signing schemes. */ if (key.equals(HttpHeader.CONTENT_LENGTH) || key.equals(HttpHeader.HOST)) { continue; } httpRequest.addHeader(header.getKey(), header.getValue()); } } // disable redirect if (params == null) { params = new BasicHttpParams(); params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); } httpRequest.setParams(params); return httpRequest; }
From source file:com.autonavi.gxdtaojin.toolbox.HttpClientStack.java
/** * Creates the appropriate subclass of HttpUriRequest for passed in request. *//*from w w w. java 2 s.c o m*/ @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; } default: throw new IllegalStateException("Unknown request method."); } }
From source file:cn.com.zzwfang.http.HttpExecuter.java
@Override public HttpResponse put(String url, RequestParams params, Header[] headers) { if (url == null) { return null; }/*from w w w . ja v a 2 s . c om*/ HttpPut httpPut = new HttpPut(url); if (params != null) { HttpEntity entity = params.getEntity(); httpPut.setEntity(entity); } if (headers != null) { httpPut.setHeaders(headers); } return execute(httpPut); }