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.annotation.NotThreadSafe;
38 import org.apache.http.client.methods.HttpUriRequest;
39 import org.apache.http.message.AbstractHttpMessage;
40 import org.apache.http.message.BasicRequestLine;
41 import org.apache.http.params.HttpProtocolParams;
42 import org.apache.http.util.Args;
43
44
45
46
47
48
49
50
51
52
53
54
55
56 @NotThreadSafe
57 @Deprecated
58 public class RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
59
60 private final HttpRequest original;
61
62 private URI uri;
63 private String method;
64 private ProtocolVersion version;
65 private int execCount;
66
67 public RequestWrapper(final HttpRequest request) throws ProtocolException {
68 super();
69 Args.notNull(request, "HTTP request");
70 this.original = request;
71 setParams(request.getParams());
72 setHeaders(request.getAllHeaders());
73
74 if (request instanceof HttpUriRequest) {
75 this.uri = ((HttpUriRequest) request).getURI();
76 this.method = ((HttpUriRequest) request).getMethod();
77 this.version = null;
78 } else {
79 final RequestLine requestLine = request.getRequestLine();
80 try {
81 this.uri = new URI(requestLine.getUri());
82 } catch (final URISyntaxException ex) {
83 throw new ProtocolException("Invalid request URI: "
84 + requestLine.getUri(), ex);
85 }
86 this.method = requestLine.getMethod();
87 this.version = request.getProtocolVersion();
88 }
89 this.execCount = 0;
90 }
91
92 public void resetHeaders() {
93
94 this.headergroup.clear();
95 setHeaders(this.original.getAllHeaders());
96 }
97
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 public ProtocolVersion getProtocolVersion() {
108 if (this.version == null) {
109 this.version = HttpProtocolParams.getVersion(getParams());
110 }
111 return this.version;
112 }
113
114 public void setProtocolVersion(final ProtocolVersion version) {
115 this.version = version;
116 }
117
118
119 public URI getURI() {
120 return this.uri;
121 }
122
123 public void setURI(final URI uri) {
124 this.uri = uri;
125 }
126
127 public RequestLine getRequestLine() {
128 final String method = getMethod();
129 final ProtocolVersion ver = getProtocolVersion();
130 String uritext = null;
131 if (uri != null) {
132 uritext = uri.toASCIIString();
133 }
134 if (uritext == null || uritext.length() == 0) {
135 uritext = "/";
136 }
137 return new BasicRequestLine(method, uritext, ver);
138 }
139
140 public void abort() throws UnsupportedOperationException {
141 throw new UnsupportedOperationException();
142 }
143
144 public boolean isAborted() {
145 return false;
146 }
147
148 public HttpRequest getOriginal() {
149 return this.original;
150 }
151
152 public boolean isRepeatable() {
153 return true;
154 }
155
156 public int getExecCount() {
157 return this.execCount;
158 }
159
160 public void incrementExecCount() {
161 this.execCount++;
162 }
163
164 }