You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2005/09/22 15:55:30 UTC
svn commit: r290945 - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http:
CommonsHTTPTransportSender.java HTTPConstants.java
Author: ruchithf
Date: Thu Sep 22 06:55:21 2005
New Revision: 290945
URL: http://svn.apache.org/viewcvs?rev=290945&view=rev
Log:
Fixing AXIS2-236: Make timeout on client configurable
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?rev=290945&r1=290944&r2=290945&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Thu Sep 22 06:55:21 2005
@@ -16,6 +16,18 @@
package org.apache.axis2.transport.http;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
@@ -44,17 +56,8 @@
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
-
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
public class CommonsHTTPTransportSender
extends AbstractHandler
@@ -71,6 +74,8 @@
protected OMOutputImpl omOutput = new OMOutputImpl();
+ protected Log log = LogFactory.getLog(getClass().getName());
+
public CommonsHTTPTransportSender() {
} //default
@@ -418,10 +423,51 @@
//hostConfig handles the socket functions..
//HostConfiguration hostConfig = getHostConfiguration(msgContext, url);
+
+ int soTimeout = HTTPConstants.DEFAULT_SO_TIMEOUT;
+ int connectionTimeout = HTTPConstants.DEFAULT_CONNECTION_TIMEOUT;
+
+ try {
+ // First try getting the SO_TIMEOUT and CONNECTION_TIMEOUT values
+ // form the static configuration
+ Parameter tempSoTimeoutParam = msgContext
+ .getParameter(HTTPConstants.SO_TIMEOUT);
+ Parameter tempConnTimeoutParam = msgContext
+ .getParameter(HTTPConstants.CONNECTION_TIMEOUT);
+
+ if (tempSoTimeoutParam != null) {
+ soTimeout = Integer.parseInt((String) tempSoTimeoutParam
+ .getValue());
+ }
+
+ if (tempConnTimeoutParam != null) {
+ connectionTimeout = Integer
+ .parseInt((String) tempConnTimeoutParam.getValue());
+ }
+
+ // If the SO_TIMEOUT of CONNECTION_TIMEOUT is set by dynamically the
+ // override the static config
+ Integer tempSoTimeoutProperty = (Integer) msgContext
+ .getProperty(HTTPConstants.SO_TIMEOUT);
+ Integer tempConnTimeoutProperty = (Integer) msgContext
+ .getProperty(HTTPConstants.CONNECTION_TIMEOUT);
+
+ if (tempSoTimeoutProperty != null) {
+ connectionTimeout = tempSoTimeoutProperty.intValue();
+ }
+
+ if (tempConnTimeoutProperty != null) {
+ connectionTimeout = tempConnTimeoutProperty.intValue();
+ }
+ } catch (NumberFormatException nfe) {
+ //If there's a problem log it and use the default values
+ log.error("Invalid timeout value format: not a number", nfe);
+ }
+
// SO_TIMEOUT -- timeout for blocking reads
- httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000);
+ httpClient.getHttpConnectionManager().getParams().setSoTimeout(soTimeout);
// timeout for initial connection
- httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
+ httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
PostMethod postMethod = new PostMethod(url.toString());
postMethod.setPath(url.getFile());
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=290945&r1=290944&r2=290945&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java Thu Sep 22 06:55:21 2005
@@ -401,6 +401,27 @@
public static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
/**
+ * Field SO_TIMEOUT
+ */
+ public static final String SO_TIMEOUT = "SO_TIMEOUT";
+
+ /**
+ * Field CONNECTION_TIMEOUT
+ */
+ public static final String CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT";
+
+ /**
+ * Field DEFAULT_SO_TIMEOUT
+ */
+ public static final int DEFAULT_SO_TIMEOUT = 60000;
+
+ /**
+ * Field DEFAULT_CONNECTION_TIMEOUT
+ */
+ public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
+
+
+ /**
* Method getBytes
*
* @param data