List of usage examples for org.apache.commons.httpclient HttpMethod releaseConnection
public abstract void releaseConnection();
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
public int executeMethod(HostConfiguration hostConfiguration, HttpMethod method, boolean addCasTicket) throws IOException, HttpException { if (LOG.isDebugEnabled()) { LOG.debug("executeMethod(HostConfiguration, HttpMethod, boolean) - entering"); }//from w w w . ja va 2s . c om try { if (this.isAddCasTicketParams()) { HttpClientCAS.addCASTicket(method); } } catch (MotuCasException e) { throw new HttpException(e.notifyException(), e); } int returnint = 500; try { returnint = super.executeMethod(hostConfiguration, method); } catch (IOException e) { method.releaseConnection(); throw e; } if (LOG.isDebugEnabled()) { LOG.debug("executeMethod(HostConfiguration, HttpMethod, boolean) - exiting"); } return returnint; }
From source file:ensen.controler.DBpediaLookupClient.java
public String getOneResource(String query, String classes, int numberOfRes) throws Exception { HttpClient client = new HttpClient(); // client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); String query2 = URLEncoder.encode(query, "utf-8"); HttpMethod method = new GetMethod( gatway + "QueryString=" + query2 + "&QueryClass=" + classes + "&MaxHits=" + numberOfRes); // method.setFollowRedirects(true); try {/* w w w . ja v a 2s .com*/ client.executeMethod(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.out.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.out.println("Unable to connect to lookup.dbpedia.org"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } method.releaseConnection(); String resource = ""; int num_results = Results.size(); if (num_results > 0) { for (DBpediaLookupResModel res : Results) { resource = URLDecoder.decode(res.uri); /* * if (res.uri.contains("http://")) { Resource O = * model.createResource(res.uri); Property P = * model.createProperty("http://ensen.org/data#has-a"); Literal * O1 = model.createLiteral(res.label + ""); Literal O2 = * model.createLiteral(res.desc + ""); Property P1 = * model.createProperty * ("http://www.w3.org/2000/01/rdf-schema#label"); Property P2 = * model.createProperty( * "http://www.w3.org/1999/02/22-rdf-syntax-ns#description"); * O.addProperty(P1, O1); O.addProperty(P2, O2); * * for (String cat : res.cats) { Resource OO = * model.createResource(cat); Property PP = * model.createProperty("http://purl.org/dc/terms/subject"); * O.addProperty(PP, OO); } for (String c : res.classes) { * Resource OO = model.createResource(c); Property PP = * model.createProperty * ("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); * O.addProperty(PP, OO); } core.addProperty(P, O); * * } */ } } return resource; }
From source file:ensen.controler.DBpediaLookupClient.java
public Model qetEntities(String query, String classes, int numberOfRes) throws Exception { HttpClient client = new HttpClient(); // client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); String query2 = URLEncoder.encode(query, "utf-8"); HttpMethod method = new GetMethod( gatway + "QueryString=" + query2 + "&QueryClass=" + classes + "&MaxHits=" + numberOfRes); // method.setFollowRedirects(true); try {/*from w ww . j a v a2s. co m*/ client.executeMethod(method); InputStream ins = method.getResponseBodyAsStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser sax = factory.newSAXParser(); sax.parse(ins, this); } catch (HttpException he) { System.out.println("Http error connecting to lookup.dbpedia.org"); } catch (IOException ioe) { System.out.println("Unable to connect to lookup.dbpedia.org"); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } method.releaseConnection(); Model model = ModelFactory.createDefaultModel(); Resource core = model.createResource("http://ensen.org/data#q-" + query2); int num_results = Results.size(); if (num_results > 0) { for (DBpediaLookupResModel res : Results) { // System.out.println("URI: " + res.uri); if (res.uri.contains("http://")) { Resource O = model.createResource(res.uri); Property P = model.createProperty("http://ensen.org/data#has-a"); Literal O1 = model.createLiteral(res.label + ""); Literal O2 = model.createLiteral(res.desc + ""); Property P1 = model.createProperty("http://www.w3.org/2000/01/rdf-schema#label"); Property P2 = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#description"); O.addProperty(P1, O1); O.addProperty(P2, O2); for (String cat : res.cats) { Resource OO = model.createResource(cat); Property PP = model.createProperty("http://purl.org/dc/terms/subject"); O.addProperty(PP, OO); } for (String c : res.classes) { Resource OO = model.createResource(c); Property PP = model.createProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); O.addProperty(PP, OO); } core.addProperty(P, O); } } } return model; }
From source file:com.isencia.passerelle.model.util.RESTFacade.java
private String invokeMethodForURL(HttpMethod method) { try {/*from w w w . java 2s .co m*/ // Execute the method. int statusCode = httpClient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { logger.warn("Response status error : " + method.getStatusLine()); } String response = method.getResponseBodyAsString(); if (logger.isDebugEnabled()) { logger.debug("Received response\n" + response); } return response; } catch (HttpException e) { logger.error("Fatal protocol violation: ", e); return null; } catch (IOException e) { logger.error("Fatal transport error: ", e); return null; } finally { // Release the connection. method.releaseConnection(); } }
From source file:com.universalmind.core.components.mockup.loremipsum.SchmIpsumService.java
@Test public void testService() { String schmipsumSource = "bible"; Integer paragraphs = 2;/* w w w .j a v a 2 s . c om*/ String loremText = null; String url = null; url = "http://www.schmipsum.com/ipsum/" + schmipsumSource + "/" + (paragraphs * 100); HttpMethod method = null; HttpClient client = new HttpClient(); try { method = new GetMethod(url); int statusCode = client.executeMethod(method); byte[] responseBody = method.getResponseBody(); // Create a response handler //ResponseHandler<String> responseHandler = new BasicResponseHandler(); //String responseBody = httpclient.execute(httpget, responseHandler); loremText = parseBaseballIpsum(new String(responseBody)); Assert.assertNotNull(loremText); Assert.assertTrue(loremText.length() > 100); } catch (Exception jse) { //do nothing } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources //httpclient.getConnectionManager().shutdown(); if (method != null) { method.releaseConnection(); } } }
From source file:com.bonitasoft.connector.Trello_Get_BoardImpl.java
@Override protected void executeBusinessLogic() throws ConnectorException { // Get access to the connector input parameters // getBoard(); // getToken(); // getApiKey(); HttpMethod method = null; try {//from w ww . j a va 2 s .c om HttpClient client = new HttpClient(); method = new GetMethod(String.format(GET_TRELLO_BOARD_URL, getBoard(), getApiKey(), getToken())); method.addRequestHeader(new Header("Content-Type", "application/json; charset=UTF-8")); client.executeMethod(method); JSONArray array = getJSONFromResponse(method); List<Map<String, Object>> result = generateBaseStructure(array); setTrelloList(result); setBonitaColumn(TITLES); setBonitaList(getBonitaTableList(result)); setStringCSV(generateCSVFromList(result)); } catch (Exception e) { throw new ConnectorException(e.getMessage()); } finally { try { method.releaseConnection(); } catch (Exception e) { logger.severe("There is a problem releasing Trello Connection"); } } }
From source file:com.kylinolap.job.tools.HadoopStatusChecker.java
private String getHttpResponse(String url) throws IOException { HttpClient client = new HttpClient(); String response = null;//from w w w. j a v a 2 s. com while (response == null) { // follow redirects via 'refresh' if (url.startsWith("https://")) { registerEasyHttps(); } if (url.contains("anonymous=true") == false) { url += url.contains("?") ? "&" : "?"; url += "anonymous=true"; } HttpMethod get = new GetMethod(url); client.executeMethod(get); String redirect = null; Header h = get.getResponseHeader("Refresh"); if (h != null) { String s = h.getValue(); int cut = s.indexOf("url="); if (cut >= 0) { redirect = s.substring(cut + 4); } } if (redirect == null) { response = get.getResponseBodyAsString(); output.append("Job " + mrJobID + " get status check result.\n"); log.debug("Job " + mrJobID + " get status check result.\n"); } else { url = redirect; output.append("Job " + mrJobID + " check redirect url " + url + ".\n"); log.debug("Job " + mrJobID + " check redirect url " + url + ".\n"); } get.releaseConnection(); } return response; }
From source file:com.zimbra.cs.dav.client.WebDavClient.java
public Collection<DavObject> sendMultiResponseRequest(DavRequest req) throws IOException, DavException { ArrayList<DavObject> ret = new ArrayList<DavObject>(); HttpMethod m = null; try {/* w ww. j a va 2s .com*/ m = executeFollowRedirect(req); int status = m.getStatusCode(); if (status >= 400) { throw new DavException("DAV server returned an error: " + status, status); } Document doc = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(m.getResponseBodyAsStream()); Element top = doc.getRootElement(); for (Object obj : top.elements(DavElements.E_RESPONSE)) { if (obj instanceof Element) { ret.add(new DavObject((Element) obj)); } } } catch (XmlParseException e) { throw new DavException("can't parse response", e); } finally { if (m != null) { m.releaseConnection(); } } return ret; }
From source file:com.dtolabs.client.utils.HttpClientChannel.java
private HttpMethod checkFollowRedirect(final HttpMethod method, final int res) throws IOException, HttpClientException { if ((res == HttpStatus.SC_MOVED_TEMPORARILY) || (res == HttpStatus.SC_MOVED_PERMANENTLY) || (res == HttpStatus.SC_SEE_OTHER) || (res == HttpStatus.SC_TEMPORARY_REDIRECT)) { final Header locHeader = method.getResponseHeader("Location"); if (locHeader == null) { throw new HttpClientException("Redirect with no Location header, request URL: " + method.getURI()); }// w w w . j a v a2s . c om final String location = locHeader.getValue(); logger.debug("Follow redirect: " + res + ": " + location); method.releaseConnection(); final GetMethod followMethod = new GetMethod(location); followMethod.setFollowRedirects(true); resultCode = httpc.executeMethod(followMethod); reasonCode = followMethod.getStatusText(); logger.debug("Result: " + resultCode); return followMethod; } return method; }
From source file:be.ibridge.kettle.trans.step.http.HTTP.java
private Value callHttpService(Row row) throws KettleException { String url = determineUrl(row); try {/*from w ww.j a va 2s. c o m*/ logDetailed("Connecting to : [" + url + "]"); // Prepare HTTP get // HttpClient httpclient = new HttpClient(); HttpMethod method = new GetMethod(url); // Execute request // try { int result = httpclient.executeMethod(method); // The status code log.logDebug(toString(), "Response status code: " + result); // the response InputStream inputStream = method.getResponseBodyAsStream(); StringBuffer bodyBuffer = new StringBuffer(); int c; while ((c = inputStream.read()) != -1) bodyBuffer.append((char) c); inputStream.close(); String body = bodyBuffer.toString(); log.logDebug(toString(), "Response body: " + body); return new Value(meta.getFieldName(), body); } finally { // Release current connection to the connection pool once you are done method.releaseConnection(); } } catch (Exception e) { throw new KettleException("Unable to get result from specified URL :" + url, e); } }