1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.ws.soap.client;
18
19 import org.apache.commons.httpclient.HttpClient;
20 import org.apache.commons.httpclient.HttpVersion;
21 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
22 import org.apache.commons.httpclient.params.HttpClientParams;
23 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
24 import org.opensaml.ws.message.decoder.MessageDecoder;
25 import org.opensaml.ws.message.encoder.MessageEncoder;
26 import org.opensaml.ws.transport.http.HTTPTransport.HTTP_VERSION;
27
28
29
30
31 public class HTTPSOAPTransportFactory implements ClientTransportFactory {
32
33
34 private int socketTimeout = 30000;
35
36
37 private int connectionTimeout = 60000;
38
39
40 private HTTP_VERSION httpVersion = HTTP_VERSION.HTTP1_1;
41
42
43 private MessageEncoder messageEncoder;
44
45
46 private MessageDecoder messageDecoder;
47
48
49 private HttpClient httpClient;
50
51
52
53
54
55
56
57 public HTTPSOAPTransportFactory(MessageEncoder encoder, MessageDecoder decoder) {
58 messageEncoder = encoder;
59 messageDecoder = decoder;
60 initializeHttpClient();
61 }
62
63
64
65
66
67
68 public int getConnectionTimeout() {
69 return connectionTimeout;
70 }
71
72
73
74
75
76
77 public void setConnectionTimeout(int timeout) {
78 connectionTimeout = timeout;
79 }
80
81
82
83
84
85
86 public HTTP_VERSION getHttpVersion() {
87 return httpVersion;
88 }
89
90
91
92
93
94
95 public void setHttpVersion(HTTP_VERSION version) {
96 this.httpVersion = version;
97 }
98
99
100
101
102
103
104 public int getSocketTimeout() {
105 return socketTimeout;
106 }
107
108
109
110
111
112
113 public void setSocketTimeout(int timeout) {
114 this.socketTimeout = timeout;
115 }
116
117
118
119
120
121
122 public MessageDecoder getMessageDecoder() {
123 return messageDecoder;
124 }
125
126
127
128
129
130
131 public MessageEncoder getMessageEncoder() {
132 return messageEncoder;
133 }
134
135
136 public ClientTransport createTransport() {
137 return new HTTPSOAPTransport(httpClient, messageEncoder, messageDecoder);
138 }
139
140
141
142
143
144 protected void initializeHttpClient() {
145 HttpConnectionManagerParams connectionParams = new HttpConnectionManagerParams();
146 connectionParams.setConnectionTimeout(connectionTimeout);
147
148 MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
149 connectionManager.setParams(connectionParams);
150
151 HttpClientParams clientParams = new HttpClientParams();
152 clientParams.setSoTimeout(socketTimeout);
153 if (httpVersion == HTTP_VERSION.HTTP1_0) {
154 clientParams.setVersion(HttpVersion.HTTP_1_0);
155 } else {
156 clientParams.setVersion(HttpVersion.HTTP_1_1);
157 }
158
159 httpClient = new HttpClient(clientParams, connectionManager);
160 }
161 }