List of usage examples for org.apache.commons.httpclient HttpMethod isRequestSent
public abstract boolean isRequestSent();
From source file:org.apache.axis2.mtom.EchoRawMTOMFaultReportTest.java
public void testEchoFaultSync() throws Exception { HttpClient client = new HttpClient(); PostMethod httppost = new PostMethod( "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/EchoService/mtomSample"); HttpMethodRetryHandler myretryhandler = new HttpMethodRetryHandler() { public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= 10) { return false; }// www .j av a 2s . c o m if (exception instanceof NoHttpResponseException) { return true; } if (!method.isRequestSent()) { return true; } // otherwise do not retry return false; } }; httppost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler); httppost.setRequestEntity(new InputStreamRequestEntity( new FileInputStream(TestingUtils.prefixBaseDirectory("test-resources/mtom/wmtom.bin")))); httppost.setRequestHeader("Content-Type", "multipart/related; boundary=--MIMEBoundary258DE2D105298B756D; type=\"application/xop+xml\"; start=\"<0.15B50EF49317518B01@apache.org>\"; start-info=\"application/soap+xml\""); try { client.executeMethod(httppost); if (httppost.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) { // TODO: There is a missing wsa:Action header in the SOAP message. Fix or look for correct fault text! // assertEquals("HTTP/1.1 500 Internal server error", // httppost.getStatusLine().toString()); } } catch (NoHttpResponseException e) { } finally { httppost.releaseConnection(); } }
From source file:org.archive.crawler.fetcher.FetchHTTP.java
/** * Cleanup after a failed method execute. * @param curi CrawlURI we failed on.//w ww. j a v a 2 s . com * @param method Method we failed on. * @param exception Exception we failed with. */ private void failedExecuteCleanup(final HttpMethod method, final CrawlURI curi, final Exception exception) { cleanup(curi, exception, "executeMethod", (method.isRequestSent() ? S_CONNECT_LOST : S_CONNECT_FAILED)); method.releaseConnection(); }
From source file:org.colombbus.tangara.net.HttpConnRetryHandler.java
@Override public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { LOG.info("Try number " + executionCount); if (executionCount >= maxRetries) { LOG.warn("Too many tries (" + executionCount + ")", exception); // Do not retry if over max retry count return false; }//from w ww . j a v a 2s. c om if (exception instanceof NoHttpResponseException) { LOG.error("No response from the server. No more tries", exception); // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { LOG.error("Request not sent. No more tries", exception); // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry LOG.error("Source of the HTTP failure not identified. No more tries", exception); return false; }
From source file:org.jasig.portlet.weather.dao.worldwide.WorldWeatherOnlineDaoImpl.java
public void afterPropertiesSet() throws Exception { final HttpConnectionManager httpConnectionManager = httpClient.getHttpConnectionManager(); final HttpConnectionManagerParams params = httpConnectionManager.getParams(); params.setConnectionTimeout(connectionTimeout); params.setSoTimeout(readTimeout);/*ww w .j a v a2s .c o m*/ params.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= timesToRetry) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (exception instanceof SocketException) { // Retry if the server reset connection on us return true; } if (exception instanceof SocketTimeoutException) { // Retry if the read timed out return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }); }
From source file:org.portletbridge.portlet.DefaultHttpClientTemplate.java
/** * /*from w w w . ja va2s.c o m*/ */ private DefaultHttpClientTemplate(Builder b) { retryCount = b.retryCount; connectionTimeout = b.connectionTimeout; readTimeoutMillis = b.readTimeoutMillis; httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(readTimeoutMillis); HttpMethodRetryHandler retryhandler = new HttpMethodRetryHandler() { public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= retryCount) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (exception instanceof SocketException) { // Retry if the server reset connection on us return true; } if (exception instanceof SocketTimeoutException) { // Retry if the read timed out return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; httpClient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); }
From source file:org.roosster.RoossterTestCase.java
/** * // www . j a v a 2 s . c om */ public void logMethodResponse(HttpMethod method) throws java.io.IOException { if (method == null) throw new IllegalArgumentException("FAILED: Tried to log 'null' method"); if (method.isRequestSent() == false) throw new IllegalArgumentException("FAILED: Tried to log 'not-sent' method"); System.out.println("++++++++++++++++++++++++ BEGIN HEADER LOGGING ++++++++++++++++++++++++"); StatusLine sline = method.getStatusLine(); System.out.println("\nStatusLine: " + sline.getHttpVersion() + " " + sline.getStatusCode() + " " + sline.getReasonPhrase()); System.out.println("\nHeader:\n"); Header[] headers = method.getResponseHeaders(); for (int i = 0; i < headers.length; i++) { System.out.println(headers[i].toString()); } System.out.println("\nResponseBody:\n" + method.getResponseBodyAsString() + "\n\n"); System.out.println("++++++++++++++++++++++++ END HEADER LOGGING ++++++++++++++++++++++++\n\n"); }