1
2
3
4
5
6
7
8
9
10 package org.apache.commons.messagelet.impl;
11
12 import java.io.BufferedReader;
13 import java.io.InputStreamReader;
14
15 import javax.jms.JMSException;
16 import javax.jms.Message;
17 import javax.jms.TextMessage;
18 import javax.servlet.ServletInputStream;
19 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletRequestWrapper;
21
22 import org.apache.commons.messagelet.MessageletRequest;
23 import org.apache.commons.messenger.Messenger;
24
25
26
27
28
29
30
31
32 public class HttpMessageletRequestImpl extends HttpServletRequestWrapper implements MessageletRequest {
33
34
35 private Message message;
36
37 private ServletInputStream stream;
38
39 public HttpMessageletRequestImpl(HttpServletRequest request) {
40 super(request);
41 }
42
43 public void setMessage(Message message) throws JMSException {
44 this.message = message;
45 this.stream = createInputStream();
46
47
48 setAttribute( "message", message );
49 }
50
51 public void setMessenger(Messenger messenger) {
52 setAttribute( "messenger", messenger );
53 }
54
55
56
57
58
59 public Message getMessage() {
60 return message;
61 }
62
63
64
65
66
67 public ServletInputStream getInputStream() {
68 return stream;
69 }
70
71 public BufferedReader getReader() {
72 return new BufferedReader( new InputStreamReader( stream ) );
73 }
74
75
76
77
78
79
80 protected ServletInputStream createInputStream() throws JMSException {
81 if ( message instanceof TextMessage ) {
82 TextMessage textMessage = (TextMessage) message;
83 return new BufferedServletInputStream( textMessage.getText() );
84 }
85
86
87 return new BufferedServletInputStream();
88 }
89
90 }
91