use of javax.servlet.http.HttpServletRequestWrapper in project ddf by codice.
the class SparkServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String relativePath = getRelativePath(req, filterPath);
HttpServletRequestWrapper requestWrapper;
synchronized (this) {
requestWrapper = requestSupplier.apply(req, relativePath);
}
// handle static resources
boolean consumed = StaticFilesConfiguration.servletInstance.consume(req, resp);
if (consumed) {
return;
}
matcherFilter.doFilter(requestWrapper, resp, null);
}
use of javax.servlet.http.HttpServletRequestWrapper in project sling by apache.
the class SlingServlet method service.
/**
* If Sling has already been started, the request is forwarded to the
* started Sling framework. Otherwise the Sling framework is started unless
* there were too many startup failures.
* <p>
* If the request is not forwarded to Sling, this method returns a 404/NOT
* FOUND if the startup failure counter has exceeded or 503/SERVICE
* UNAVAILABLE if the Sling framework is starting up.
* <p>
* If a request causes the framework to start, it is immediately terminated
* with said response status and framework is started in a separate thread.
*/
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// delegate the request to the registered delegatee servlet
Servlet delegatee = sling;
if (delegatee != null) {
// check for problematic application servers like WebSphere
// where path info and servlet path is set wrong SLING-2410
final HttpServletRequest request = (HttpServletRequest) req;
if (request.getPathInfo() == null && request.getServletPath() != null && request.getServletPath().endsWith(".jsp")) {
req = new HttpServletRequestWrapper(request) {
@Override
public String getPathInfo() {
return request.getServletPath();
}
@Override
public String getServletPath() {
return "";
}
};
}
delegatee.service(req, res);
} else if (startFailureCounter > MAX_START_FAILURES) {
// too many startup retries, fail for ever
((HttpServletResponse) res).sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
startSling(req);
((HttpServletResponse) res).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Apache Sling is currently starting up, please try again");
}
}
use of javax.servlet.http.HttpServletRequestWrapper in project ddf by codice.
the class SparkServlet method service.
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String relativePath = getRelativePath(req, filterPath);
HttpServletRequestWrapper requestWrapper;
synchronized (this) {
requestWrapper = requestSupplier.apply(req, relativePath);
}
// handle static resources
boolean consumed = StaticFilesConfiguration.servletInstance.consume(req, resp);
if (consumed) {
return;
}
matcherFilter.doFilter(requestWrapper, resp, null);
}
use of javax.servlet.http.HttpServletRequestWrapper in project uPortal by Jasig.
the class RemoteUserSettingFilter method doFilter.
/* (non-Javadoc)
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
final String remoteUser = StringUtils.trimToNull(FileUtils.readFileToString(this.remoteUserFile));
if (remoteUser != null) {
request = new HttpServletRequestWrapper((HttpServletRequest) request) {
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getRemoteUser()
*/
@Override
public String getRemoteUser() {
return remoteUser;
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getHeader(java.lang.String)
*/
@Override
public String getHeader(String name) {
if ("REMOTE_USER".equals(name)) {
return remoteUser;
}
return super.getHeader(name);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getHeaders(java.lang.String)
*/
@Override
public Enumeration<String> getHeaders(String name) {
if ("REMOTE_USER".equals(name)) {
return Iterators.asEnumeration(Collections.singleton(remoteUser).iterator());
}
return super.getHeaders(name);
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getHeaderNames()
*/
@Override
public Enumeration<String> getHeaderNames() {
final LinkedHashSet<String> headers = new LinkedHashSet<String>();
for (final Enumeration<String> headersEnum = super.getHeaderNames(); headersEnum.hasMoreElements(); ) {
headers.add(headersEnum.nextElement());
}
headers.add("REMOTE_USER");
return Iterators.asEnumeration(headers.iterator());
}
/* (non-Javadoc)
* @see javax.servlet.http.HttpServletRequestWrapper#getIntHeader(java.lang.String)
*/
@Override
public int getIntHeader(String name) {
if ("REMOTE_USER".equals(name)) {
return Integer.valueOf(remoteUser);
}
return super.getIntHeader(name);
}
};
}
chain.doFilter(request, response);
}
use of javax.servlet.http.HttpServletRequestWrapper in project ORCID-Source by ORCID.
the class JsonpCallbackFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
Map<String, String[]> parms = httpRequest.getParameterMap();
if (parms.containsKey("callback")) {
HttpServletRequestWrapper requestWrapper = new AcceptHeaderRequestWrapper(httpRequest, "application/json");
OutputStream out = httpResponse.getOutputStream();
GenericResponseWrapper responseWrapper = new GenericResponseWrapper(httpResponse);
filterChain.doFilter(requestWrapper, responseWrapper);
out.write(new String(parms.get("callback")[0] + "(").getBytes());
out.write(responseWrapper.getData());
out.write(new String(");").getBytes());
responseWrapper.setContentType("text/javascript;charset=UTF-8");
out.close();
} else {
filterChain.doFilter(request, response);
}
}
Aggregations