⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpmessageservlet.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        Cookie[] cookies = req.getCookies();        if (cookies != null) {            for (int i = 0; i < cookies.length; i++) {                builder.append("  COOKIE[").append(i).append("]:" + nl);                builder.append("    comment: ").append(cookies[i].getComment()).append(nl);                builder.append("    domain: ").append(cookies[i].getDomain()).append(nl);                builder.append("    max age: ").append(cookies[i].getMaxAge()).append(nl);                builder.append("    name: ").append(cookies[i].getName()).append(nl);                builder.append("    path: ").append(cookies[i].getPath()).append(nl);                builder.append("    secure: ").append(cookies[i].getSecure()).append(nl);                builder.append("    value: ").append(cookies[i].getValue()).append(nl);                builder.append("    version: ").append(cookies[i].getVersion()).append(nl);            }        }        for (Enumeration headers = req.getHeaderNames(); headers.hasMoreElements();) {            String header = (String) headers.nextElement();            builder.append("  HEADER[").append(header).append("]: ").append(req.getHeader(header)).append(nl);        }        builder.append("  METHOD: ").append(req.getMethod()).append(nl);        builder.append("  PATH_INFO: ").append(req.getPathInfo()).append(nl);        builder.append("  PATH_TRANSLATED: ").append(req.getPathTranslated()).append(nl);        builder.append("  QUERY_STRING: ").append(req.getQueryString()).append(nl);        builder.append("  REMOTE_USER: ").append(req.getRemoteUser()).append(nl);        builder.append("  REQUESTED_SESSION_ID: ").append(req.getRequestedSessionId()).append(nl);        builder.append("  REQUEST_URI: ").append(req.getRequestURI()).append(nl);        builder.append("  SERVLET_PATH: ").append(req.getServletPath()).append(nl);        builder.append("  REMOTE_USER: ").append(req.getRemoteUser()).append(nl);        builder.append("  isSessionIdFromCookie: ").append(req.isRequestedSessionIdFromCookie()).append(nl);        builder.append("  isSessionIdFromURL: ").append(req.isRequestedSessionIdFromURL()).append(nl);        builder.append("  isSessionIdValid: ").append(req.isRequestedSessionIdValid()).append(nl);        for (Enumeration attributes = req.getAttributeNames(); attributes.hasMoreElements();) {            String attribute = (String) attributes.nextElement();            builder.append("  ATTRIBUTE[").append(attribute).append("]: ").append(req.getAttribute(attribute)).append(nl);        }        builder.append("  ENCODING: ").append(req.getCharacterEncoding()).append(nl);        builder.append("  CONTENT_LENGTH: ").append(req.getContentLength()).append(nl);        builder.append("  CONTENT_TYPE: ").append(req.getContentType()).append(nl);        builder.append("  LOCALE: ").append(req.getLocale().toString()).append(nl);        for (Enumeration parameters = req.getParameterNames(); parameters.hasMoreElements();) {            String parameter = (String) parameters.nextElement();            builder.append("  PARAMETER[").append(parameter).append("]: ").append(req.getParameter(parameter)).append(nl);        }        builder.append("  PROTOCOL: ").append(req.getProtocol()).append(nl);        builder.append("  REMOTE_ADDR: ").append(req.getRemoteAddr()).append(nl);        builder.append("  REMOTE_HOST: ").append(req.getRemoteHost()).append(nl);        builder.append("  SCHEME: ").append(req.getScheme()).append(nl);        builder.append("  SERVER_NAME: ").append(req.getServerName()).append(nl);        builder.append("  SERVER_PORT: ").append(req.getServerPort()).append(nl);        builder.append("  isSecure: ").append(req.isSecure());        LOG.finest(builder.toString());    }    /**     *  A servlet request.     *     *  @see <a href="https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html#trans-httpt-msg-msgs" target="_blank">JXTA Protocols Specification : Standard JXTA Transport Bindings : HTTP Bindings</a>     */    private static class JxtaRequest {        /**         *  Absolute time in milliseconds at which this request began processing.         */        final long requestStartTime;        /**         *  Endpoint address of the requestor.         */        final EndpointAddress requestorAddr;        /**         *  Duration of time to wait for the initial response message.         *         *  <p/><ul>         *      <li><tt>&lt;0</tt> : No response message wanted.</li>         *      <li><tt> 0</tt> : Wait indefinitely for response message.</li>         *      <li><tt>&gt;0</tt> : Wait specified amount of time for response message.</li>         *  </ul>         */        final long responseTimeout;        /**         *  Duration of time to wait for additional response messages.         *         *  <p/><ul>         *      <li><tt>&lt;0</tt> : No additional response messages wanted.</li>         *      <li><tt> 0</tt> : Wait indefinitely for additional response messages.</li>         *      <li><tt>&gt;0</tt> : Wait specified amount of time for additional response messages.</li>         *  </ul>         */        final long extraResponsesTimeout;        /**         *  Destination address for messages sent in this connection.         */        final EndpointAddress destAddr;        /**         *  If <tt>true</tt> then the requestor is providing a Message.         */        final boolean messageContent;        /**         *  Construct a request.         */        JxtaRequest(HttpServletRequest req) {            requestStartTime = TimeUtils.timeNow();            // check if a peerId was given            String requestorPeerId = getRequestorPeerId(req);            if (null != requestorPeerId) {                requestorAddr = new EndpointAddress("jxta", requestorPeerId, null, null);            } else {                requestorAddr = null;            }            // get the query string            String queryString = req.getQueryString();            if (queryString != null) {                // the query string is of the format responseTimeout,extraResponsesTimeout,destAdd                // the times given are in milliseconds                int commaIndex = queryString.indexOf(',');                if (commaIndex == -1) {                    // there is no extra responses timeout                    responseTimeout = getResponseTimeout(queryString);                    extraResponsesTimeout = -1;                    destAddr = null;                } else {                    responseTimeout = getResponseTimeout(queryString.substring(0, commaIndex));                    String moreQueryParams = queryString.substring(commaIndex + 1);                    commaIndex = moreQueryParams.indexOf(',');                    if (commaIndex == -1) {                        extraResponsesTimeout = getExtraResponsesTimeout(moreQueryParams);                        destAddr = null;                    } else {                        extraResponsesTimeout = getExtraResponsesTimeout(moreQueryParams.substring(0, commaIndex));                        destAddr = new EndpointAddress(moreQueryParams.substring(commaIndex + 1));                    }                }            } else {                responseTimeout = 0;                extraResponsesTimeout = -1;                destAddr = null;            }                       // check for incoming message            messageContent = hasMessageContent(req);            if (Logging.SHOW_FINER && LOG.isLoggable(Level.FINER)) {                LOG.finer(                        "New JXTA Request for Requestor=" + requestorAddr + "\n\tResponse Timeout=" + responseTimeout                        + "\tAdditional Response Timeout=" + extraResponsesTimeout + "\tRequest Destination Address=" + destAddr                        + "\tHas Message Content=" + Boolean.toString(messageContent));            }        }        /**         * Returns the peerId of the peer making the request, if given         */        private static String getRequestorPeerId(HttpServletRequest req) {            // get the potential PeerId from the PathInfo            String requestorPeerId = req.getPathInfo();            if (null != requestorPeerId) {                int begin = 0;                int end = requestorPeerId.length();                // check for all leading "/"                while (begin < end && requestorPeerId.charAt(begin) == '/') {                    begin++;                }                // check for all trailing "/"                while (end - begin > 0 && requestorPeerId.charAt(end - 1) == '/') {                    end--;                }                if (begin == end) {                    // nothing left of the string                    requestorPeerId = null;                } else {                    // get the new substring                    requestorPeerId = requestorPeerId.substring(begin, end);                }            }            if (Logging.SHOW_FINER && LOG.isLoggable(Level.FINER)) {                LOG.finer("requestorPeerId = " + requestorPeerId);            }            return requestorPeerId;        }        /**         * Returns the request timeout or -1 if a request timeout is not given         */        private static long getResponseTimeout(String requestTimeoutString) {            // the default timeout is -1, which means do not return a message            long timeout = -1;            try {                timeout = Long.parseLong(requestTimeoutString);                // Protect agains clients that will try top have us keep                // connections for ever. If they re-establish all the time it's                // fine, but until we have a more sophisticated mechanism, we                // want to make sure we quit timely if the client's gone.                if (timeout > MAXIMUM_RESPONSE_DURATION || timeout == 0) {                    timeout = MAXIMUM_RESPONSE_DURATION;                }            } catch (NumberFormatException e) {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("The requestTimeout does not contain a decimal number " + requestTimeoutString);                }            }            if (Logging.SHOW_FINER && LOG.isLoggable(Level.FINER)) {                LOG.finer("requestTimeout = " + timeout);            }            return timeout;        }        /**         * Returns the lazy close timeout or -1 if a lazy close timeout is not given         */        private static long getExtraResponsesTimeout(String extraResponseTimeoutString) {            // the default timeout is -1, which means do not wait for additional messages            long timeout = -1;            try {                timeout = Long.parseLong(extraResponseTimeoutString);                // Protect agains clients that will try top have us keep                // connections for ever. If they re-establish all the time it's                // fine, but until we have a more sophisticated mechanism, we                // want to make sure we quit timely if the client's gone.                if (timeout > (2 * TimeUtils.AMINUTE) || timeout == 0) {                    timeout = (2 * TimeUtils.AMINUTE);                }            } catch (NumberFormatException e) {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.warning("The extraResponseTimeoutString does not contain a decimal number " + extraResponseTimeoutString);                }            }            if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) {                LOG.fine("extraResponseTimeout = " + timeout);            }            return timeout;        }        /**         *  Checks if the request includes a message as content.         *         *  @param req The request to be inspected.         *  @return <tt>true</tt> if there is content to be read from this request.         */        private static boolean hasMessageContent(HttpServletRequest req) {            boolean hasContent = false;            int contentLength = req.getContentLength();            // if the content length is not zero, there is an incoming message            // Either the message length is given or it is a chunked message            if (contentLength > 0) {                hasContent = true;            } else if (contentLength == -1) {                // check if the transfer encoding is chunked                String transferEncoding = req.getHeader("Transfer-Encoding");                hasContent = "chunked".equals(transferEncoding);            }            if (Logging.SHOW_FINER && LOG.isLoggable(Level.FINER)) {                LOG.finer("hasMessageContent = " + hasContent);            }            return hasContent;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -