Commits

Ning Sun  committed 13fc68e

add Environ class

  • Participants
  • Parent commits 30f4852

Comments (0)

Files changed (1)

File java/info/sunng/wsgiservlet/wsgi/Environ.java

-# Copyright (C) 2011 Sun Ning<classicning@gmail.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-#
+/** 
+ * Copyright (C) 2011 Sun Ning<classicning@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
 
 package info.sunng.wsgiservlet.wsgi;
 
+import java.io.IOException;
+import java.util.Enumeration;
 import javax.servlet.http.HttpServletRequest;
 
 import org.python.core.PyBoolean;
 import org.python.core.PyDictionary;
 import org.python.core.PyFile;
 import org.python.core.PyInteger;
+import org.python.core.PyObject;
 import org.python.core.PyString;
 import org.python.core.PyTuple;
 import org.python.core.util.FileUtil;
     protected static final PyInteger ONE = new PyInteger(1);
     
     public Environ(HttpServletRequest request) {
-        initFromRequest(request);
     }
         
-    private void initFromRequest(HttpServletRequest request) {
+    private void initFromRequest(HttpServletRequest request) throws IOException {
         
         this.setValue("wsgi.version", new PyTuple(ONE, ZERO));
-        this.setValue("wsgi.url_scheme", request.getScheme())
+        this.setValue("wsgi.url_scheme", request.getScheme());
         this.setValue("wsgi.multithread", true);
         this.setValue("wsgi.multiprocess", false);
         this.setValue("wsgi.run_once", false);
         this.setValue("PATH_INFO", request.getRequestURI());
         this.setValue("QUERY_STRING", request.getQueryString());
         this.setValue("CONTENT_TYPE", request.getHeader("Content-Type"));
-        this.setValue("CONTENT_LENGTH", request.getHeader("Content-Length"))
+        this.setValue("CONTENT_LENGTH", request.getHeader("Content-Length"));
         this.setValue("SERVER_NAME", request.getLocalName());
         this.setValue("SERVER_PORT", request.getLocalPort());
         this.setValue("REMOTE_ADDR", request.getRemoteHost());
     private void initHeaders(HttpServletRequest request) {
         Enumeration headerNames = request.getHeaderNames();
         while(headerNames.hasMoreElements()){
-            String headerName = headerNames.nextElement();
+            String headerName = (String)headerNames.nextElement();
             String keyName = "HTTP_"+headerName.replace("-", "_");
             this.setValue(keyName, request.getHeader(headerName));
         }