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.ServletRequest;
20 import javax.servlet.ServletRequestWrapper;
21
22 import org.apache.commons.messagelet.MessageletRequest;
23 import org.apache.commons.messenger.Messenger;
24
25
26
27
28
29
30
31 public class MessageletRequestImpl extends ServletRequestWrapper implements MessageletRequest {
32
33
34 private Message message;
35
36 private ServletInputStream stream;
37
38 public MessageletRequestImpl(ServletRequest request) {
39 super(request);
40 }
41
42 public void setMessage(Message message) throws JMSException {
43 this.message = message;
44 this.stream = createInputStream();
45
46
47 setAttribute( "message", message );
48 }
49
50 public void setMessenger(Messenger messenger) {
51 setAttribute( "messenger", messenger );
52 }
53
54
55
56
57
58 public Message getMessage() {
59 return message;
60 }
61
62
63
64
65
66 public ServletInputStream getInputStream() {
67 return stream;
68 }
69
70 public BufferedReader getReader() {
71 return new BufferedReader( new InputStreamReader( stream ) );
72 }
73
74
75
76
77
78 protected ServletInputStream createInputStream() throws JMSException {
79 if ( message instanceof TextMessage ) {
80 TextMessage textMessage = (TextMessage) message;
81 return new BufferedServletInputStream( textMessage.getText() );
82 }
83
84
85 return new BufferedServletInputStream();
86 }
87
88 }
89