|
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.InvocationException; |
|
12 |
| import net.sf.crispy.util.Util; |
|
13 |
| |
|
14 |
| import com.caucho.hessian.io.HessianInput; |
|
15 |
| import com.caucho.hessian.io.HessianOutput; |
|
16 |
| import com.caucho.hessian.server.HessianSkeleton; |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| public class HessianServlet extends CauchoServlet { |
|
25 |
| |
|
26 |
| private static final long serialVersionUID = 471335728357L; |
|
27 |
| |
|
28 |
2
| public HessianServlet() {
|
|
29 |
| |
|
30 |
| |
|
31 |
| } |
|
32 |
| |
|
33 |
2
| public void init(ServletConfig pvConfig) throws ServletException {
|
|
34 |
2
| super.init(pvConfig);
|
|
35 |
2
| Enumeration lvEnumeration = pvConfig.getInitParameterNames();
|
|
36 |
2
| while (lvEnumeration.hasMoreElements()) {
|
|
37 |
6
| String lvKey = (String) lvEnumeration.nextElement();
|
|
38 |
6
| String lvValue = getInitParameter(lvKey);
|
|
39 |
6
| try {
|
|
40 |
6
| Object lvServiceObject = Util.createObject(lvValue);
|
|
41 |
5
| Class clazz = null;
|
|
42 |
5
| try {
|
|
43 |
5
| clazz = Class.forName(lvKey);
|
|
44 |
| } catch (Exception e) { |
|
45 |
2
| clazz = lvServiceObject.getClass();
|
|
46 |
| } |
|
47 |
5
| addCache(lvKey, new HessianSkeleton(lvServiceObject, clazz));
|
|
48 |
| } catch (Exception e) { |
|
49 |
1
| throw new ServletException("Exception in init-method: " + e, e);
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
54
| protected void doPost(HttpServletRequest pvRequest, HttpServletResponse pvResponse) throws ServletException, IOException {
|
|
56 |
54
| String lvKey = getCacheKey(pvRequest);
|
|
57 |
54
| HessianSkeleton skeleton = (HessianSkeleton) getFromCache(getCacheKey(pvRequest));
|
|
58 |
| if (log.isDebugEnabled()) { log.debug("CachKey: " + lvKey + " / Skeleton: " + skeleton); } |
|
59 |
0
| if (skeleton == null) { throw new InvocationException("For the key: " + lvKey + " can't find a register service in the HessianServlet!"); }
|
|
60 |
| |
|
61 |
54
| HessianInput in = new HessianInput(pvRequest.getInputStream());
|
|
62 |
54
| HessianOutput out = new HessianOutput(pvResponse.getOutputStream());
|
|
63 |
| |
|
64 |
54
| try {
|
|
65 |
54
| skeleton.invoke(in, out);
|
|
66 |
| } catch (Throwable e) { |
|
67 |
0
| throw new ServletException(e);
|
|
68 |
| } |
|
69 |
| } |
|
70 |
| |
|
71 |
| } |