01: /**
02: *
03: */package org.enhydra.util.chiba;
04:
05: import java.io.BufferedReader;
06: import java.io.IOException;
07: import java.io.InputStream;
08: import java.io.StringReader;
09:
10: import javax.servlet.ServletInputStream;
11: import javax.servlet.http.HttpServletRequest;
12: import javax.servlet.http.HttpServletRequestWrapper;
13: import javax.xml.transform.stream.StreamSource;
14:
15: /**
16: * @author Slobodan Vujasinovic
17: *
18: */
19: public class ChibaRequest extends HttpServletRequestWrapper {
20:
21: public ChibaRequest(HttpServletRequest arg0) {
22: super (arg0);
23: }
24:
25: // private HttpServletRequest hsr = null;
26:
27: private String body = null;
28:
29: /*
30: * (non-Javadoc)
31: *
32: * @see javax.servlet.ServletRequest#getContentLength()
33: */
34: public int getContentLength() {
35: if (body != null) {
36: try {
37: // return body.getBytes(getCharacterEncoding()).length;
38: return body.getBytes().length;
39: } catch (Exception uee) {
40: uee.printStackTrace();
41: }
42: }
43: /* Alex
44: * if (hsr != null)
45: return hsr.getContentLength();*/
46: return 0;
47: }
48:
49: /*
50: * (non-Javadoc)
51: *
52: * @see javax.servlet.ServletRequest#getInputStream()
53: */
54: public ServletInputStream getInputStream() throws IOException {
55: if (body != null) {
56: StringReader sr = new StringReader(body);
57: StreamSource ss = new StreamSource(sr);
58: InputStream is = ss.getInputStream();
59: ChibaPresentationInputStream cpis = new ChibaPresentationInputStream(
60: is);
61: return cpis;
62: }
63: /* Alex
64: * if (hsr != null)
65: return hsr.getInputStream();*/
66: return null;
67: }
68:
69: /*
70: * (non-Javadoc)
71: *
72: * @see javax.servlet.ServletRequest#getReader()
73: */
74: public BufferedReader getReader() throws IOException {
75: BufferedReader br = new BufferedReader(new StringReader(body));
76: if (br != null)
77: return br;
78: /* Alex
79: * if (hsr != null)
80: return hsr.getReader();*/
81: return null;
82: }
83:
84: /*
85: *
86: */
87: public String getBody() {
88: return body;
89: }
90:
91: /*
92: *
93: */
94: public void setBody(String body) {
95: this.body = body;
96: }
97:
98: }
|