01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: WebservicesHessian.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine.elements;
09:
10: import com.caucho.hessian.io.HessianInput;
11: import com.caucho.hessian.io.HessianOutput;
12: import com.caucho.services.server.ServiceContext;
13: import com.uwyn.rife.engine.Element;
14: import com.uwyn.rife.engine.ElementService;
15: import com.uwyn.rife.engine.RequestMethod;
16: import com.uwyn.rife.engine.annotations.Elem;
17: import com.uwyn.rife.engine.exceptions.EngineException;
18: import java.io.InputStream;
19: import java.io.OutputStream;
20: import javax.servlet.ServletException;
21: import javax.servlet.http.HttpServletResponse;
22:
23: @Elem
24: public class WebservicesHessian extends Element {
25: public Class getDeploymentClass() {
26: return WebservicesHessianDeployer.class;
27: }
28:
29: public void processElement() {
30: if (!getMethod().equals(RequestMethod.POST)) {
31: setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
32: setContentType("text/html");
33: print("<h1>Hessian Requires POST</h1>");
34:
35: return;
36: }
37:
38: WebservicesHessianDeployer deployer = (WebservicesHessianDeployer) getDeployer();
39: String service_id = getHttpServletRequest().getPathInfo();
40: String object_id = getHttpServletRequest().getParameter("id");
41: if (object_id == null) {
42: object_id = getHttpServletRequest().getParameter("ejbid");
43: }
44:
45: try {
46: ServiceContext.begin(getHttpServletRequest(), service_id,
47: object_id);
48:
49: try {
50: InputStream is = getHttpServletRequest()
51: .getInputStream();
52: OutputStream os = getOutputStream();
53:
54: HessianInput in = new HessianInput(is);
55: HessianOutput out = new HessianOutput();
56: out.setSerializerFactory(deployer
57: .getSerializerFactory());
58: out.init(os);
59:
60: if (object_id != null) {
61: Object service = deployer.getObject();
62: synchronized (service) {
63: if (service instanceof ElementService) {
64: ((ElementService) service)
65: .setRequestElement(this );
66: }
67: deployer.getObjectSkeleton().invoke(in, out);
68: }
69: } else {
70: Object service = deployer.getHome();
71: synchronized (service) {
72: if (service instanceof ElementService) {
73: ((ElementService) service)
74: .setRequestElement(this );
75: }
76: deployer.getHomeSkeleton().invoke(in, out);
77: }
78: }
79: } catch (RuntimeException e) {
80: throw e;
81: } catch (Throwable e) {
82: throw new EngineException(e);
83: } finally {
84: ServiceContext.end();
85: }
86: } catch (ServletException e) {
87: throw new EngineException(e);
88: }
89: }
90:
91: public boolean prohibitRawAccess() {
92: return false;
93: }
94: }
|