|
1 |
| package net.sf.crispy.impl.caucho; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.util.Enumeration; |
|
5 |
| |
|
6 |
| import javax.servlet.ServletConfig; |
|
7 |
| import javax.servlet.ServletException; |
|
8 |
| import javax.servlet.http.HttpServletRequest; |
|
9 |
| import javax.servlet.http.HttpServletResponse; |
|
10 |
| |
|
11 |
| import net.sf.crispy.util.Util; |
|
12 |
| |
|
13 |
| import com.caucho.burlap.io.BurlapInput; |
|
14 |
| import com.caucho.burlap.io.BurlapOutput; |
|
15 |
| |
|
16 |
| public class BurlapServlet2 extends CauchoServlet { |
|
17 |
| |
|
18 |
| private static final long serialVersionUID = -6663937528359674399L; |
|
19 |
| |
|
20 |
2
| public void init(ServletConfig pvConfig) throws ServletException {
|
|
21 |
2
| super.init(pvConfig);
|
|
22 |
2
| Enumeration lvEnumeration = pvConfig.getInitParameterNames();
|
|
23 |
2
| while (lvEnumeration.hasMoreElements()) {
|
|
24 |
3
| String lvKey = (String) lvEnumeration.nextElement();
|
|
25 |
3
| String lvValue = getInitParameter(lvKey);
|
|
26 |
3
| try {
|
|
27 |
3
| Object lvServiceObject = Util.createObject(lvValue);
|
|
28 |
2
| addCache(lvKey, lvServiceObject);
|
|
29 |
| } catch (Exception e) { |
|
30 |
1
| throw new ServletException("Exception in init-method: " + e, e);
|
|
31 |
| } |
|
32 |
| } |
|
33 |
| } |
|
34 |
| |
|
35 |
3
| protected void doPost(HttpServletRequest pvRequest, HttpServletResponse pvResponse) throws ServletException, IOException {
|
|
36 |
3
| String lvKey = getCacheKey(pvRequest);
|
|
37 |
| |
|
38 |
3
| BurlapInput in = new BurlapInput(pvRequest.getInputStream());
|
|
39 |
3
| BurlapOutput out = new BurlapOutput(pvResponse.getOutputStream());
|
|
40 |
| |
|
41 |
3
| try {
|
|
42 |
| |
|
43 |
3
| Object serviceObj = getFromCache(lvKey);
|
|
44 |
3
| BurlapInvoker bi = new BurlapInvoker(serviceObj, Class.forName(lvKey));
|
|
45 |
3
| bi.setWithConverter(true);
|
|
46 |
3
| bi.invoke(in, out);
|
|
47 |
| |
|
48 |
| } catch (Throwable e) { |
|
49 |
0
| throw new ServletException(e);
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| |
|
53 |
| } |