blob: cf58f398af620c57cb799d368fc46567217fcd86 (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
@VaadinApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal.gwt.server;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import com.vaadin.Application;
import com.vaadin.terminal.CombinedRequest;
import com.vaadin.terminal.DeploymentConfiguration;
import com.vaadin.terminal.WrappedRequest;
/**
* Wrapper for {@link HttpServletRequest}.
*
* @author Vaadin Ltd.
* @since 7.0
*
* @see WrappedRequest
* @see WrappedHttpServletResponse
*/
public class WrappedHttpServletRequest extends HttpServletRequestWrapper
implements WrappedRequest {
private final DeploymentConfiguration deploymentConfiguration;
/**
* Wraps a http servlet request and associates with a deployment
* configuration
*
* @param request
* the http servlet request to wrap
* @param deploymentConfiguration
* the associated deployment configuration
*/
public WrappedHttpServletRequest(HttpServletRequest request,
DeploymentConfiguration deploymentConfiguration) {
super(request);
this.deploymentConfiguration = deploymentConfiguration;
}
@Override
public String getRequestPathInfo() {
return getPathInfo();
}
@Override
public int getSessionMaxInactiveInterval() {
return getSession().getMaxInactiveInterval();
}
@Override
public Object getSessionAttribute(String name) {
return getSession().getAttribute(name);
}
@Override
public void setSessionAttribute(String name, Object attribute) {
getSession().setAttribute(name, attribute);
}
/**
* Gets the original, unwrapped HTTP servlet request.
*
* @return the servlet request
*/
public HttpServletRequest getHttpServletRequest() {
return this;
}
@Override
public DeploymentConfiguration getDeploymentConfiguration() {
return deploymentConfiguration;
}
@Override
public BrowserDetails getBrowserDetails() {
return new BrowserDetails() {
@Override
public String getUriFragment() {
return null;
}
@Override
public String getWindowName() {
return null;
}
@Override
public WebBrowser getWebBrowser() {
WebApplicationContext context = (WebApplicationContext) Application
.getCurrent().getContext();
return context.getBrowser();
}
};
}
/**
* Helper method to get a <code>WrappedHttpServletRequest</code> from a
* <code>WrappedRequest</code>. Aside from casting, this method also takes
* care of situations where there's another level of wrapping.
*
* @param request
* a wrapped request
* @return a wrapped http servlet request
* @throws ClassCastException
* if the wrapped request doesn't wrap a http servlet request
*/
public static WrappedHttpServletRequest cast(WrappedRequest request) {
if (request instanceof CombinedRequest) {
CombinedRequest combinedRequest = (CombinedRequest) request;
request = combinedRequest.getSecondRequest();
}
return (WrappedHttpServletRequest) request;
}
}
|