List of usage examples for org.apache.commons.httpclient.methods PutMethod PutMethod
public PutMethod(String paramString)
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
@Override public HttpResponse putJson(String path, String putJsonBody, Map<String, String> headers, int timeoutMillis) throws HttpClientException { return executeMethodJson(new PutMethod(path), putJsonBody, headers, timeoutMillis); }
From source file:com.cellbots.remoteEyes.RemoteEyesActivity.java
private void uploadImage(byte[] imageData) { try {//from ww w .j ava2s .com YuvImage yuvImage = new YuvImage(imageData, previewFormat, previewWidth, previewHeight, null); yuvImage.compressToJpeg(r, 20, out); // Tweak the quality here - 20 // seems pretty decent for // quality + size. PutMethod put = new PutMethod(putUrl); put.setRequestBody(new ByteArrayInputStream(out.toByteArray())); put.execute(mHttpState, mConnection); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); resetConnection(); } catch (ClientProtocolException e) { e.printStackTrace(); resetConnection(); } catch (IOException e) { e.printStackTrace(); resetConnection(); } finally { out.reset(); if (mCamera != null) { mCamera.addCallbackBuffer(mCallbackBuffer); } isUploading = false; } }
From source file:net.sf.sail.webapp.domain.webservice.http.impl.HttpRestTransportImpl.java
/** * @see net.sf.sail.webapp.domain.webservice.http.HttpRestTransport#put(net.sf.sail.webapp.domain.webservice.http.HttpPutRequest) *///from w w w .j av a2 s. c o m public Map<String, String> put(final HttpPutRequest httpPutRequestData) throws HttpStatusCodeException { final PutMethod method = new PutMethod(this.baseUrl + httpPutRequestData.getRelativeUrl()); this.setHeaders(httpPutRequestData, method); // set body data final String bodyData = httpPutRequestData.getBodyData(); if (StringUtils.hasText(bodyData)) { method.setRequestEntity(new StringRequestEntity(bodyData)); } final Map<String, String> responseHeaders = new HashMap<String, String>(); try { // Execute the method. logRequest(method, bodyData); final int statusCode = this.client.executeMethod(method); httpPutRequestData.isValidResponseStatus(method, statusCode); final Header[] headers = method.getResponseHeaders(); for (int i = 0; i < headers.length; i++) { responseHeaders.put(headers[i].getName(), headers[i].getValue()); } } catch (HttpException e) { logAndThrowRuntimeException(e); } catch (IOException e) { logAndThrowRuntimeException(e); } finally { method.releaseConnection(); } return responseHeaders; }
From source file:com.sun.jersey.client.apache.ApacheHttpClientHandler.java
private HttpMethod getHttpMethod(ClientRequest cr) { final String strMethod = cr.getMethod(); final String uri = cr.getURI().toString(); if (strMethod.equals("GET")) { return new GetMethod(uri); } else if (strMethod.equals("POST")) { return new PostMethod(uri); } else if (strMethod.equals("PUT")) { return new PutMethod(uri); } else if (strMethod.equals("DELETE")) { return new CustomMethod("DELETE", uri); } else if (strMethod.equals("HEAD")) { return new HeadMethod(uri); } else if (strMethod.equals("OPTIONS")) { return new OptionsMethod(uri); } else {// w w w .ja v a 2s .c o m return new CustomMethod(strMethod, uri); } }
From source file:gov.va.vinci.leo.tools.JamService.java
/** * Remove a host/port from a service queue. * <p/>/* w ww . j a va 2s .com*/ * If the host is not part of the service queue, no-op. If it is * part of the Service Queue, it is removed. * @param queueName the name of the queue to remove. * @param brokerUrl the broker url this service is using. * @param host the host the service is running on. * @param port the port the service is running on. * * @throws IOException if any communication exception occurs. */ public void removeServerFromServiceQueue(final String queueName, final String brokerUrl, final String host, final int port) throws IOException { String requestBody = createJmxServerXml(queueName, brokerUrl, host, port); PutMethod method = new PutMethod(jamServerBaseUrl + "webservice/removeServerFromServiceQueue"); method.setRequestBody(requestBody); doHttpCall(method); }
From source file:com.nextcloud.android.sso.InputStreamBinder.java
private InputStream processRequest(final NextcloudRequest request) throws UnsupportedOperationException, com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { Account account = AccountUtils.getOwnCloudAccountByName(context, request.getAccountName()); // TODO handle case that account is not found! if (account == null) { throw new IllegalStateException(EXCEPTION_ACCOUNT_NOT_FOUND); }// www . j a v a 2 s. c om // Validate token if (!isValid(request)) { throw new IllegalStateException(EXCEPTION_INVALID_TOKEN); } // Validate URL if (request.getUrl().length() == 0 || request.getUrl().charAt(0) != PATH_SEPARATOR) { throw new IllegalStateException(EXCEPTION_INVALID_REQUEST_URL, new IllegalStateException("URL need to start with a /")); } OwnCloudClientManager ownCloudClientManager = OwnCloudClientManagerFactory.getDefaultSingleton(); OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); OwnCloudClient client = ownCloudClientManager.getClientFor(ocAccount, context); String requestUrl = client.getBaseUri() + request.getUrl(); HttpMethodBase method; switch (request.getMethod()) { case "GET": method = new GetMethod(requestUrl); break; case "POST": method = new PostMethod(requestUrl); if (request.getRequestBody() != null) { StringRequestEntity requestEntity = new StringRequestEntity(request.getRequestBody(), CONTENT_TYPE_APPLICATION_JSON, CHARSET_UTF8); ((PostMethod) method).setRequestEntity(requestEntity); } break; case "PUT": method = new PutMethod(requestUrl); if (request.getRequestBody() != null) { StringRequestEntity requestEntity = new StringRequestEntity(request.getRequestBody(), CONTENT_TYPE_APPLICATION_JSON, CHARSET_UTF8); ((PutMethod) method).setRequestEntity(requestEntity); } break; case "DELETE": method = new DeleteMethod(requestUrl); break; default: throw new UnsupportedOperationException(EXCEPTION_UNSUPPORTED_METHOD); } method.setQueryString(convertMapToNVP(request.getParameter())); method.addRequestHeader("OCS-APIREQUEST", "true"); client.setFollowRedirects(request.isFollowRedirects()); int status = client.executeMethod(method); // Check if status code is 2xx --> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success if (status >= HTTP_STATUS_CODE_OK && status < HTTP_STATUS_CODE_MULTIPLE_CHOICES) { return method.getResponseBodyAsStream(); } else { throw new IllegalStateException(EXCEPTION_HTTP_REQUEST_FAILED, new IllegalStateException(String.valueOf(status))); } }
From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java
@Override public void deleteRecommendations(String modelSetId, String simulationid, String userId) throws LpRestException { String contentType = "application/xml"; HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/bridge/notify/deleterecs/%s", DefaultRestResource.REST_URI, modelSetId);//from ww w. j a va 2 s . co m PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", contentType); NameValuePair[] queryString = new NameValuePair[2]; queryString[0] = new NameValuePair("simulationid", simulationid); queryString[1] = new NameValuePair("userid", userId); putMethod.setQueryString(queryString); try { httpClient.executeMethod(putMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:com.rometools.propono.atom.client.ClientMediaEntry.java
/** * Update entry on server.//from w ww. j ava 2 s.com */ @Override public void update() throws ProponoException { if (partial) { throw new ProponoException("ERROR: attempt to update partial entry"); } EntityEnclosingMethod method = null; final Content updateContent = getContents().get(0); try { if (getMediaLinkURI() != null && getBytes() != null) { // existing media entry and new file, so PUT file to edit-media URI method = new PutMethod(getMediaLinkURI()); if (inputStream != null) { method.setRequestEntity(new InputStreamRequestEntity(inputStream)); } else { method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(getBytes()))); } method.setRequestHeader("Content-type", updateContent.getType()); } else if (getEditURI() != null) { // existing media entry and NO new file, so PUT entry to edit URI method = new PutMethod(getEditURI()); final StringWriter sw = new StringWriter(); Atom10Generator.serializeEntry(this, sw); method.setRequestEntity(new StringRequestEntity(sw.toString(), null, null)); method.setRequestHeader("Content-type", "application/atom+xml; charset=utf8"); } else { throw new ProponoException("ERROR: media entry has no edit URI or media-link URI"); } getCollection().addAuthentication(method); method.addRequestHeader("Title", getTitle()); getCollection().getHttpClient().executeMethod(method); if (inputStream != null) { inputStream.close(); } final InputStream is = method.getResponseBodyAsStream(); if (method.getStatusCode() != 200 && method.getStatusCode() != 201) { throw new ProponoException( "ERROR HTTP status=" + method.getStatusCode() + " : " + Utilities.streamToString(is)); } } catch (final Exception e) { throw new ProponoException("ERROR: saving media entry"); } if (method.getStatusCode() != 201) { throw new ProponoException("ERROR HTTP status=" + method.getStatusCode()); } }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
@Override public void updateConfig(Long operatorId, Map<OperatorConfigParamDTO, String> config) { PutMethod method = new PutMethod(String.format(baseUrl + UPDATE_CONFIG, operatorId)); prepareMethod(method);/* www . j a v a2s . c om*/ try { String data = serialize(config); method.setRequestEntity(new StringRequestEntity(data, "application/json", "UTF-8")); // Execute the method. int statusCode = getClient().executeMethod(method); if (statusCode == HttpStatus.SC_NOT_FOUND) { return; } assertResponseCodeOK(method, statusCode); } catch (Exception e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
@Override public HttpResponse putBytes(String path, byte[] putBytes, int timeoutMillis) throws HttpClientException { return executeMethodBytes(new PutMethod(path), putBytes, timeoutMillis); }