RequestHandler.java
2.69 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.callbacks.Prox0
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletRequestWrapper
* javax.servlet.http.HttpServletResponse
* org.springframework.context.i18n.LocaleContextHolder
* org.springframework.web.context.request.RequestAttributes
* org.springframework.web.context.request.RequestContextHolder
* org.springframework.web.context.request.ServletRequestAttributes
*/
package com.adobe.cq.dam.s7imaging.impl.ps;
import com.scene7.is.util.callbacks.Prox0;
import java.io.Closeable;
import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
public abstract class RequestHandler
implements Closeable {
public final void handleRequest(final HttpServletRequest req, final HttpServletResponse res) throws Exception {
RequestHandler.withRequestContext(req, new Prox0<Exception>(){
protected void run() throws Exception {
RequestHandler.this.doHandleRequest(RequestHandler.this.translate(req), res);
}
});
}
protected abstract String contextRoot();
protected abstract void doHandleRequest(HttpServletRequest var1, HttpServletResponse var2) throws ServletException, IOException;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private static <X extends Exception> void withRequestContext(HttpServletRequest request, Prox0<X> block) throws Exception {
ServletRequestAttributes attributes = new ServletRequestAttributes(request);
LocaleContextHolder.setLocale((Locale)request.getLocale(), (boolean)false);
RequestContextHolder.setRequestAttributes((RequestAttributes)attributes, (boolean)false);
try {
block.call();
}
finally {
LocaleContextHolder.resetLocaleContext();
RequestContextHolder.resetRequestAttributes();
attributes.requestCompleted();
}
}
private HttpServletRequest translate(HttpServletRequest req) {
return new HttpServletRequestWrapper(req){
public String getServletPath() {
return RequestHandler.this.contextRoot();
}
};
}
}