1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.client;
29
30 import java.net.URI;
31 import java.net.URISyntaxException;
32
33 import org.apache.http.HttpRequest;
34 import org.apache.http.ProtocolException;
35 import org.apache.http.ProtocolVersion;
36 import org.apache.http.RequestLine;
37 import org.apache.http.client.methods.HttpUriRequest;
38 import org.apache.http.message.AbstractHttpMessage;
39 import org.apache.http.message.BasicRequestLine;
40 import org.apache.http.params.HttpProtocolParams;
41 import org.apache.http.util.Args;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 @Deprecated
57 public class RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
58
59 private final HttpRequest original;
60
61 private URI uri;
62 private String method;
63 private ProtocolVersion version;
64 private int execCount;
65
66 public RequestWrapper(final HttpRequest request) throws ProtocolException {
67 super();
68 Args.notNull(request, "HTTP request");
69 this.original = request;
70 setParams(request.getParams());
71 setHeaders(request.getAllHeaders());
72
73 if (request instanceof HttpUriRequest) {
74 this.uri = ((HttpUriRequest) request).getURI();
75 this.method = ((HttpUriRequest) request).getMethod();
76 this.version = null;
77 } else {
78 final RequestLine requestLine = request.getRequestLine();
79 try {
80 this.uri = new URI(requestLine.getUri());
81 } catch (final URISyntaxException ex) {
82 throw new ProtocolException("Invalid request URI: "
83 + requestLine.getUri(), ex);
84 }
85 this.method = requestLine.getMethod();
86 this.version = request.getProtocolVersion();
87 }
88 this.execCount = 0;
89 }
90
91 public void resetHeaders() {
92
93 this.headergroup.clear();
94 setHeaders(this.original.getAllHeaders());
95 }
96
97 @Override
98 public String getMethod() {
99 return this.method;
100 }
101
102 public void setMethod(final String method) {
103 Args.notNull(method, "Method name");
104 this.method = method;
105 }
106
107 @Override
108 public ProtocolVersion getProtocolVersion() {
109 if (this.version == null) {
110 this.version = HttpProtocolParams.getVersion(getParams());
111 }
112 return this.version;
113 }
114
115 public void setProtocolVersion(final ProtocolVersion version) {
116 this.version = version;
117 }
118
119
120 @Override
121 public URI getURI() {
122 return this.uri;
123 }
124
125 public void setURI(final URI uri) {
126 this.uri = uri;
127 }
128
129 @Override
130 public RequestLine getRequestLine() {
131 final ProtocolVersion ver = getProtocolVersion();
132 String uritext = null;
133 if (uri != null) {
134 uritext = uri.toASCIIString();
135 }
136 if (uritext == null || uritext.isEmpty()) {
137 uritext = "/";
138 }
139 return new BasicRequestLine(getMethod(), uritext, ver);
140 }
141
142 @Override
143 public void abort() throws UnsupportedOperationException {
144 throw new UnsupportedOperationException();
145 }
146
147 @Override
148 public boolean isAborted() {
149 return false;
150 }
151
152 public HttpRequest getOriginal() {
153 return this.original;
154 }
155
156 public boolean isRepeatable() {
157 return true;
158 }
159
160 public int getExecCount() {
161 return this.execCount;
162 }
163
164 public void incrementExecCount() {
165 this.execCount++;
166 }
167
168 }