1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.http;
17
18 import org.esigate.Parameters;
19 import org.esigate.impl.DriverRequest;
20 import org.esigate.util.UriUtils;
21
22
23
24
25
26
27 public final class ResourceUtils {
28
29
30
31
32 private ResourceUtils() {
33
34 }
35
36 private static String buildQueryString(DriverRequest originalRequest, boolean proxy) {
37 StringBuilder queryString = new StringBuilder(Parameters.SMALL_BUFFER_SIZE);
38
39 String originalQuerystring =
40 UriUtils.getRawQuery(originalRequest.getOriginalRequest().getRequestLine().getUri());
41 if (proxy && originalQuerystring != null) {
42
43
44
45
46 String jsessionid;
47 jsessionid = originalRequest.getOriginalRequest().getSessionId();
48 if (jsessionid != null) {
49 originalQuerystring = UriUtils.removeSessionId(jsessionid, originalQuerystring);
50 }
51 queryString.append(originalQuerystring);
52 }
53 return queryString.toString();
54 }
55
56 private static String concatUrl(String baseUrl, String relUrl) {
57 StringBuilder url = new StringBuilder(Parameters.SMALL_BUFFER_SIZE);
58 if (baseUrl != null && relUrl != null && (baseUrl.endsWith("/") || baseUrl.endsWith("\\"))
59 && relUrl.startsWith("/")) {
60 url.append(baseUrl.substring(0, baseUrl.length() - 1)).append(relUrl);
61 } else {
62 url.append(baseUrl).append(relUrl);
63 }
64 return url.toString();
65 }
66
67 public static String getHttpUrlWithQueryString(String url, DriverRequest originalRequest, boolean proxy) {
68 if (!url.startsWith("http://") && !url.startsWith("https://")) {
69
70 String baseUrl = originalRequest.getBaseUrl().toString();
71 if (baseUrl != null) {
72 url = concatUrl(baseUrl, url);
73 }
74 }
75 String queryString = ResourceUtils.buildQueryString(originalRequest, proxy);
76 if (queryString.length() == 0) {
77 return url;
78 } else {
79 return url + "?" + queryString;
80 }
81 }
82
83 }