List of usage examples for org.apache.commons.httpclient DefaultMethodRetryHandler DefaultMethodRetryHandler
DefaultMethodRetryHandler
From source file:net.mumie.cocoon.msg.AbstractPostMessage.java
/** * Sends this message.// ww w . ja v a2 s .co m */ public boolean send() { final String METHOD_NAME = "send"; this.logDebug(METHOD_NAME + " 1/3: Started"); boolean success = true; MessageDestinationTable destinationTable = null; SimpleHttpClient httpClient = null; try { // Init services: destinationTable = (MessageDestinationTable) this.serviceManager.lookup(MessageDestinationTable.ROLE); httpClient = (SimpleHttpClient) this.serviceManager.lookup(SimpleHttpClient.ROLE); // Get destination: MessageDestination destination = destinationTable.getDestination(this.destinationName); // Create and setup a Http Post method object: PostMethod method = new PostMethod(destination.getURL()); DefaultMethodRetryHandler retryHandler = new DefaultMethodRetryHandler(); retryHandler.setRequestSentRetryEnabled(false); retryHandler.setRetryCount(3); method.setMethodRetryHandler(retryHandler); // Set login name and password: method.addParameter("name", destination.getLoginName()); method.addParameter("password", destination.getPassword()); // Specific setup: this.init(method, destination); // Execute method: try { if (httpClient.executeMethod(method) != HttpStatus.SC_OK) { this.logError(METHOD_NAME + ": Failed to send message: " + method.getStatusLine()); success = false; } String response = new String(method.getResponseBody()); if (response.trim().startsWith("ERROR")) { this.logError(METHOD_NAME + ": Failed to send message: " + response); success = false; } this.logDebug(METHOD_NAME + " 2/3: response = " + response); } finally { method.releaseConnection(); } } catch (Exception exception) { this.logError(METHOD_NAME, exception); success = false; } finally { if (httpClient != null) this.serviceManager.release(httpClient); if (destinationTable != null) this.serviceManager.release(destinationTable); } this.logDebug(METHOD_NAME + " 3/3: Done. success = " + success); return success; }
From source file:org.bench4Q.agent.rbe.HttpClientFactory.java
/** * get a HttpClient./*w ww . j ava 2 s.c o m*/ * * @return HttpClient */ public static HttpClient getInstance() { if (m_client == null) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setMaxConnectionsPerHost(10000); connectionManager.setMaxTotalConnections(10000); m_client = new HttpClient(connectionManager); DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRetryCount(DEFAULT_RETRY_COUNT); m_client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); } return m_client; }
From source file:org.bench4Q.agent.rbe.HttpClientFactory.java
/** * set retry count.// w w w. j a v a 2 s .c om * * @param count */ public static void setRetryCount(int count) { if (m_client != null) { DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(); retryhandler.setRetryCount(count); m_client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); } }