CRXHttpServlet.java
3.96 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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletContext
* javax.servlet.ServletException
* javax.servlet.http.HttpServlet
* javax.servlet.http.HttpServletRequest
* javax.servlet.http.HttpServletResponse
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.crx.explorer.impl.j2ee;
import com.day.crx.explorer.impl.j2ee.CRXContext;
import com.day.crx.explorer.impl.j2ee.CRXHttpServletRequest;
import com.day.crx.explorer.impl.j2ee.CRXHttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CRXHttpServlet
extends HttpServlet {
private static final Logger log = LoggerFactory.getLogger(CRXHttpServlet.class);
public void init() throws ServletException {
if (this.getServletContext().getAttribute(this.getClass().getName()) != null) {
throw new ServletException("Only one servlet allowed per web-app.");
}
this.getServletContext().setAttribute(this.getClass().getName(), (Object)this);
log.info(this.getClass().getSimpleName() + " initialized.");
}
public Properties getInitProperties() {
Properties props = new Properties();
Enumeration e = this.getInitParameterNames();
while (e.hasMoreElements()) {
String name = e.nextElement().toString();
String value = this.getInitParameter(name);
props.put(name, value);
}
return props;
}
public static CRXHttpServlet getInstance(ServletContext ctx, String name) {
CRXHttpServlet instance = (CRXHttpServlet)((Object)ctx.getAttribute(name));
if (instance == null) {
throw new IllegalStateException("No Servlet instance in ServletContext, Servlet not initialized?");
}
return instance;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
CRXContext ctx = null;
if (!(req instanceof CRXHttpServletRequest)) {
ctx = CRXContext.getInstance(this.getServletContext(), (HttpServletRequest)req);
req = new CRXHttpServletRequest(ctx);
}
if (!(resp instanceof CRXHttpServletResponse)) {
resp = new CRXHttpServletResponse((HttpServletResponse)resp);
}
try {
super.service((HttpServletRequest)req, (HttpServletResponse)resp);
}
finally {
if (ctx != null) {
ctx.close();
}
}
}
protected void doGet(CRXHttpServletRequest req, CRXHttpServletResponse resp) throws ServletException, IOException {
super.doGet((HttpServletRequest)req, (HttpServletResponse)resp);
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req instanceof CRXHttpServletRequest && resp instanceof CRXHttpServletResponse) {
this.doGet((CRXHttpServletRequest)req, (CRXHttpServletResponse)resp);
} else {
super.doGet(req, resp);
}
}
protected void doPost(CRXHttpServletRequest req, CRXHttpServletResponse resp) throws ServletException, IOException {
super.doPost((HttpServletRequest)req, (HttpServletResponse)resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req instanceof CRXHttpServletRequest && resp instanceof CRXHttpServletResponse) {
this.doPost((CRXHttpServletRequest)req, (CRXHttpServletResponse)resp);
} else {
super.doPost(req, resp);
}
}
}