if ((host != null) && (host.toLowerCase().indexOf(cookieDomain) == -1)) {
String proxiedHost = request.getHeader("x-forwarded-host"); if (proxiedHost != null) { if (proxiedHost.toLowerCase().indexOf(cookieDomain) == -1) { resCookieDomain = null; } } else if ((host != null) && host.toLowerCase().indexOf(cookieDomain) == -1) {
    protected void service (HttpServletRequest request, HttpServletResponse response)                throws ServletException, IOException {        RequestTrans reqtrans = new RequestTrans(request, response, getPathInfo(request));        try {            // get the character encoding            String encoding = request.getCharacterEncoding();            if (encoding == null) {                // no encoding from request, use the application's charset                encoding = getApplication().getCharset();            }            // read and set http parameters            Map parameters = parseParameters(request, encoding);            for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {                Map.Entry entry = (Map.Entry) i.next();                String key = (String) entry.getKey();                String[] values = (String[]) entry.getValue();                if ((values != null) && (values.length > 0)) {                    reqtrans.set(key, values[0]); // set to single string value                    if (values.length > 1) {                        reqtrans.set(key + "_array", values); // set string array                    }                }            }            if (FileUpload.isMultipartContent(request)) {                // File Upload                try {                    DiskFileUpload upload = new DiskFileUpload();                    upload.setSizeMax(uploadLimit * 1024);                    upload.setHeaderEncoding(encoding);                    List uploads = upload.parseRequest(request);                    Iterator it = uploads.iterator();                    while (it.hasNext()) {                        FileItem item = (FileItem) it.next();                        String name = item.getFieldName();                        Object value = null;                        // check if this is an ordinary HTML form element or a file upload                        if (item.isFormField()) {                            value =  item.getString(encoding);                        } else {                            value = new MimePart(item.getName(),                                    item.get(),                                    item.getContentType());                        }                        item.delete();                        // if multiple values exist for this name, append to _array                        if (reqtrans.get(name) != null) {                            appendFormValue(reqtrans, name, value);                        } else {                            reqtrans.set(name, value);                        }                    }                } catch (Exception upx) {                    System.err.println("Error in file upload: " + upx);                    if (uploadSoftfail) {                        String msg = upx.getMessage();                        if (msg == null || msg.length() == 0) {                            msg = upx.toString();                        }                        reqtrans.set("helma_upload_error", msg);                    } else if (upx instanceof FileUploadBase.SizeLimitExceededException) {                        sendError(response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,                              "File upload size exceeds limit of " + uploadLimit + "kB");                        return;                    } else {                        sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,                              "Error in file upload: " + upx);                        return;                    }                }            }            // read cookies            Cookie[] reqCookies = request.getCookies();            if (reqCookies != null) {                for (int i = 0; i < reqCookies.length; i++)                    try {                        // get Cookies                        String nextKey = reqCookies[i].getName();                        String nextPart = reqCookies[i].getValue();                        if (sessionCookieName.equals(nextKey)) {                            reqtrans.setSession(nextPart);                        } else {                            reqtrans.set(nextKey, nextPart);                        }                                   } catch (Exception badCookie) {                        // ignore                    }            }            // do standard HTTP variables            String host = request.getHeader("Host");            if (host != null) {                host = host.toLowerCase();                reqtrans.set("http_host", host);            }            String referer = request.getHeader("Referer");            if (referer != null) {                reqtrans.set("http_referer", referer);            }            try {                long ifModifiedSince = request.getDateHeader("If-Modified-Since");                if (ifModifiedSince > -1) {                    reqtrans.setIfModifiedSince(ifModifiedSince);                }            } catch (IllegalArgumentException ignore) {            }            String ifNoneMatch = request.getHeader("If-None-Match");            if (ifNoneMatch != null) {                reqtrans.setETags(ifNoneMatch);            }            String remotehost = request.getRemoteAddr();            if (remotehost != null) {                reqtrans.set("http_remotehost", remotehost);            }            // get the cookie domain to use for this response, if any.            String resCookieDomain = cookieDomain;            if (resCookieDomain != null) {                // check if cookieDomain is valid for this response.                // (note: cookieDomain is guaranteed to be lower case)                if ((host != null) && (host.toLowerCase().indexOf(cookieDomain) == -1)) {                    resCookieDomain = null;                }            }            // check if session cookie is present and valid, creating it if not.            checkSessionCookie(request, response, reqtrans, resCookieDomain);            String browser = request.getHeader("User-Agent");            if (browser != null) {                reqtrans.set("http_browser", browser);            }                       String language = request.getHeader("Accept-Language");                        if (language != null) {                reqtrans.set("http_language", language);            }                         String authorization = request.getHeader("authorization");            if (authorization != null) {                reqtrans.set("authorization", authorization);            }            ResponseTrans restrans = getApplication().execute(reqtrans);            // if the response was already written and committed by the application            // we can skip this part and return            if (response.isCommitted()) {                return;            }            // set cookies            if (restrans.countCookies() > 0) {                CookieTrans[] resCookies = restrans.getCookies();                for (int i = 0; i < resCookies.length; i++)                    try {                        Cookie c = resCookies[i].getCookie("/", resCookieDomain);                        response.addCookie(c);                    } catch (Exception ignore) {                    }            }            // write response            writeResponse(request, response, restrans);        } catch (Exception x) {            try {                if (debug) {                    sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,                              "Server error: " + x);                    x.printStackTrace();                } else {                    sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,                              "The server encountered an error while processing your request. " +                              "Please check back later.");                }                log("Exception in execute: " + x);            } catch (IOException io_e) {                log("Exception in sendError: " + io_e);            }        }    }