List of usage examples for org.apache.commons.httpclient HttpMethodBase releaseConnection
@Override public void releaseConnection()
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
@Override public OperatorDTO getOperator(Long operatorId) { String url = String.format(baseUrl + OPERATOR, operatorId); HttpMethodBase method = createGetMethod(url); try {// w w w. ja v a2 s . co m // Execute the method. InputStream body = execute(method); if (body == null) { return null; } return parseJson(body, OperatorDTO.class); } catch (Exception e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:com.bdaum.juploadr.uploadapi.smugrest.SmugmugMethod.java
public boolean execute() throws ProtocolException, CommunicationException { HttpMethodBase method = getMethod(); boolean rv = false; try {//from ww w .j a v a 2s . c om int response = client.executeMethod(method); if (HttpStatus.SC_OK == response) { rv = parseResponse(method.getResponseBodyAsString()); } else { throw new CommunicationException(Messages.getString("juploadr.ui.error.bad.http.response", //$NON-NLS-1$ Activator.getStatusText(response))); } } catch (HttpException e) { throw new CommunicationException(e.getMessage(), e); } catch (IOException e) { throw new CommunicationException(e.getMessage(), e); } finally { method.releaseConnection(); } return rv; }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
private String getOperatorConfig(Long operatorId, OperatorConfigParamDTO param) { String val; String url = String.format(baseUrl + OPERATOR_CONFIG_PARAM, operatorId, param.name()); HttpMethodBase method = createGetMethod(url); try {/*from w w w . j av a 2s .c om*/ InputStream body = execute(method); if (body == null) { return null; } val = new java.util.Scanner(body).useDelimiter("\\A").next(); } catch (Exception e) { logger.error("unable to get " + url); throw new RuntimeException(e); } finally { method.releaseConnection(); } return val; }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
@Override public List<OperatorDTO> getOperators() { HttpMethodBase method = createGetMethod(baseUrl + OPERATOR_LIST); try {/*from w w w . jav a 2s .co m*/ // Execute the method. InputStream body = execute(method); if (body == null) { return null; } return this.<List<OperatorDTO>>parseList(body, new TypeReference<List<OperatorDTO>>() { }); } catch (Exception e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:de.avanux.livetracker.sender.LocationSender.java
private String executeHttpMethod(HttpMethodBase method) { String response = null;//from ww w . jav a 2 s . com HttpClient client = new HttpClient(); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); response = new String(responseBody); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } return response; }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
@SuppressWarnings("unchecked") protected Map<OperatorConfigParamDTO, String> loadOperatorConfigForClients(Long operatorId) { String url = String.format(baseUrl + OPERATOR_CLIENT_CONFIG_MAP, operatorId); HttpMethodBase method = createGetMethod(url); try {//from ww w .ja v a 2s . c o m InputStream body = execute(method); if (body == null) { return new HashMap<OperatorConfigParamDTO, String>(); } return (Map<OperatorConfigParamDTO, String>) parseJson(body, Map.class); } catch (Exception e) { logger.error("unable to get " + url); throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:com.cubeia.backoffice.operator.client.OperatorServiceClientHTTP.java
@Override public Map<OperatorConfigParamDTO, String> getConfig(Long operatorId) { String url = String.format(baseUrl + OPERATOR_CONFIG_MAP, operatorId); HttpMethodBase method = createGetMethod(url); try {//from w w w . j av a 2 s . c o m // Execute the method. InputStream body = execute(method); if (body == null) { return null; } return this.<Map<OperatorConfigParamDTO, String>>parseList(body, new TypeReference<Map<OperatorConfigParamDTO, String>>() { }); } catch (Exception e) { throw new RuntimeException(e); } finally { method.releaseConnection(); } }
From source file:com.sittinglittleduck.DirBuster.Worker.java
/** Run method of the thread */ public void run() { queue = manager.workQueue;/*ww w. jav a 2 s . c o m*/ while (manager.hasWorkLeft()) { working = false; // code to make the worker pause, if the pause button has been presed // if the stop signal has been given stop the thread if (stop) { return; } // this pauses the thread synchronized (this) { while (pleaseWait) { try { wait(); } catch (InterruptedException e) { return; } catch (Exception e) { e.printStackTrace(); } } } HttpMethodBase httpMethod = null; try { work = (WorkUnit) queue.take(); working = true; url = work.getWork(); int code = 0; String response = ""; String rawResponse = ""; httpMethod = createHttpMethod(work.getMethod(), url.toString()); // if the work is a head request if (work.getMethod().equalsIgnoreCase("HEAD")) { code = makeRequest(httpMethod); httpMethod.releaseConnection(); } // if we are doing a get request else if (work.getMethod().equalsIgnoreCase("GET")) { code = makeRequest(httpMethod); String rawHeader = getHeadersAsString(httpMethod); response = getResponseAsString(httpMethod); rawResponse = rawHeader + response; // clean the response if (Config.parseHTML && !work.getBaseCaseObj().isUseRegexInstead()) { parseHtml(httpMethod, response); } response = FilterResponce.CleanResponce(response, work); Thread.sleep(10); httpMethod.releaseConnection(); } // if we need to check the against the base case if (work.getMethod().equalsIgnoreCase("GET") && work.getBaseCaseObj().useContentAnalysisMode()) { if (code == HttpStatus.SC_OK) { verifyResponseForValidRequests(code, response, rawResponse); } else if (code == HttpStatus.SC_NOT_FOUND || code == HttpStatus.SC_BAD_REQUEST) { if (Config.debug) { System.out .println("DEBUG Worker[" + threadId + "]: " + code + " for: " + url.toString()); } } else { notifyItemFound(code, response, rawResponse, work.getBaseCaseObj().getBaseCase()); } } /* * use the custom regex check instead */ else if (work.getBaseCaseObj().isUseRegexInstead()) { Pattern regexFindFile = Pattern.compile(work.getBaseCaseObj().getRegex()); Matcher m = regexFindFile.matcher(rawResponse); if (m.find()) { // do nothing as we have a 404 if (Config.debug) { System.out.println("DEBUG Worker[" + threadId + "]: Regex matched so it's a 404, " + url.toString()); } } else { if (Config.parseHTML) { parseHtml(httpMethod, rawResponse); } notifyItemFound(code, response, rawResponse, work.getBaseCaseObj().getBaseCase()); } } // just check the response code else { // if is not the fail code, a 404 or a 400 then we have a possible if (code != work.getBaseCaseObj().getFailCode() && verifyIfCodeIsValid(code)) { if (work.getMethod().equalsIgnoreCase("HEAD")) { httpMethod = createHttpMethod("GET", url.toString()); int newCode = makeRequest(httpMethod); // in some cases the second get can return a different result, than the // first head request! if (newCode != code) { manager.foundError(url, "Return code for first HEAD, is different to the second GET: " + code + " - " + newCode); } // build a string version of the headers rawResponse = getHeadersAsString(httpMethod); if (httpMethod.getResponseContentLength() > 0) { String responseBodyAsString = getResponseAsString(httpMethod); rawResponse = rawResponse + responseBodyAsString; if (Config.parseHTML) { parseHtml(httpMethod, responseBodyAsString); } } httpMethod.releaseConnection(); } if (work.isDir()) { manager.foundDir(url, code, rawResponse, work.getBaseCaseObj()); } else { manager.foundFile(url, code, rawResponse, work.getBaseCaseObj()); } } } manager.workDone(); Thread.sleep(20); } catch (NoHttpResponseException e) { manager.foundError(url, "NoHttpResponseException " + e.getMessage()); manager.workDone(); } catch (ConnectTimeoutException e) { manager.foundError(url, "ConnectTimeoutException " + e.getMessage()); manager.workDone(); } catch (URIException e) { manager.foundError(url, "URIException " + e.getMessage()); manager.workDone(); } catch (IOException e) { manager.foundError(url, "IOException " + e.getMessage()); manager.workDone(); } catch (InterruptedException e) { // manager.foundError(url, "InterruptedException " + e.getMessage()); manager.workDone(); return; } catch (IllegalArgumentException e) { e.printStackTrace(); manager.foundError(url, "IllegalArgumentException " + e.getMessage()); manager.workDone(); } finally { if (httpMethod != null) { httpMethod.releaseConnection(); } } } }
From source file:com.google.enterprise.connector.sharepoint.client.SiteDataHelper.java
/** * Makes a call to Site Data web service to retrieve site meta data and create * a SPDocuemnt and it returns a single SPDcoument.This method returns null if * and only if any one of SiteData stub or webState is null. * * @param webState The web from which we need to construct SPDcoument for it's * landing page./*from w w w .j av a 2s . co m*/ * @return a single SPDocument for the given web. */ public SPDocument getSiteData(final WebState webState) { if (webState == null) { LOGGER.warning("Unable to get the list collection because webstate is null"); // in case if the web state is null and is not existing in SharePoint // server. return null; } final _sWebMetadataHolder sWebMetadata = getWebMetadata(); if (sWebMetadata == null) { LOGGER.warning("Unable to get site data. The call to getSiteData returned null."); return null; } final SPDocument siteDataDocument = new SPDocument( webState.getPrimaryKey() + SPConstants.DEFAULT_SITE_LANDING_PAGE + SPConstants.DOC_TOKEN + sWebMetadata.value.getWebID(), webState.getWebUrl() + SPConstants.DEFAULT_SITE_LANDING_PAGE, sWebMetadata.value.getLastModified(), sWebMetadata.value.getAuthor(), SPConstants.SITE, webState.getTitle(), sharepointClientContext.getFeedType(), webState.getSharePointType()); String strUrl = Util.encodeURL(siteDataDocument.getUrl()); HttpMethodBase method = new HeadMethod(strUrl); try { int responseCode = sharepointClientContext.checkConnectivity(strUrl, method); if (responseCode != 200) { LOGGER.log(Level.INFO, "Possible Publishing website. Marking Url [ " + strUrl + " ] with Document Type as ACL"); siteDataDocument.setDocumentType(DocumentType.ACL); } } catch (final Exception e) { LOGGER.log(Level.WARNING, "Unable to connect [ " + strUrl + " ] marking site home page as ACL document", e); siteDataDocument.setDocumentType(DocumentType.ACL); } finally { method.releaseConnection(); } return siteDataDocument; }
From source file:com.jaspersoft.ireport.jasperserver.ws.CommonsHTTPSender.java
private InputStream createConnectionReleasingInputStream(final HttpMethodBase method) throws IOException { return new FilterInputStream(method.getResponseBodyAsStream()) { public void close() throws IOException { try { super.close(); } finally { method.releaseConnection(); }/*from w w w .ja va 2 s .c o m*/ } }; }