View Javadoc

1   /*
2    * Copyright (c) 2005-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.http;
14  
15  import java.io.IOException;
16  import java.text.SimpleDateFormat;
17  import java.util.List;
18  import java.util.Map;
19  
20  import org.abstracthorizon.danube.connection.Connection;
21  import org.abstracthorizon.danube.http.util.MultiStringMap;
22  
23  /**
24   * <p>
25   * This connection represents one HTTP request and response.
26   * It can be reused over the same underlaying connection
27   * (multiple requests over the same socket).
28   * </p>
29   * <p>
30   * This implementation handles HTTP request string, headers and parameters.
31   * </p>
32   *
33   * @author Daniel Sendula
34   */
35  public interface HTTPConnection extends Connection {
36  
37      // Request methods
38      SimpleDateFormat HEADER_DATE_FORMAT = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
39  
40      /**
41       * Returns request protocol
42       * @return request protocol
43       */
44      public String getRequestProtocol();
45  
46      /**
47       * Returns request method
48       * @return request method
49       */
50      public String getRequestMethod();
51  
52      /**
53       * Returns request headers map
54       * @return request headers map
55       */
56      public MultiStringMap getRequestHeaders();
57  
58      /**
59       * Returns request parameters map. If more
60       * then one parameter is supplied with the same name
61       * then {@link List} returned with all parameter
62       * values in it.
63       * @return request parameters map
64       */
65      public MultiStringMap getRequestParameters();
66  
67      /**
68       * Returns raw requested uri along with path info (if supplied
69       * in GET method)
70       * @return raw requested uri
71       */
72      public String getRequestURI();
73  
74      /**
75       * This is similar to {@link #getRequestURI()} but without path info (parameters) part
76       * @return full (unchanged) uri
77       */
78      public String getRequestPath();
79  
80      /**
81       * Returns portion of request path up to component path
82       * @return portion of request path up to component path
83       */
84      public String getContextPath();
85  
86      /**
87       * Updates context path adding new path element to it
88       */
89      public void addComponentPathToContextPath();
90  
91      /**
92       * Returns portion of request URI from context path till end or '?' whichever comes first
93       * @return request path
94       */
95      public String getComponentPath();
96  
97      /**
98       * Sets request uri.
99       * This is to be called from selectors not applicaiton code.
100      *
101      * @param requestURI
102      */
103     public void setComponentPath(String requestURI);
104 
105     /**
106      * Returns remainder of path after context path and component path is removed
107      * @return remainder of path after context path and component path is removed
108      */
109     public String getComponentResourcePath();
110 
111     /**
112      * Sets component resource path
113      * @param resourcePath component resource path
114      */
115     public void setComponentResourcePath(String resourcePath);
116 
117     // Response methods
118 
119     /**
120      * Returns response headers map
121      * @return response headers map
122      */
123     public MultiStringMap getResponseHeaders();
124 
125     /**
126      * Returns response status
127      * @return response status
128      */
129     public Status getResponseStatus();
130 
131     /**
132      * Sets response status
133      * @param status response status
134      */
135     public void setResponseStatus(Status status);
136 
137     /**
138      * Returns response protocol
139      * @return response protocol
140      */
141     public String getResponseProtocol();
142 
143     /**
144      * Sets response protocol
145      * @param protocol response protocol
146      */
147     public void setResponseProtocol(String protocol);
148 
149     /**
150      * Returns <code>true</code> if headers are already send back to the client
151      * TODO - maybe this method is not needed!
152      * @return <code>true</code> if headers are already send back to the client
153      */
154     public boolean isCommited();
155 
156     /**
157      * This method processes request.
158      * It extracts method, uri, parameters (GET or POST),
159      * protocol version and headers.
160      */
161     public void reset();
162 
163     /**
164      * This method returns map of attributes.
165      *
166      * @return map of attributes
167      */
168     public Map<String, Object> getAttributes();
169 
170     /**
171      * Forwards request.
172      * @param path uri for request to be forwarded to.
173      * @throws IOException if underlaying handler had IOException
174      */
175     public void forward(String path);
176 
177     /**
178      * Sets buffer size
179      *
180      * @param size buffer size
181      */
182     public void setBufferSize(int size);
183 
184     /**
185      * Returns buffer size
186      *
187      * @return buffer size
188      */
189     public int getBufferSize();
190 }