View Javadoc
1   /* 
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   *
14   */
15  
16  package org.esigate.http;
17  
18  import java.net.URL;
19  
20  import org.apache.http.ProtocolVersion;
21  import org.apache.http.RequestLine;
22  import org.apache.http.client.config.RequestConfig;
23  import org.apache.http.client.methods.Configurable;
24  import org.apache.http.message.BasicHttpEntityEnclosingRequest;
25  import org.apache.http.message.BasicRequestLine;
26  import org.esigate.UserContext;
27  import org.esigate.api.ContainerRequestContext;
28  import org.esigate.impl.DriverRequest;
29  
30  /**
31   * Allows request line / uri modification after request creation.
32   * 
33   * @author fxbonnet
34   * 
35   */
36  public class OutgoingRequest extends BasicHttpEntityEnclosingRequest implements Configurable {
37  
38      private RequestLine requestLine;
39      private final RequestConfig requestConfig;
40      private final OutgoingRequestContext context;
41      private final DriverRequest originalRequest;
42  
43      public OutgoingRequest(String method, String uri, ProtocolVersion version, DriverRequest originalRequest,
44              RequestConfig requestConfig, OutgoingRequestContext context) {
45          super(method, uri, version);
46          requestLine = new BasicRequestLine(method, uri, version);
47          this.requestConfig = requestConfig;
48          this.context = context;
49          this.originalRequest = originalRequest;
50      }
51  
52      public void setUri(String uri) {
53          requestLine = new BasicRequestLine(requestLine.getMethod(), uri, requestLine.getProtocolVersion());
54      }
55  
56      @Override
57      public ProtocolVersion getProtocolVersion() {
58          return requestLine.getProtocolVersion();
59      }
60  
61      @Override
62      public RequestLine getRequestLine() {
63          return requestLine;
64      }
65  
66      @Override
67      public String toString() {
68          return requestLine.toString();
69      }
70  
71      @Override
72      public RequestConfig getConfig() {
73          return requestConfig;
74      }
75  
76      public OutgoingRequestContext getContext() {
77          return context;
78      }
79  
80      public UserContext getUserContext() {
81          return originalRequest.getUserContext();
82      }
83  
84      public ContainerRequestContext getContainerRequestContext() {
85          return originalRequest.getContext();
86      }
87  
88      public URL getBaseUrl() {
89          return originalRequest.getBaseUrl();
90      }
91  
92      public DriverRequest getOriginalRequest() {
93          return originalRequest;
94      }
95  
96  }