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.burlap.io.BurlapInput;
15 import com.caucho.burlap.io.BurlapOutput;
16 import com.caucho.burlap.server.BurlapSkeleton;
17
18 /**
19 * This class execute the services and answer to request from the burlap client.
20 *
21 * @author Linke
22 *
23 */
24 public class BurlapServlet extends CauchoServlet {
25
26 private static final long serialVersionUID = 47128998724L;
27
28 public BurlapServlet() {
29
30
31 }
32
33 public void init(ServletConfig pvConfig) throws ServletException {
34 super.init(pvConfig);
35 Enumeration lvEnumeration = pvConfig.getInitParameterNames();
36 while (lvEnumeration.hasMoreElements()) {
37 String lvKey = (String) lvEnumeration.nextElement();
38 String lvValue = getInitParameter(lvKey);
39 try {
40 Object lvServiceObject = Util.createObject(lvValue);
41 addCache(lvKey, new BurlapSkeleton(lvServiceObject));
42
43 } catch (Exception e) {
44 throw new ServletException("Exception in init-method: " + e, e);
45 }
46 }
47 }
48
49 protected void doPost(HttpServletRequest pvRequest, HttpServletResponse pvResponse) throws ServletException, IOException {
50 String lvKey = getCacheKey(pvRequest);
51 BurlapSkeleton skeleton = (BurlapSkeleton) getFromCache(lvKey);
52
53 if (log.isDebugEnabled()) { log.debug("CachKey: " + lvKey + " / Skeleton: " + skeleton); }
54 if (skeleton == null) { throw new InvocationException("For the key: " + lvKey + " can't find a register service in the BurlapServlet!"); }
55
56 BurlapInput in = new BurlapInput(pvRequest.getInputStream());
57 BurlapOutput out = new BurlapOutput(pvResponse.getOutputStream());
58
59 try {
60 skeleton.invoke(in, out);
61 } catch (Throwable e) {
62 e.printStackTrace();
63 throw new ServletException(e);
64 }
65 }
66
67
68 }