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 public void init(ServletConfig pvConfig) throws ServletException {
21 super.init(pvConfig);
22 Enumeration lvEnumeration = pvConfig.getInitParameterNames();
23 while (lvEnumeration.hasMoreElements()) {
24 String lvKey = (String) lvEnumeration.nextElement();
25 String lvValue = getInitParameter(lvKey);
26 try {
27 Object lvServiceObject = Util.createObject(lvValue);
28 addCache(lvKey, lvServiceObject);
29 } catch (Exception e) {
30 throw new ServletException("Exception in init-method: " + e, e);
31 }
32 }
33 }
34
35 protected void doPost(HttpServletRequest pvRequest, HttpServletResponse pvResponse) throws ServletException, IOException {
36 String lvKey = getCacheKey(pvRequest);
37
38 BurlapInput in = new BurlapInput(pvRequest.getInputStream());
39 BurlapOutput out = new BurlapOutput(pvResponse.getOutputStream());
40
41 try {
42
43 Object serviceObj = getFromCache(lvKey);
44 BurlapInvoker bi = new BurlapInvoker(serviceObj, Class.forName(lvKey));
45 bi.setWithConverter(true);
46 bi.invoke(in, out);
47
48 } catch (Throwable e) {
49 throw new ServletException(e);
50 }
51 }
52
53 }