List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String xhrRequest(String shrDataString) { InputStream is = null;// w ww. j ava 2s. c o m String json = null; try { logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "shrDataString [" + shrDataString + "]"); Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString)); String url = (String) xhrData.get("url"); String method = (String) xhrData.get("method"); List headers = (List) xhrData.get("headers"); URL requestURL = createURL(url); URI uri = new URI(requestURL.toString()); HashMap httpMethods = new HashMap(7); httpMethods.put("DELETE", new HttpDelete(uri)); httpMethods.put("GET", new HttpGet(uri)); httpMethods.put("HEAD", new HttpHead(uri)); httpMethods.put("OPTIONS", new HttpOptions(uri)); httpMethods.put("POST", new HttpPost(uri)); httpMethods.put("PUT", new HttpPut(uri)); httpMethods.put("TRACE", new HttpTrace(uri)); HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase()); if (request.equals(null)) { throw new Error("SYNTAX_ERR"); } for (Object header : headers) { StringTokenizer st = new StringTokenizer((String) header, ":"); String name = st.nextToken(); String value = st.nextToken(); request.addHeader(name, value); } HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); Map headerMap = new HashMap(); HeaderIterator headerIter = response.headerIterator(); while (headerIter.hasNext()) { Header header = headerIter.nextHeader(); headerMap.put(header.getName(), header.getValue()); } int status = response.getStatusLine().getStatusCode(); String statusText = response.getStatusLine().toString(); is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } Map m = new HashMap(); m.put("status", new Integer(status)); m.put("statusText", statusText); m.put("responseText", sb.toString()); m.put("headers", headerMap.toString()); StringWriter w = new StringWriter(); JSONSerializer.serialize(w, m); json = w.toString(); logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]"); } catch (Throwable e) { logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest", "Failed request for [" + shrDataString + "]", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return json; }
From source file:org.dasein.cloud.aws.storage.S3Action.java
public HttpRequestBase getMethod(String url) { switch (this) { case OBJECT_EXISTS: return new HttpHead(url); case DELETE_BUCKET: case DELETE_OBJECT: return new HttpDelete(url); case LIST_BUCKETS: case LIST_CONTENTS: case LOCATE_BUCKET: case GET_OBJECT: case GET_ACL: return new HttpGet(url); case CREATE_BUCKET: case COPY_OBJECT: case PUT_OBJECT: case SET_ACL: return new HttpPut(url); }//from ww w . ja v a 2 s . co m return null; }
From source file:com.meschbach.psi.util.rest.PutRequest.java
@Override protected HttpUriRequest build(URI resource) { return new HttpPut(resource); }
From source file:org.jenkinsci.plugins.relution_publisher.net.requests.EntityRequest.java
private HttpUriRequest createHttpRequest(final Method method, final String uri, final HttpEntity entity) { switch (method) { default:/* w w w . j a v a2 s . c o m*/ case GET: return new HttpGet(uri); case POST: final HttpPost post = new HttpPost(uri); if (entity != null) { post.setEntity(entity); } return post; case PUT: final HttpPut put = new HttpPut(uri); if (entity != null) { put.setEntity(entity); } return put; case DELETE: return new HttpDelete(uri); } }
From source file:com.codota.uploader.Uploader.java
private void uploadFile(File file, String uploadUrl) throws IOException { HttpPut putRequest = new HttpPut(uploadUrl); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.addPart("code", new FileBody(file)); final HttpEntity entity = builder.build(); putRequest.setEntity(entity);/*from w w w . j ava 2 s. co m*/ putRequest.setHeader("enctype", "multipart/form-data"); putRequest.setHeader("authorization", "bearer " + token); httpClient.execute(putRequest, new UploadResponseHandler()); }
From source file:ecplugins.websphere.TestUtils.java
public static void setDefaultResourceAndWorkspace() throws Exception { if (!isResourceSetSuccessfully) { HttpClient httpClient = new DefaultHttpClient(); JSONObject jo = new JSONObject(); jo.put("projectName", "EC-WebSphere-" + StringConstants.PLUGIN_VERSION); jo.put("resourceName", StringConstants.RESOURCE_NAME); jo.put("workspaceName", StringConstants.WORKSPACE_NAME); HttpPut httpPutRequest = new HttpPut("http://" + props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/projects/" + "EC-WebSphere-" + StringConstants.PLUGIN_VERSION); StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPutRequest.setEntity(input); HttpResponse httpResponse = httpClient.execute(httpPutRequest); if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException("Failed to set default resource " + StringConstants.RESOURCE_NAME + " to project " + "EC-WebSphere-" + StringConstants.PLUGIN_VERSION); }//from w w w .jav a2 s. c o m System.out.println("Set the default resource as " + StringConstants.RESOURCE_NAME + " and default workspace as " + StringConstants.WORKSPACE_NAME + " successfully."); isResourceSetSuccessfully = true; } }
From source file:org.bishoph.oxdemo.util.RequestVisibleFolders.java
@Override protected JSONObject doInBackground(Object... params) { try {//from www . jav a2s. c o m String uri = (String) params[0]; Log.d("OXDemo", "Execute put request " + uri); HttpPut httput = new HttpPut(uri); httput.setHeader("Accept", "application/json, text/javascript"); HttpResponse response = httpclient.execute(httput, localcontext); HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); Log.d("OXDemo", "<<<<<<<\n" + result + "\n\n"); JSONObject jsonObj = new JSONObject(result); return jsonObj; } catch (JSONException e) { Log.e("OXDemo", e.getMessage()); } catch (ClientProtocolException e) { Log.e("OXDemo", e.getMessage()); } catch (IOException e) { Log.e("OXDemo", e.getMessage()); } return null; }
From source file:com.strato.hidrive.api.connection.httpgateway.request.JSONPutRequest.java
protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor) throws UnsupportedEncodingException { HttpPut httpPost = new HttpPut(requestUri); String jsonString = ""; if (jsonObject != null) { jsonString = jsonObject.toString(); } else if (jsonArray != null) { jsonString = jsonArray.toString(); }/*from w ww. j a v a2 s .c o m*/ StringEntity stringEntity = new StringEntity(jsonString); stringEntity.setContentType(CONTENT_TYPE_APPLICATION_JSON); httpPost.setEntity(stringEntity); return httpPost; }
From source file:com.google.resting.rest.client.BaseRESTClient.java
protected static HttpRequest buildHttpRequest(ServiceContext serviceContext) { String path = serviceContext.getPath(); Verb verb = serviceContext.getVerb(); HttpEntity httpEntity = serviceContext.getHttpEntity(); List<Header> headers = serviceContext.getHeaders(); if (verb == Verb.GET) { HttpGet httpGet = new HttpGet(path); if (headers != null) { for (Header header : headers) httpGet.addHeader(header); }//from w w w .j a v a 2s .c om return httpGet; } else if (verb == Verb.POST) { HttpPost httpPost = new HttpPost(path); if (headers != null) { for (Header header : headers) httpPost.addHeader(header); } if (httpEntity != null) httpPost.setEntity(httpEntity); return httpPost; } else if (verb == Verb.DELETE) { HttpDelete httpDelete = new HttpDelete(path); if (headers != null) { for (Header header : headers) httpDelete.addHeader(header); } return httpDelete; } else { HttpPut httpPut = new HttpPut(path); if (headers != null) { for (Header header : headers) httpPut.addHeader(header); } if (httpEntity != null) httpPut.setEntity(httpEntity); return httpPut; } //if }
From source file:org.sonatype.nexus.testsuite.deploy.nxcm970.ContinuousDeployer.java
public void run() { final HttpPut method = new HttpPut(targetUrl); method.setEntity(new InputStreamEntity(new EndlessBlockingInputStream(this), -1)); try {// w w w. j a va 2s . c om result = httpClient.execute(method).getStatusLine().getStatusCode(); } catch (Exception e) { result = -2; e.printStackTrace(); } }