PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/org.mwc.asset.comms/docs/restlet_src/org.restlet/org/restlet/util/WrapperRequest.java

https://bitbucket.org/haris_peco/debrief
Java | 502 lines | 203 code | 51 blank | 248 comment | 0 complexity | 3befe51eb05c400a79d9b13b598ff6be MD5 | raw file
  1. /**
  2. * Copyright 2005-2010 Noelios Technologies.
  3. *
  4. * The contents of this file are subject to the terms of one of the following
  5. * open source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL 1.0 (the
  6. * "Licenses"). You can select the license that you prefer but you may not use
  7. * this file except in compliance with one of these Licenses.
  8. *
  9. * You can obtain a copy of the LGPL 3.0 license at
  10. * http://www.opensource.org/licenses/lgpl-3.0.html
  11. *
  12. * You can obtain a copy of the LGPL 2.1 license at
  13. * http://www.opensource.org/licenses/lgpl-2.1.php
  14. *
  15. * You can obtain a copy of the CDDL 1.0 license at
  16. * http://www.opensource.org/licenses/cddl1.php
  17. *
  18. * You can obtain a copy of the EPL 1.0 license at
  19. * http://www.opensource.org/licenses/eclipse-1.0.php
  20. *
  21. * See the Licenses for the specific language governing permissions and
  22. * limitations under the Licenses.
  23. *
  24. * Alternatively, you can obtain a royalty free commercial license with less
  25. * limitations, transferable or non-transferable, directly at
  26. * http://www.noelios.com/products/restlet-engine
  27. *
  28. * Restlet is a registered trademark of Noelios Technologies.
  29. */
  30. package org.restlet.util;
  31. import java.util.List;
  32. import java.util.Map;
  33. import org.restlet.Request;
  34. import org.restlet.Response;
  35. import org.restlet.Uniform;
  36. import org.restlet.data.ChallengeResponse;
  37. import org.restlet.data.ClientInfo;
  38. import org.restlet.data.Conditions;
  39. import org.restlet.data.Cookie;
  40. import org.restlet.data.Form;
  41. import org.restlet.data.MediaType;
  42. import org.restlet.data.Method;
  43. import org.restlet.data.Protocol;
  44. import org.restlet.data.Range;
  45. import org.restlet.data.Reference;
  46. import org.restlet.representation.Representation;
  47. /**
  48. * Request wrapper. Useful for application developer who need to enrich the
  49. * request with application related properties and behavior.
  50. *
  51. * @see <a href="http://c2.com/cgi/wiki?DecoratorPattern">The decorator (aka
  52. * wrapper) pattern</a>
  53. * @author Jerome Louvel
  54. */
  55. public class WrapperRequest extends Request {
  56. /** The wrapped request. */
  57. private final Request wrappedRequest;
  58. /**
  59. * Constructor.
  60. *
  61. * @param wrappedRequest
  62. * The wrapped request.
  63. */
  64. public WrapperRequest(Request wrappedRequest) {
  65. this.wrappedRequest = wrappedRequest;
  66. }
  67. @Override
  68. public boolean abort() {
  69. return wrappedRequest.abort();
  70. }
  71. @Override
  72. public void commit(Response response) {
  73. wrappedRequest.commit(response);
  74. }
  75. /**
  76. * Returns a modifiable attributes map that can be used by developers to
  77. * save information relative to the message. This is an easier alternative
  78. * to the creation of a wrapper instance around the whole message.<br>
  79. * <br>
  80. *
  81. * In addition, this map is a shared space between the developer and the
  82. * connectors. In this case, it is used to exchange information that is not
  83. * uniform across all protocols and couldn't therefore be directly included
  84. * in the API. For this purpose, all attribute names starting with
  85. * "org.restlet" are reserved. Currently the following attributes are used:
  86. * <table>
  87. * <tr>
  88. * <th>Attribute name</th>
  89. * <th>Class name</th>
  90. * <th>Description</th>
  91. * </tr>
  92. * <tr>
  93. * <td>org.restlet.http.headers</td>
  94. * <td>org.restlet.data.Form</td>
  95. * <td>Server HTTP connectors must provide all request headers and client
  96. * HTTP connectors must provide all response headers, exactly as they were
  97. * received. In addition, developers can also use this attribute to specify
  98. * <b>non-standard</b> headers that should be added to the request or to the
  99. * response.</td>
  100. * </tr>
  101. * </table>
  102. * Adding standard HTTP headers is forbidden because it could conflict with
  103. * the connector's internal behavior, limit portability or prevent future
  104. * optimizations.</td>
  105. *
  106. * @return The modifiable attributes map.
  107. */
  108. @Override
  109. public Map<String, Object> getAttributes() {
  110. return getWrappedRequest().getAttributes();
  111. }
  112. /**
  113. * Returns the authentication response sent by a client to an origin server.
  114. *
  115. * @return The authentication response sent by a client to an origin server.
  116. */
  117. @Override
  118. public ChallengeResponse getChallengeResponse() {
  119. return getWrappedRequest().getChallengeResponse();
  120. }
  121. /**
  122. * Returns the client-specific information.
  123. *
  124. * @return The client-specific information.
  125. */
  126. @Override
  127. public ClientInfo getClientInfo() {
  128. return getWrappedRequest().getClientInfo();
  129. }
  130. /**
  131. * Returns the conditions applying to this call.
  132. *
  133. * @return The conditions applying to this call.
  134. */
  135. @Override
  136. public Conditions getConditions() {
  137. return getWrappedRequest().getConditions();
  138. }
  139. /**
  140. * Returns the cookies provided by the client.
  141. *
  142. * @return The cookies provided by the client.
  143. */
  144. @Override
  145. public Series<Cookie> getCookies() {
  146. return getWrappedRequest().getCookies();
  147. }
  148. /**
  149. * Returns the entity representation.
  150. *
  151. * @return The entity representation.
  152. */
  153. @Override
  154. public Representation getEntity() {
  155. return getWrappedRequest().getEntity();
  156. }
  157. /**
  158. * Returns the entity as a DOM representation.<br>
  159. * Note that this triggers the parsing of the entity into a reusable DOM
  160. * document stored in memory.<br>
  161. * This method and the related getEntity*() methods can only be invoked
  162. * once.
  163. *
  164. * @return The entity as a DOM representation.
  165. * @deprecated Will be removed in future release 2.1.
  166. */
  167. @Deprecated
  168. @Override
  169. public Form getEntityAsForm() {
  170. return getWrappedRequest().getEntityAsForm();
  171. }
  172. /**
  173. * Returns the host reference. This may be different from the resourceRef's
  174. * host, for example for URNs and other URIs that don't contain host
  175. * information.
  176. *
  177. * @return The host reference.
  178. */
  179. @Override
  180. public Reference getHostRef() {
  181. return getWrappedRequest().getHostRef();
  182. }
  183. @Override
  184. public int getMaxForwards() {
  185. return wrappedRequest.getMaxForwards();
  186. }
  187. /**
  188. * Returns the method.
  189. *
  190. * @return The method.
  191. */
  192. @Override
  193. public Method getMethod() {
  194. return getWrappedRequest().getMethod();
  195. }
  196. @Override
  197. public Uniform getOnResponse() {
  198. return wrappedRequest.getOnResponse();
  199. }
  200. @Override
  201. public Reference getOriginalRef() {
  202. return wrappedRequest.getOriginalRef();
  203. }
  204. /**
  205. * Returns the protocol by first returning the baseRef.schemeProtocol
  206. * property if it is set, or the resourceRef.schemeProtocol property
  207. * otherwise.
  208. *
  209. * @return The protocol or null if not available.
  210. */
  211. @Override
  212. public Protocol getProtocol() {
  213. return getWrappedRequest().getProtocol();
  214. }
  215. /**
  216. * Returns the authentication response sent by a client to a proxy.
  217. *
  218. * @return The authentication response sent by a client to a proxy.
  219. */
  220. @Override
  221. public ChallengeResponse getProxyChallengeResponse() {
  222. return getWrappedRequest().getProxyChallengeResponse();
  223. }
  224. @Override
  225. public List<Range> getRanges() {
  226. return wrappedRequest.getRanges();
  227. }
  228. /**
  229. * Returns the referrer reference if available.
  230. *
  231. * @return The referrer reference.
  232. */
  233. @Override
  234. public Reference getReferrerRef() {
  235. return getWrappedRequest().getReferrerRef();
  236. }
  237. /**
  238. * Returns the reference of the target resource.
  239. *
  240. * @return The reference of the target resource.
  241. */
  242. @Override
  243. public Reference getResourceRef() {
  244. return getWrappedRequest().getResourceRef();
  245. }
  246. /**
  247. * Returns the application root reference.
  248. *
  249. * @return The application root reference.
  250. */
  251. @Override
  252. public Reference getRootRef() {
  253. return getWrappedRequest().getRootRef();
  254. }
  255. /**
  256. * Returns the wrapped request.
  257. *
  258. * @return The wrapped request.
  259. */
  260. protected Request getWrappedRequest() {
  261. return this.wrappedRequest;
  262. }
  263. /**
  264. * Indicates if the call came over a confidential channel such as an
  265. * SSL-secured connection.
  266. *
  267. * @return True if the call came over a confidential channel.
  268. */
  269. @Override
  270. public boolean isConfidential() {
  271. return getWrappedRequest().isConfidential();
  272. }
  273. /**
  274. * Indicates if a content is available and can be sent. Several conditions
  275. * must be met: the method must allow the sending of content, the content
  276. * must exists and have some available data.
  277. *
  278. * @return True if a content is available and can be sent.
  279. */
  280. @Override
  281. public boolean isEntityAvailable() {
  282. return getWrappedRequest().isEntityAvailable();
  283. }
  284. @Override
  285. public boolean isExpectingResponse() {
  286. return wrappedRequest.isExpectingResponse();
  287. }
  288. /**
  289. * Sets the authentication response sent by a client to an origin server.
  290. *
  291. * @param response
  292. * The authentication response sent by a client to an origin
  293. * server.
  294. */
  295. @Override
  296. public void setChallengeResponse(ChallengeResponse response) {
  297. getWrappedRequest().setChallengeResponse(response);
  298. }
  299. @Override
  300. public void setClientInfo(ClientInfo clientInfo) {
  301. wrappedRequest.setClientInfo(clientInfo);
  302. }
  303. @Override
  304. public void setConditions(Conditions conditions) {
  305. wrappedRequest.setConditions(conditions);
  306. }
  307. @Override
  308. public void setCookies(Series<Cookie> cookies) {
  309. wrappedRequest.setCookies(cookies);
  310. }
  311. /**
  312. * Sets the entity representation.
  313. *
  314. * @param entity
  315. * The entity representation.
  316. */
  317. @Override
  318. public void setEntity(Representation entity) {
  319. getWrappedRequest().setEntity(entity);
  320. }
  321. /**
  322. * Sets a textual entity.
  323. *
  324. * @param value
  325. * The represented string.
  326. * @param mediaType
  327. * The representation's media type.
  328. */
  329. @Override
  330. public void setEntity(String value, MediaType mediaType) {
  331. getWrappedRequest().setEntity(value, mediaType);
  332. }
  333. /**
  334. * Sets the host reference.
  335. *
  336. * @param hostRef
  337. * The host reference.
  338. */
  339. @Override
  340. public void setHostRef(Reference hostRef) {
  341. getWrappedRequest().setHostRef(hostRef);
  342. }
  343. /**
  344. * Sets the host reference using an URI string.
  345. *
  346. * @param hostUri
  347. * The host URI.
  348. */
  349. @Override
  350. public void setHostRef(String hostUri) {
  351. getWrappedRequest().setHostRef(hostUri);
  352. }
  353. @Override
  354. public void setMaxForwards(int maxForwards) {
  355. wrappedRequest.setMaxForwards(maxForwards);
  356. }
  357. /**
  358. * Sets the method called.
  359. *
  360. * @param method
  361. * The method called.
  362. */
  363. @Override
  364. public void setMethod(Method method) {
  365. getWrappedRequest().setMethod(method);
  366. }
  367. @Override
  368. public void setOnResponse(Uniform onResponseCallback) {
  369. wrappedRequest.setOnResponse(onResponseCallback);
  370. }
  371. @Override
  372. public void setOriginalRef(Reference originalRef) {
  373. wrappedRequest.setOriginalRef(originalRef);
  374. }
  375. @Override
  376. public void setProtocol(Protocol protocol) {
  377. wrappedRequest.setProtocol(protocol);
  378. }
  379. /**
  380. * Sets the authentication response sent by a client to a proxy.
  381. *
  382. * @param response
  383. * The authentication response sent by a client to a proxy.
  384. */
  385. @Override
  386. public void setProxyChallengeResponse(ChallengeResponse response) {
  387. getWrappedRequest().setProxyChallengeResponse(response);
  388. }
  389. @Override
  390. public void setRanges(List<Range> ranges) {
  391. wrappedRequest.setRanges(ranges);
  392. }
  393. /**
  394. * Sets the referrer reference if available.
  395. *
  396. * @param referrerRef
  397. * The referrer reference.
  398. */
  399. @Override
  400. public void setReferrerRef(Reference referrerRef) {
  401. getWrappedRequest().setReferrerRef(referrerRef);
  402. }
  403. /**
  404. * Sets the referrer reference if available using an URI string.
  405. *
  406. * @param referrerUri
  407. * The referrer URI.
  408. */
  409. @Override
  410. public void setReferrerRef(String referrerUri) {
  411. getWrappedRequest().setReferrerRef(referrerUri);
  412. }
  413. /**
  414. * Sets the target resource reference. If the reference is relative, it will
  415. * be resolved as an absolute reference. Also, the context's base reference
  416. * will be reset. Finally, the reference will be normalized to ensure a
  417. * consistent handling of the call.
  418. *
  419. * @param resourceRef
  420. * The resource reference.
  421. */
  422. @Override
  423. public void setResourceRef(Reference resourceRef) {
  424. getWrappedRequest().setResourceRef(resourceRef);
  425. }
  426. /**
  427. * Sets the target resource reference using an URI string. Note that the URI
  428. * can be either absolute or relative to the context's base reference.
  429. *
  430. * @param resourceUri
  431. * The resource URI.
  432. */
  433. @Override
  434. public void setResourceRef(String resourceUri) {
  435. getWrappedRequest().setResourceRef(resourceUri);
  436. }
  437. /**
  438. * Sets the application root reference.
  439. *
  440. * @param rootRef
  441. * The application root reference.
  442. */
  443. @Override
  444. public void setRootRef(Reference rootRef) {
  445. getWrappedRequest().setRootRef(rootRef);
  446. }
  447. @Override
  448. public String toString() {
  449. return wrappedRequest.toString();
  450. }
  451. }