📄 httpmessageservlet.java
字号:
b.append(" COOKIE[" + i + "]:" + nl); b.append(" comment: " + cookies[i].getComment() + nl); b.append(" domain: " + cookies[i].getDomain() + nl); b.append(" max age: " + cookies[i].getMaxAge() + nl); b.append(" name: " + cookies[i].getName() + nl); b.append(" path: " + cookies[i].getPath() + nl); b.append(" secure: " + cookies[i].getSecure() + nl); b.append(" value: " + cookies[i].getValue() + nl); b.append(" version: " + cookies[i].getVersion() + nl); } } for (Enumeration headers = req.getHeaderNames(); headers.hasMoreElements();) { String header = (String) headers.nextElement(); b.append(" HEADER[" + header + "]: " + req.getHeader(header) + nl); } b.append(" METHOD: " + req.getMethod() + nl); b.append(" PATH_INFO: " + req.getPathInfo() + nl); b.append(" PATH_TRANSLATED: " + req.getPathTranslated() + nl); b.append(" QUERY_STRING: " + req.getQueryString() + nl); b.append(" REMOTE_USER: " + req.getRemoteUser() + nl); b.append(" REQUESTED_SESSION_ID: " + req.getRequestedSessionId() + nl); b.append(" REQUEST_URI: " + req.getRequestURI() + nl); b.append(" SERVLET_PATH: " + req.getServletPath() + nl); b.append(" REMOTE_USER: " + req.getRemoteUser() + nl); b.append(" isSessionIdFromCookie: " + req.isRequestedSessionIdFromCookie() + nl); b.append(" isSessionIdFromURL: " + req.isRequestedSessionIdFromURL() + nl); b.append(" isSessionIdValid: " + req.isRequestedSessionIdValid() + nl); for (Enumeration attributes = req.getAttributeNames(); attributes.hasMoreElements();) { String attribute = (String) attributes.nextElement(); b.append(" ATTRIBUTE[" + attribute + "]: " + req.getAttribute(attribute) + nl); } b.append(" ENCODING: " + req.getCharacterEncoding() + nl); b.append(" CONTENT_LENGTH: " + req.getContentLength() + nl); b.append(" CONTENT_TYPE: " + req.getContentType() + nl); b.append(" LOCALE: " + req.getLocale().toString() + nl); for (Enumeration parameters = req.getParameterNames(); parameters.hasMoreElements();) { String parameter = (String) parameters.nextElement(); b.append(" PARAMETER[" + parameter + "]: " + req.getParameter(parameter) + nl); } b.append(" PROTOCOL: " + req.getProtocol() + nl); b.append(" REMOTE_ADDR: " + req.getRemoteAddr() + nl); b.append(" REMOTE_HOST: " + req.getRemoteHost() + nl); b.append(" SCHEME: " + req.getScheme() + nl); b.append(" SERVER_NAME: " + req.getServerName() + nl); b.append(" SERVER_PORT: " + req.getServerPort() + nl); b.append(" isSecure: " + req.isSecure()); LOG.trace(b); } /** * A servlet request. * * @see <a href="http://spec.jxta.org/nonav/v1.0/docbook/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><0</tt> : No response message wanted.</li> * <li><tt> 0</tt> : Wait indefinitely for response message.</li> * <li><tt>>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><0</tt> : No additional response messages wanted.</li> * <li><tt> 0</tt> : Wait indefinitely for additional response messages.</li> * <li><tt>>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 (LOG.isEnabledFor(Level.TRACE)) { LOG.trace("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 (LOG.isEnabledFor(Level.TRACE)) { LOG.trace("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 (LOG.isEnabledFor(Level.WARN)) { LOG.warn("The requestTimeout does not contain a decimal number " + requestTimeoutString); } } if (LOG.isEnabledFor(Level.TRACE)) { LOG.trace("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 (LOG.isEnabledFor(Level.WARN)) { LOG.warn("The extraResponseTimeoutString does not contain a decimal number " + extraResponseTimeoutString); } } if (LOG.isEnabledFor(Level.DEBUG)) { LOG.debug("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 (LOG.isEnabledFor(Level.TRACE)) { LOG.trace("hasMessageContent = " + hasContent); } return hasContent; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -