* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with any library licensed under the Apache Software License,
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
- * (or with modified versions of the above that use the same license as the above),
- * and distribute linked combinations including the two. You must obey the
- * GNU General Public License in all respects for all of the code used other than
- * the above mentioned libraries. If you modify this file, you may extend this
- * exception to your version of the file, but you are not obligated to do so.
+ * the code of this program with any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two. You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries. If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package mir.session;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Vector;
-
+import java.util.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import mir.util.HTTPParsedRequest;
-
import org.apache.commons.fileupload.FileItem;
public class HTTPAdapters {
public static class HTTPRequestAdapter implements Request {
private HttpServletRequest request;
+ private String cachedHostName = null;
public HTTPRequestAdapter(HttpServletRequest aRequest) {
request = aRequest;
}
+ public String getHeader(String aHeaderName) {
+ if (aHeaderName.equals("ip"))
+ return request.getRemoteAddr();
+
+ if (aHeaderName.equals("hostname")) {
+ if (aHeaderName.equals("hostname")) {
+ if (cachedHostName==null) {
+ try {
+ cachedHostName = InetAddress.getByName(request.getRemoteAddr()).getHostName();
+ }
+ catch (UnknownHostException e) {
+ cachedHostName = request.getRemoteAddr();
+ }
+ }
+
+ return cachedHostName;
+ }
+
+ }
+
+ return request.getHeader(aHeaderName);
+ };
+
public String getParameter(String aName) {
return request.getParameter(aName);
};
+ public List getPrefixedParameterNames(String aPrefix) {
+ List result = new ArrayList();
+
+ Enumeration enumeration = request.getParameterNames();
+ while (enumeration.hasMoreElements()) {
+ String name = (String) enumeration.nextElement();
+ if (name.startsWith(aPrefix)) {
+ result.add(name);
+ }
+ }
+
+ return result;
+ };
+
public List getUploadedFiles() {
- return new Vector();
+ return Collections.EMPTY_LIST;
};
public List getParameters(String aName) {
public static class HTTPParsedRequestAdapter implements Request {
private HTTPParsedRequest request;
+ private String cachedHostName = null;
public HTTPParsedRequestAdapter(HTTPParsedRequest aRequest) {
request = aRequest;
}
+ public String getHeader(String aHeaderName) {
+ if (aHeaderName.equals("ip"))
+ return request.getRequest().getRemoteAddr();
+
+ if (aHeaderName.equals("hostname")) {
+ if (cachedHostName==null) {
+ try {
+ cachedHostName = InetAddress.getByName(request.getRequest().getRemoteAddr()).getHostName();
+ }
+ catch (UnknownHostException e) {
+ cachedHostName = request.getRequest().getRemoteAddr();
+ }
+ }
+
+ return cachedHostName;
+ }
+
+ return request.getHeader(aHeaderName);
+ }
+
public String getParameter(String aName) {
return request.getParameter(aName);
};
return request.getParameterList(aName);
};
+ public List getPrefixedParameterNames(String aPrefix) {
+ List result = new ArrayList();
+
+ Iterator i = request.getParameterNames().iterator();
+
+ while (i.hasNext()) {
+ String name = (String) i.next();
+ if (name.startsWith(aPrefix)) {
+ result.add(name);
+ }
+ }
+
+ return result;
+ };
+
public List getUploadedFiles() {
- List result = new Vector();
+ List result = new ArrayList();
List files = request.getFiles();
for (int i=0; i<files.size(); i++) {
}
public void setAttribute(String aName, Object aNewValue) {
- session.setAttribute(aName, aNewValue);
+ if (aName.equals("$httpsessiontimeout")) {
+ if (aNewValue instanceof Number) {
+ try {
+ session.setMaxInactiveInterval( ( (Number) aNewValue).intValue());
+ }
+ catch (Throwable t) {
+ }
+ }
+ }
+ else {
+ if (aNewValue == null)
+ deleteAttribute(aName);
+ else
+ session.setAttribute(aName, aNewValue);
+ }
}
public void terminate() {