List of usage examples for org.apache.http.client.methods HttpPut HttpPut
public HttpPut(final String uri)
From source file:org.talend.dataprep.api.service.command.preparation.PreparationUpdate.java
private HttpRequestBase onExecute(String id, Preparation preparation) { try {//from w ww. ja v a 2 s . com final byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation); final HttpPut preparationCreation = new HttpPut(preparationServiceUrl + "/preparations/" + id); preparationCreation.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE); preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue)); return preparationCreation; } catch (JsonProcessingException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:net.gcolin.httpquery.HttpHandlerImpl.java
@Override public RequestWithPayload put(String uri, Object obj) { return new RequestWithPayloadImpl(new HttpPut(uri), obj); }
From source file:revServTest.IoTTestForPUT.java
public String testPut(String url0, StringEntity input) { String result;// www . j ava 2 s . c o m HttpResponse response = null; try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPut putRequest = new HttpPut(url0); input.setContentType("application/xml"); putRequest.setEntity(input); response = httpClient.execute(putRequest); if (response.getStatusLine().getStatusCode() != 409 && response.getStatusLine().getStatusCode() != 201 && response.getStatusLine().getStatusCode() != 400 && response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 404 && response.getStatusLine().getStatusCode() != 500) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } httpClient.getConnectionManager().shutdown(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // if (response.getStatusLine().getStatusCode() == 409 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 400 // || response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 404 || response.getStatusLine().getStatusCode() == 500) { // // result = RevocationOutCome.code; // // } else { // String res = Integer.toString(response.getStatusLine().getStatusCode()); // result = res; // } // return result; return RevocationOutCome.code; }
From source file:com.aliyun.oss.common.comm.HttpRequestFactory.java
public HttpRequestBase createHttpRequest(ServiceClient.Request request, ExecutionContext context) { String uri = request.getUri(); HttpRequestBase httpRequest;/*from w w w.j a v a 2 s . c om*/ HttpMethod method = request.getMethod(); if (method == HttpMethod.POST) { HttpPost postMethod = new HttpPost(uri); if (request.getContent() != null) { postMethod.setEntity(new RepeatableInputStreamEntity(request)); } httpRequest = postMethod; } else if (method == HttpMethod.PUT) { HttpPut putMethod = new HttpPut(uri); if (request.getContent() != null) { if (request.isUseChunkEncoding()) { putMethod.setEntity(buildChunkedInputStreamEntity(request)); } else { putMethod.setEntity(new RepeatableInputStreamEntity(request)); } } httpRequest = putMethod; } else if (method == HttpMethod.GET) { httpRequest = new HttpGet(uri); } else if (method == HttpMethod.DELETE) { httpRequest = new HttpDelete(uri); } else if (method == HttpMethod.HEAD) { httpRequest = new HttpHead(uri); } else if (method == HttpMethod.OPTIONS) { httpRequest = new HttpOptions(uri); } else { throw new ClientException("Unknown HTTP method name: " + method.toString()); } configureRequestHeaders(request, context, httpRequest); return httpRequest; }
From source file:org.talend.dataprep.command.preparation.UpdateStepRowMetadata.java
private HttpRequestBase onExecute(String preparationId, List<Step> steps) { try {// w w w.j a v a 2 s .c o m final String stepsAsJson = objectMapper.writeValueAsString(steps); final HttpPut updater = new HttpPut( preparationServiceUrl + "/preparations/" + preparationId + "/steps"); updater.setHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE); updater.setEntity(new StringEntity(stepsAsJson, APPLICATION_JSON)); return updater; } catch (JsonProcessingException e) { throw new TDPException(UNEXPECTED_EXCEPTION, e); } }
From source file:org.deviceconnect.android.profile.restful.test.NormalVibrationProfileTestCase.java
/** * Vibration????./* ww w . j a v a 2 s . c o m*/ * <pre> * ?HTTP * Method: PUT * Path: /vibration/vibrate?deviceid=xxxx * </pre> * <pre> * ?? * result?0??????? * </pre> */ public void testPutVibrate001() { StringBuilder builder = new StringBuilder(); builder.append(DCONNECT_MANAGER_URI); builder.append("/" + VibrationProfileConstants.PROFILE_NAME); builder.append("/" + VibrationProfileConstants.ATTRIBUTE_VIBRATE); builder.append("?"); builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId()); builder.append("&" + AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken()); builder.append("&"); builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); // ? ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(VibrationProfileConstants.PARAM_PATTERN, "100, 100, 100, 100")); ((HttpPut) request).setEntity(new UrlEncodedFormEntity(params, "UTF-8")); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } catch (Exception e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:com.mber.client.HTTParty.java
public static Call put(final String url, final JSONObject data) throws UnsupportedEncodingException, IOException { HttpPut request = new HttpPut(url); request.setEntity(toStringEntity(data)); return execute(request); }
From source file:org.openiot.gsn.http.rest.PushDelivery.java
public PushDelivery(String deliveryContactPoint, double notificaitonId, Writer writer) { httpPut = new HttpPut(deliveryContactPoint); this.writer = writer; this.notificationId = notificaitonId; }
From source file:org.deviceconnect.android.profile.restful.test.FailVibrationProfileTestCase.java
/** * deviceId??????.// w w w.j a v a 2 s .c o m * <pre> * ?HTTP * Method: PUT * Path: /vibration/vibrate * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutVibrateNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(VibrationProfileConstants.PROFILE_NAME); builder.setAttribute(VibrationProfileConstants.ATTRIBUTE_VIBRATE); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
From source file:retsys.client.http.HttpHelper.java
public HttpPut getHttpPutObj(String operation, String body) throws IOException { HttpPut put = null;/*from w ww . j a v a 2 s . co m*/ put = new HttpPut(getHttpUrl(hostName, hostPort, context) + "/" + operation); StringEntity se = new StringEntity(body); se.setContentEncoding("UTF-8"); se.setContentType("application/json"); put.setEntity(se); return put; }