19
19
import java .io .IOException ;
20
20
import java .net .URI ;
21
21
22
- import org .springframework .beans .factory .DisposableBean ;
23
- import org .springframework .beans .factory .InitializingBean ;
24
- import org .springframework .util .Assert ;
25
- import org .springframework .ws .transport .WebServiceConnection ;
26
-
27
22
import org .apache .commons .httpclient .Credentials ;
28
23
import org .apache .commons .httpclient .HttpClient ;
29
24
import org .apache .commons .httpclient .HttpConnectionManager ;
33
28
import org .apache .commons .httpclient .auth .AuthScope ;
34
29
import org .apache .commons .httpclient .methods .PostMethod ;
35
30
31
+ import org .springframework .beans .factory .DisposableBean ;
32
+ import org .springframework .beans .factory .InitializingBean ;
33
+ import org .springframework .util .Assert ;
34
+ import org .springframework .ws .transport .WebServiceConnection ;
35
+
36
36
/**
37
37
* <code>WebServiceMessageSender</code> implementation that uses <a href="http://jakarta.apache.org/commons/httpclient">Jakarta
38
38
* Commons HttpClient</a> to execute POST requests.
50
50
public class CommonsHttpMessageSender extends AbstractHttpWebServiceMessageSender
51
51
implements InitializingBean , DisposableBean {
52
52
53
+ private static final int DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS = (60 * 1000 );
54
+
55
+ private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = (60 * 1000 );
56
+
53
57
private HttpClient httpClient ;
54
58
55
59
private Credentials credentials ;
@@ -62,6 +66,8 @@ public class CommonsHttpMessageSender extends AbstractHttpWebServiceMessageSende
62
66
*/
63
67
public CommonsHttpMessageSender () {
64
68
httpClient = new HttpClient (new MultiThreadedHttpConnectionManager ());
69
+ setConnectionTimeout (DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS );
70
+ setReadTimeout (DEFAULT_READ_TIMEOUT_MILLISECONDS );
65
71
}
66
72
67
73
/**
@@ -99,6 +105,32 @@ public void setCredentials(Credentials credentials) {
99
105
this .credentials = credentials ;
100
106
}
101
107
108
+ /**
109
+ * Sets the timeout until a connection is etablished. A value of 0 means <em>never</em> timeout.
110
+ *
111
+ * @param timeout the timeout value in milliseconds
112
+ * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setConnectionTimeout(int)
113
+ */
114
+ public void setConnectionTimeout (int timeout ) {
115
+ if (timeout < 0 ) {
116
+ throw new IllegalArgumentException ("timeout must be a non-negative value" );
117
+ }
118
+ getHttpClient ().getHttpConnectionManager ().getParams ().setConnectionTimeout (timeout );
119
+ }
120
+
121
+ /**
122
+ * Set the socket read timeout for the underlying HttpClient. A value of 0 means <em>never</em> timeout.
123
+ *
124
+ * @param timeout the timeout value in milliseconds
125
+ * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int)
126
+ */
127
+ public void setReadTimeout (int timeout ) {
128
+ if (timeout < 0 ) {
129
+ throw new IllegalArgumentException ("timeout must be a non-negative value" );
130
+ }
131
+ getHttpClient ().getHttpConnectionManager ().getParams ().setSoTimeout (timeout );
132
+ }
133
+
102
134
/**
103
135
* Returns the authentication scope to be used. Only used when the <code>credentials</code> property has been set.
104
136
* <p/>
0 commit comments