return false; } finally { redirectedReq.releaseConnection();
protected <T> String executeUpdateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException, IllegalArgumentException{ checkInvariants(); PutMethod pm = (PutMethod)createMethod("put", uri, _port); setHttpHeader(pm); try { pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null)); } catch (UnsupportedEncodingException e) { throw new BigSwitchBcfApiException("Failed to encode json request body", e); } executeMethod(pm); String hash = checkResponse(pm, "BigSwitch HTTP update failed: "); pm.releaseConnection(); return hash; }
protected String executePut(final String uri) throws NeutronRestApiException { try { validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class); PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri); try { String encodedCredentials = encodeCredentials(); putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(putMethod); if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } return putMethod.getResponseBodyAsString(); } catch (NeutronRestApiException e) { s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { throw new NeutronRestApiException("Failed to load json response body", e); } finally { putMethod.releaseConnection(); } }
protected void executePut(final String uri, final StringRequestEntity entity) throws NeutronRestApiException { try { validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class); PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri); try { putMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); putMethod.setRequestEntity(entity); String encodedCredentials = encodeCredentials(); putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(putMethod); if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } } catch (NeutronRestApiException e) { s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { putMethod.releaseConnection(); } }
private String eval(String input) { BufferedReader reader; String sessionUrl = url.toString() + sessionId; PutMethod method = new PutMethod(sessionUrl); String result = ""; try { RequestEntity entity = new StringRequestEntity(input, "text/plain", "UTF-8"); method.setRequestEntity(entity); client.executeMethod(method); reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); String line; while (((line = reader.readLine()) != null)) { result = result + line; } } catch (HttpException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } return result; }
e.printStackTrace(); } finally { putMethod.releaseConnection();
public String doPut(String url, String charset, String jsonObj) { String resStr = null; HttpClient htpClient = new HttpClient(); PutMethod putMethod = new PutMethod(url); putMethod.getParams().setParameter( HttpMethodParams.HTTP_CONTENT_CHARSET, charset); try { putMethod.setRequestEntity(new StringRequestEntity(jsonObj, "application/json", charset)); int statusCode = htpClient.executeMethod(putMethod); if (statusCode != HttpStatus.SC_OK) { log.error("Method failed: " + putMethod.getStatusLine()); return null; } byte[] responseBody = putMethod.getResponseBody(); resStr = new String(responseBody, charset); } catch (Exception e) { log.error(e.getMessage(),e); } finally { putMethod.releaseConnection(); } return resStr; } }
put.releaseConnection(); Log_OC.e(TAG, "Exception while updating remote share ", e); if (put != null) { put.releaseConnection(); put.releaseConnection();
putMethod.releaseConnection(); // let the connection available for other methods putMethod.releaseConnection(); // let the connection available for other methods
protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { int status; RemoteOperationResult result; try { File f = new File(localPath); entity = new FileRequestEntity(f, mimeType); synchronized (dataTransferListeners) { ((ProgressiveDataTransfer) entity) .addDataTransferProgressListeners(dataTransferListeners); } if (requiredEtag != null && requiredEtag.length() > 0) { putMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + requiredEtag + "\""); } putMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(f.length())); putMethod.addRequestHeader(OC_X_OC_MTIME_HEADER, lastModificationTimestamp); putMethod.setRequestEntity(entity); status = client.executeMethod(putMethod); result = new RemoteOperationResult(isSuccess(status), putMethod); client.exhaustResponse(putMethod.getResponseBodyAsStream()); } finally { putMethod.releaseConnection(); // let the connection available for other methods } return result; }
public ApplicationServerManagerResult deploy(String appPath, InputStream is, int size) throws IOException { try { deploy.setQueryString(buildPathQueryArgs(appPath)); deploy.setContentChunked(true); deploy.setRequestEntity(new InputStreamRequestEntity(is)); client.executeMethod(deploy); return parseResult(deploy.getResponseBodyAsString()); } finally { deploy.releaseConnection(); deploy.setPath(deployPath); } }
protected PutMethod internalCreateOrUpdate(String encodedHref, byte[] mimeContent) throws IOException { PutMethod putmethod = new PutMethod(encodedHref); putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Overwrite", "f"); if (etag != null) { putmethod.setRequestHeader("If-Match", etag); } if (noneMatch != null) { putmethod.setRequestHeader("If-None-Match", noneMatch); } putmethod.setRequestHeader("Content-Type", "message/rfc822"); putmethod.setRequestEntity(new ByteArrayRequestEntity(mimeContent, "message/rfc822")); try { httpClient.executeMethod(putmethod); } finally { putmethod.releaseConnection(); } return putmethod; }
public void upload(File src, URL dest, CopyProgressListener l) throws IOException { HttpClient client = getClient(); PutMethod put = new PutMethod(normalizeToString(dest)); put.setDoAuthentication(useAuthentication(dest) || useProxyAuthentication()); put.getParams().setBooleanParameter("http.protocol.expect-continue", true); try { put.setRequestEntity(new FileRequestEntity(src)); int statusCode = client.executeMethod(put); validatePutStatusCode(dest, statusCode, null); } finally { put.releaseConnection(); } }
} finally { if (putMethod != null) putMethod.releaseConnection();
/** * Send a PUT request * @param cluster the cluster definition * @param path the path or URI * @param headers the HTTP headers to include, <tt>Content-Type</tt> must be * supplied * @param content the content bytes * @return a Response object with response detail * @throws IOException */ public Response put(Cluster cluster, String path, Header[] headers, byte[] content) throws IOException { PutMethod method = new PutMethod(); try { method.setRequestEntity(new ByteArrayRequestEntity(content)); int code = execute(cluster, method, headers, path); headers = method.getResponseHeaders(); content = method.getResponseBody(); return new Response(code, headers, content); } finally { method.releaseConnection(); } }