1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.impl;
17
18 import java.net.MalformedURLException;
19 import java.net.URL;
20
21 import org.apache.http.HttpStatus;
22 import org.esigate.Driver;
23 import org.esigate.HttpErrorPage;
24 import org.esigate.UserContext;
25 import org.esigate.api.ContainerRequestContext;
26 import org.esigate.http.IncomingRequest;
27 import org.esigate.util.UriUtils;
28
29
30
31
32
33
34
35 public class DriverRequest {
36 private final IncomingRequest wrappedRequest;
37 private final Driver driver;
38 private final UserContext userContext;
39 private final URL baseUrl;
40 private final String visibleBaseUrl;
41 private final boolean external;
42 private String characterEncoding;
43
44
45
46
47
48
49
50
51 public DriverRequest(IncomingRequest request, Driver driver, String relUrl) throws HttpErrorPage {
52 this.wrappedRequest = request;
53 this.driver = driver;
54 this.external = UriUtils.isAbsolute(relUrl);
55 this.userContext = new UserContext(request, driver.getConfiguration().getInstanceName());
56 try {
57 this.baseUrl = new URL(driver.getConfiguration().getBaseUrlRetrieveStrategy().getBaseURL(request));
58 } catch (MalformedURLException e) {
59 throw new HttpErrorPage(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal server error", e);
60 }
61 String visibleBase = driver.getConfiguration().getVisibleBaseURL();
62 if (visibleBase == null) {
63 String requestUri = request.getRequestLine().getUri();
64 requestUri = UriUtils.removeQuerystring(requestUri);
65 if (!this.external && requestUri.endsWith(relUrl)) {
66 visibleBase = requestUri.substring(0, requestUri.length() - relUrl.length());
67 } else {
68 visibleBase = this.baseUrl.toString();
69 }
70 }
71 this.visibleBaseUrl = UriUtils.rewriteURI(visibleBase, UriUtils.extractHost(request.getRequestLine().getUri()));
72 }
73
74
75
76
77
78
79 public Driver getDriver() {
80 return driver;
81 }
82
83
84
85
86
87
88 public UserContext getUserContext() {
89 return userContext;
90 }
91
92
93
94
95
96
97 public URL getBaseUrl() {
98 return baseUrl;
99 }
100
101
102
103
104
105
106 public String getCharacterEncoding() {
107 return characterEncoding;
108 }
109
110
111
112
113
114
115
116 public void setCharacterEncoding(String characterEncoding) {
117 this.characterEncoding = characterEncoding;
118 }
119
120
121
122
123
124
125 public ContainerRequestContext getContext() {
126 return wrappedRequest.getContext();
127 }
128
129
130
131
132
133
134 public IncomingRequest getOriginalRequest() {
135 return wrappedRequest;
136 }
137
138
139
140
141
142
143 public boolean isExternal() {
144 return external;
145 }
146
147
148
149
150
151
152 public String getVisibleBaseUrl() {
153 return visibleBaseUrl;
154 }
155
156 }