| Home >> All >> com >> aendvari >> hermes >> broker >> [ http Javadoc ] |
Source code: com/aendvari/hermes/broker/http/HttpMessageBrokerContext.java
1 /* 2 * HttpMessageBrokerContext.java 3 * 4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved. 5 * 6 * See the file LICENSE for terms of use. 7 * 8 */ 9 10 package com.aendvari.hermes.broker.http; 11 12 import javax.servlet.*; 13 import javax.servlet.http.*; 14 15 import com.aendvari.hermes.broker.MessageBrokerContext; 16 17 import com.aendvari.common.properties.Properties; 18 19 /** 20 * <p>Extends {@link MessageBrokerContext} to include HTTP/Servlet specific information.</p> 21 * 22 * <p>This class also provides an interface for accessing HTTP/Servlet information from 23 * a {@link MessageBrokerContext MessageBrokerContext's} properties.</p> 24 * 25 * @author Trevor Milne 26 * 27 */ 28 29 public class HttpMessageBrokerContext extends MessageBrokerContext 30 { 31 /* Constants. */ 32 33 34 /** Various property constants. */ 35 public interface Property 36 { 37 /** The <code>HttpServletRequest</code> property. */ 38 public static String Request = "servlet/request"; 39 40 /** The <code>HttpServletResponse</code> property. */ 41 public static String Response = "servlet/response"; 42 43 /** The <code>HttpSession</code> property. */ 44 public static String Session = "servlet/session"; 45 46 /** The <code>ServletConfig</code> property. */ 47 public static String ServletConfig = "servlet/config"; 48 } 49 50 51 /* Constructors. */ 52 53 54 /** 55 * Constructs a <code>HttpMessageBrokerContext</code>. 56 * 57 */ 58 59 public HttpMessageBrokerContext() 60 { 61 super(); 62 } 63 64 65 /* Accessors. */ 66 67 68 /* Request. */ 69 70 /** 71 * Sets the request of this context. 72 * 73 * @param setRequest The <code>HttpServletRequest</code> for this context. 74 * 75 */ 76 77 public void setRequest(HttpServletRequest setRequest) 78 { 79 getProperties().setObject(Property.Request, setRequest); 80 getProperties().setObject(Property.Session, setRequest.getSession()); 81 } 82 83 /** 84 * Returns the request of this context. 85 * 86 * @return The <code>HttpServletRequest</code> for this context. 87 * 88 */ 89 90 public HttpServletRequest getRequest() 91 { 92 return (HttpServletRequest)getProperties().getObject(Property.Request); 93 } 94 95 /** 96 * Returns the request of the supplied context. 97 * 98 * @param context The {@link MessageBrokerContext} to read from. 99 * 100 * @return The <code>HttpServletRequest</code> for the context. 101 * 102 */ 103 104 public static HttpServletRequest getRequest(MessageBrokerContext context) 105 { 106 return (HttpServletRequest)context.getProperties().getObject(Property.Request); 107 } 108 109 /* Response. */ 110 111 /** 112 * Sets the response of this context. 113 * 114 * @param setResponse The <code>HttpServletRespose</code> for this context. 115 * 116 */ 117 118 public void setResponse(HttpServletResponse setResponse) 119 { 120 getProperties().setObject(Property.Response, setResponse); 121 } 122 123 /** 124 * Returns the response of this context. 125 * 126 * @return The <code>HttpServletResponse</code> for this context. 127 * 128 */ 129 130 public HttpServletResponse getResponse() 131 { 132 return (HttpServletResponse)getProperties().getObject(Property.Response); 133 } 134 135 /** 136 * Returns the response of the supplied context. 137 * 138 * @param context The {@link MessageBrokerContext} to read from. 139 * 140 * @return The <code>HttpServletResponse</code> for the context. 141 * 142 */ 143 144 public static HttpServletResponse getResponse(MessageBrokerContext context) 145 { 146 return (HttpServletResponse)context.getProperties().getObject(Property.Response); 147 } 148 149 /* Session. */ 150 151 /** 152 * Sets the session of this context. 153 * 154 * @param setSession The <code>HttpSession</code> for this context. 155 * 156 */ 157 158 public void setSession(HttpSession setSession) 159 { 160 getProperties().setObject(Property.Session, setSession); 161 } 162 163 /** 164 * Sets the session of this context. The session is obtained from the supplied request. 165 * 166 * @param setRequest The <code>HttpServletRequest</code> containing the session. 167 * 168 */ 169 170 public void setSession(HttpServletRequest setRequest) 171 { 172 getProperties().setObject(Property.Session, setRequest.getSession()); 173 } 174 175 /** 176 * Returns the session of this context. 177 * 178 * @return The <code>HttpSession</code> for this context. 179 * 180 */ 181 182 public HttpSession getSession() 183 { 184 return (HttpSession)getProperties().getObject(Property.Session); 185 } 186 187 /** 188 * Returns the session of the supplied context. 189 * 190 * @param context The {@link MessageBrokerContext} to read from. 191 * 192 * @return The <code>HttpSession</code> for the context. 193 * 194 */ 195 196 public static HttpSession getSession(MessageBrokerContext context) 197 { 198 return (HttpSession)context.getProperties().getObject(Property.Session); 199 } 200 201 /* Servlet config. */ 202 203 /** 204 * Sets the servlet configuration of this context. 205 * 206 * @param setServletConfig The <code>ServletConfig</code> for this context. 207 * 208 */ 209 210 public void setServletConfig(ServletConfig setServletConfig) 211 { 212 getProperties().setObject(Property.ServletConfig, setServletConfig); 213 } 214 215 /** 216 * Returns the servlet configuration of this context. 217 * 218 * @return The <code>ServletConfig</code> for this context. 219 * 220 */ 221 222 public ServletConfig getServletConfig() 223 { 224 return (ServletConfig)getProperties().getObject(Property.ServletConfig); 225 } 226 227 /** 228 * Returns the servlet configuration of the supplied context. 229 * 230 * @param context The {@link MessageBrokerContext} to read from. 231 * 232 * @return The <code>ServletConfig</code> for the context. 233 * 234 */ 235 236 public static ServletConfig getServletConfig(MessageBrokerContext context) 237 { 238 return (ServletConfig)context.getProperties().getObject(Property.ServletConfig); 239 } 240 } 241