Repository: mina Updated Branches: refs/heads/2.0 3ff1bf1aa -> e5d1758cd
o Fixed missing javadocs o Fixed sonarlint warnings Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/cb9bb7cf Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/cb9bb7cf Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/cb9bb7cf Branch: refs/heads/2.0 Commit: cb9bb7cf1d3103fbfeb6b376e86570fc7c3a9534 Parents: 9f00651 850bc14 Author: Emmanuel Lécharny <[email protected]> Authored: Fri Dec 9 11:15:18 2016 +0100 Committer: Emmanuel Lécharny <[email protected]> Committed: Fri Dec 9 14:26:33 2016 +0100 ---------------------------------------------------------------------- .../apache/mina/proxy/event/IoSessionEvent.java | 42 +++--- .../mina/proxy/event/IoSessionEventQueue.java | 10 +- .../mina/proxy/event/IoSessionEventType.java | 36 +++-- .../apache/mina/proxy/filter/ProxyFilter.java | 2 +- .../proxy/filter/ProxyHandshakeIoBuffer.java | 4 + .../handlers/http/digest/DigestUtilities.java | 15 +- .../http/digest/HttpDigestAuthLogicHandler.java | 20 ++- .../proxy/handlers/http/ntlm/NTLMConstants.java | 151 ++++++++++++------- .../proxy/handlers/http/ntlm/NTLMResponses.java | 23 ++- .../proxy/handlers/http/ntlm/NTLMUtilities.java | 58 ++++--- .../mina/proxy/session/ProxyIoSession.java | 6 +- .../session/ProxyIoSessionInitializer.java | 15 ++ .../apache/mina/proxy/utils/ByteUtilities.java | 24 +-- .../mina/proxy/utils/IoBufferDecoder.java | 37 ++++- .../mina/proxy/utils/StringUtilities.java | 31 ++-- .../apache/mina/util/AvailablePortFinder.java | 14 +- .../org/apache/mina/util/CopyOnWriteMap.java | 38 +++-- .../mina/util/DefaultExceptionMonitor.java | 2 +- .../org/apache/mina/util/ExceptionMonitor.java | 6 +- .../apache/mina/util/ExpirationListener.java | 8 +- .../java/org/apache/mina/util/ExpiringMap.java | 76 ++++++++++ .../org/apache/mina/util/IdentityHashSet.java | 16 +- .../mina/util/LazyInitializedCacheMap.java | 33 +++- .../org/apache/mina/util/LazyInitializer.java | 2 + .../org/apache/mina/util/Log4jXmlFormatter.java | 19 ++- .../java/org/apache/mina/util/MapBackedSet.java | 31 ++++ .../java/org/apache/mina/util/Transform.java | 55 ++++--- 27 files changed, 553 insertions(+), 221 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java index 785e3d7,785e3d7..ad7bb2e --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEvent.java @@@ -32,7 -32,7 +32,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class IoSessionEvent { -- private final static Logger logger = LoggerFactory.getLogger(IoSessionEvent.class); ++ private static final Logger logger = LoggerFactory.getLogger(IoSessionEvent.class); /** * The next filter in the chain. @@@ -63,7 -63,7 +63,7 @@@ * @param session the session * @param type the event type */ -- public IoSessionEvent(final NextFilter nextFilter, final IoSession session, final IoSessionEventType type) { ++ public IoSessionEvent(NextFilter nextFilter, IoSession session, IoSessionEventType type) { this.nextFilter = nextFilter; this.session = session; this.type = type; @@@ -77,7 -77,7 +77,7 @@@ * @param session the session * @param status the idle status */ -- public IoSessionEvent(final NextFilter nextFilter, final IoSession session, final IdleStatus status) { ++ public IoSessionEvent(NextFilter nextFilter, IoSession session, IdleStatus status) { this(nextFilter, session, IoSessionEventType.IDLE); this.status = status; } @@@ -100,21 -100,21 +100,24 @@@ * @param status the idle status should only be non null only if the event type is * {@link IoSessionEventType#IDLE} */ -- private static void deliverEvent(final NextFilter nextFilter, final IoSession session, -- final IoSessionEventType type, final IdleStatus status) { ++ private static void deliverEvent(NextFilter nextFilter, IoSession session, ++ IoSessionEventType type, IdleStatus status) { switch (type) { -- case CREATED: -- nextFilter.sessionCreated(session); -- break; -- case OPENED: -- nextFilter.sessionOpened(session); -- break; -- case IDLE: -- nextFilter.sessionIdle(session, status); -- break; -- case CLOSED: -- nextFilter.sessionClosed(session); -- break; ++ case CREATED: ++ nextFilter.sessionCreated(session); ++ break; ++ ++ case OPENED: ++ nextFilter.sessionOpened(session); ++ break; ++ ++ case IDLE: ++ nextFilter.sessionIdle(session, status); ++ break; ++ ++ case CLOSED: ++ nextFilter.sessionClosed(session); ++ break; } } @@@ -129,6 -129,6 +132,7 @@@ sb.append(" - [ ").append(session); sb.append(", ").append(type); sb.append(']'); ++ return sb.toString(); } @@@ -147,14 -147,14 +151,14 @@@ } /** -- * @return the session on which the event occured. ++ * @return the session on which the event occurred. */ public IoSession getSession() { return session; } /** -- * @return the event type that occured. ++ * @return the event type that occurred. */ public IoSessionEventType getType() { return type; http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java index 0f02918,0f02918..33b09ce --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventQueue.java @@@ -35,7 -35,7 +35,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class IoSessionEventQueue { -- private final static Logger logger = LoggerFactory.getLogger(IoSessionEventQueue.class); ++ private static final Logger logger = LoggerFactory.getLogger(IoSessionEventQueue.class); /** * The proxy session object. @@@ -45,8 -45,8 +45,13 @@@ /** * Queue of session events which occurred before the proxy handshake had completed. */ -- private Queue<IoSessionEvent> sessionEventsQueue = new LinkedList<IoSessionEvent>(); ++ private Queue<IoSessionEvent> sessionEventsQueue = new LinkedList<>(); ++ /** ++ * Creates a new proxyIoSession instance ++ * ++ * @param proxyIoSession The proxy session instance ++ */ public IoSessionEventQueue(ProxyIoSession proxyIoSession) { this.proxyIoSession = proxyIoSession; } @@@ -79,6 -79,6 +84,7 @@@ if (proxyIoSession.getRequest() instanceof SocksProxyRequest) { // No reconnection used evt.deliverEvent(); ++ return; } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java index a499ae7,a499ae7..fe8a047 --- a/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java @@@ -26,7 -26,7 +26,17 @@@ package org.apache.mina.proxy.event * @since MINA 2.0.0-M3 */ public enum IoSessionEventType { -- CREATED(1), OPENED(2), IDLE(3), CLOSED(4); ++ /** Session created */ ++ CREATED(1), ++ ++ /** Session opened */ ++ OPENED(2), ++ ++ /** Session Idling */ ++ IDLE(3), ++ ++ /** Session closed*/ ++ CLOSED(4); /** * The event type id. @@@ -50,16 -50,16 +60,20 @@@ @Override public String toString() { switch (this) { -- case CREATED: -- return "- CREATED event -"; -- case OPENED: -- return "- OPENED event -"; -- case IDLE: -- return "- IDLE event -"; -- case CLOSED: -- return "- CLOSED event -"; -- default: -- return "- Event Id=" + id + " -"; ++ case CREATED: ++ return "- CREATED event -"; ++ ++ case OPENED: ++ return "- OPENED event -"; ++ ++ case IDLE: ++ return "- IDLE event -"; ++ ++ case CLOSED: ++ return "- CLOSED event -"; ++ ++ default: ++ return "- Event Id=" + id + " -"; } } } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java index 8b1880c,8b1880c..d0e9e11 --- a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyFilter.java @@@ -55,7 -55,7 +55,7 @@@ import org.slf4j.LoggerFactory * @since MINA 2.0.0-M3 */ public class ProxyFilter extends IoFilterAdapter { -- private final static Logger LOGGER = LoggerFactory.getLogger(ProxyFilter.class); ++ private static final Logger LOGGER = LoggerFactory.getLogger(ProxyFilter.class); /** * Create a new {@link ProxyFilter}. http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java index 77babbb,77babbb..5bcdaef --- a/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java @@@ -30,6 -30,6 +30,10 @@@ import org.apache.mina.core.buffer.IoBu * @since MINA 2.0.0-M3 */ public class ProxyHandshakeIoBuffer extends IoBufferWrapper { ++ /** ++ * Creates a new ProxyHandshakeIoBuffer instance ++ * @param buf The wrapped buffer ++ */ public ProxyHandshakeIoBuffer(final IoBuffer buf) { super(buf); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/DigestUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/DigestUtilities.java index 206c71d,206c71d..5642cda --- a/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/DigestUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/DigestUtilities.java @@@ -22,7 -22,7 +22,7 @@@ package org.apache.mina.proxy.handlers. import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; --import java.util.HashMap; ++import java.util.Map; import javax.security.sasl.AuthenticationException; @@@ -38,8 -38,8 +38,8 @@@ import org.apache.mina.proxy.utils.Stri * @since MINA 2.0.0-M3 */ public class DigestUtilities { -- -- public final static String SESSION_HA1 = DigestUtilities.class + ".SessionHA1"; ++ /** The Session digest attribute name */ ++ public static final String SESSION_HA1 = DigestUtilities.class + ".SessionHA1"; private static MessageDigest md5; @@@ -51,11 -51,11 +51,14 @@@ throw new RuntimeException(e); } } -- ++ /** * The supported qualities of protections. */ -- public final static String[] SUPPORTED_QOPS = new String[] { "auth", "auth-int" }; ++ public static final String[] SUPPORTED_QOPS = new String[] { "auth", "auth-int" }; ++ ++ private DigestUtilities() { ++ } /** * Computes the response to the DIGEST challenge. @@@ -71,7 -71,7 +74,7 @@@ * @throws UnsupportedEncodingException If we weren't able to encode to ISO 8859_1 the username or realm, * or if we weren't able to encode the charsetName */ -- public static String computeResponseValue(IoSession session, HashMap<String, String> map, String method, ++ public static String computeResponseValue(IoSession session, Map<String, String> map, String method, String pwd, String charsetName, String body) throws AuthenticationException, UnsupportedEncodingException{ byte[] hA1; http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java index 4ddbb38,4ddbb38..478f80c --- a/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java @@@ -53,7 -53,7 +53,7 @@@ public class HttpDigestAuthLogicHandle /** * The challenge directives provided by the server. */ -- private HashMap<String, String> directives = null; ++ private Map<String, String> directives = null; /** * The response received to the last request. @@@ -71,13 -71,13 +71,22 @@@ } } -- public HttpDigestAuthLogicHandler(final ProxyIoSession proxyIoSession) throws ProxyAuthException { ++ /** ++ * Creates a new HttpDigestAuthLogicHandler instance ++ * ++ * @param proxyIoSession The Proxy IoSession ++ * @throws ProxyAuthException The Proxy AuthException ++ */ ++ public HttpDigestAuthLogicHandler(ProxyIoSession proxyIoSession) throws ProxyAuthException { super(proxyIoSession); ((HttpProxyRequest) request).checkRequiredProperties(HttpProxyConstants.USER_PROPERTY, HttpProxyConstants.PWD_PROPERTY); } -- ++ ++ /** ++ * {@inheritDoc} ++ */ @Override public void doHandshake(NextFilter nextFilter) throws ProxyAuthException { logger.debug(" doHandshake()"); @@@ -94,7 -94,7 +103,7 @@@ logger.debug(" sending DIGEST challenge response"); // Build a challenge response -- HashMap<String, String> map = new HashMap<String, String>(); ++ HashMap<String, String> map = new HashMap<>(); map.put("username", req.getProperties().get(HttpProxyConstants.USER_PROPERTY)); StringUtilities.copyDirective(directives, map, "realm"); StringUtilities.copyDirective(directives, map, "uri"); @@@ -109,17 -109,17 +118,20 @@@ // Check for a supported qop String qop = directives.get("qop"); ++ if (qop != null) { StringTokenizer st = new StringTokenizer(qop, ","); String token = null; while (st.hasMoreTokens()) { String tk = st.nextToken(); ++ if ("auth".equalsIgnoreCase(token)) { break; } int pos = Arrays.binarySearch(DigestUtilities.SUPPORTED_QOPS, tk); ++ if (pos > -1) { token = tk; } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMConstants.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMConstants.java index e067a3b,e067a3b..dbe996e --- a/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMConstants.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMConstants.java @@@ -26,132 -26,132 +26,173 @@@ package org.apache.mina.proxy.handlers. * @since MINA 2.0.0-M3 */ public interface NTLMConstants { -- // Signature "NTLMSSP"+{0} ++ /** Signature "NTLMSSP"+{0} */ byte[] NTLM_SIGNATURE = new byte[] { 0x4E, 0x54, 0x4C, 0x4D, 0x53, 0x53, 0x50, 0 }; -- // Version 5.1.2600 a Windows XP version (ex: Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) ++ /** Version 5.1.2600 a Windows XP version (ex: Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) */ byte[] DEFAULT_OS_VERSION = new byte[] { 0x05, 0x01, 0x28, 0x0A, 0, 0, 0, 0x0F }; /** * Message types */ ++ /** Type 1 */ int MESSAGE_TYPE_1 = 1; ++ /** Type 2 */ int MESSAGE_TYPE_2 = 2; ++ /** Type 3 */ int MESSAGE_TYPE_3 = 3; /** * Message flags */ -- // Indicates that Unicode strings are supported for use in security buffer data ++ /** Indicates that Unicode strings are supported for use in security buffer data */ int FLAG_NEGOTIATE_UNICODE = 0x00000001; -- // Indicates that OEM strings are supported for use in security buffer data ++ /** Indicates that OEM strings are supported for use in security buffer data */ int FLAG_NEGOTIATE_OEM = 0x00000002; -- // Requests that the server's authentication realm be included in the Type 2 message ++ /** Requests that the server's authentication realm be included in the Type 2 message */ int FLAG_REQUEST_SERVER_AUTH_REALM = 0x00000004; -- // Specifies that authenticated communication between the client -- // and server should carry a digital signature (message integrity) ++ /** ++ * Specifies that authenticated communication between the client ++ * and server should carry a digital signature (message integrity) ++ */ int FLAG_NEGOTIATE_SIGN = 0x00000010; -- // Specifies that authenticated communication between the client -- // and server should be encrypted (message confidentiality) ++ /** ++ * Specifies that authenticated communication between the client ++ * and server should be encrypted (message confidentiality) ++ */ int FLAG_NEGOTIATE_SEAL = 0x00000020; -- // Indicates that datagram authentication is being used ++ /** Indicates that datagram authentication is being used */ int FLAG_NEGOTIATE_DATAGRAM_STYLE = 0x00000040; -- // Indicates that the Lan Manager Session Key should be used for signing and -- // sealing authenticated communications ++ /** ++ * Indicates that the Lan Manager Session Key should be used for signing and ++ * sealing authenticated communications ++ */ int FLAG_NEGOTIATE_LAN_MANAGER_KEY = 0x00000080; -- // Indicates that NTLM authentication is being used ++ /** Indicates that NTLM authentication is being used */ int FLAG_NEGOTIATE_NTLM = 0x00000200; -- // Sent by the client in the Type 3 message to indicate that an anonymous context -- // has been established. This also affects the response fields ++ /** ++ * Sent by the client in the Type 3 message to indicate that an anonymous context ++ * has been established. This also affects the response fields ++ **/ int FLAG_NEGOTIATE_ANONYMOUS = 0x00000800; -- // Sent by the client in the Type 1 message to indicate that the name of the domain in which -- // the client workstation has membership is included in the message. This is used by the -- // server to determine whether the client is eligible for local authentication ++ /** ++ * Sent by the client in the Type 1 message to indicate that the name of the domain in which ++ * the client workstation has membership is included in the message. This is used by the ++ * server to determine whether the client is eligible for local authentication ++ */ int FLAG_NEGOTIATE_DOMAIN_SUPPLIED = 0x00001000; -- // Sent by the client in the Type 1 message to indicate that the client workstation's name -- // is included in the message. This is used by the server to determine whether the client -- // is eligible for local authentication ++ /** ++ * Sent by the client in the Type 1 message to indicate that the client workstation's name ++ * is included in the message. This is used by the server to determine whether the client ++ * is eligible for local authentication ++ */ int FLAG_NEGOTIATE_WORKSTATION_SUPPLIED = 0x00002000; -- // Sent by the server to indicate that the server and client are on the same machine. -- // Implies that the client may use the established local credentials for authentication -- // instead of calculating a response to the challenge ++ /** ++ * Sent by the server to indicate that the server and client are on the same machine. ++ * Implies that the client may use the established local credentials for authentication ++ * instead of calculating a response to the challenge ++ */ int FLAG_NEGOTIATE_LOCAL_CALL = 0x00004000; -- // Indicates that authenticated communication between the client and server should -- // be signed with a "dummy" signature ++ /** ++ * Indicates that authenticated communication between the client and server should ++ * be signed with a "dummy" signature ++ **/ int FLAG_NEGOTIATE_ALWAYS_SIGN = 0x00008000; -- // Sent by the server in the Type 2 message to indicate that the target authentication -- // realm is a domain ++ /** ++ * Sent by the server in the Type 2 message to indicate that the target authentication ++ * realm is a domain ++ **/ int FLAG_TARGET_TYPE_DOMAIN = 0x00010000; -- // Sent by the server in the Type 2 message to indicate that the target authentication -- // realm is a server ++ /** ++ * Sent by the server in the Type 2 message to indicate that the target authentication ++ * realm is a server ++ */ int FLAG_TARGET_TYPE_SERVER = 0x00020000; -- // Sent by the server in the Type 2 message to indicate that the target authentication -- // realm is a share. Presumably, this is for share-level authentication. Usage is unclear ++ /** ++ * Sent by the server in the Type 2 message to indicate that the target authentication ++ * realm is a share. Presumably, this is for share-level authentication. Usage is unclear ++ **/ int FLAG_TARGET_TYPE_SHARE = 0x00040000; -- // Indicates that the NTLM2 signing and sealing scheme should be used for protecting -- // authenticated communications. Note that this refers to a particular session security -- // scheme, and is not related to the use of NTLMv2 authentication. This flag can, however, -- // have an effect on the response calculations ++ /** ++ * Indicates that the NTLM2 signing and sealing scheme should be used for protecting ++ * authenticated communications. Note that this refers to a particular session security ++ * scheme, and is not related to the use of NTLMv2 authentication. This flag can, however, ++ * have an effect on the response calculations ++ **/ int FLAG_NEGOTIATE_NTLM2 = 0x00080000; -- // Sent by the server in the Type 2 message to indicate that it is including a Target -- // Information block in the message. The Target Information block is used in the -- // calculation of the NTLMv2 response ++ /** ++ * Sent by the server in the Type 2 message to indicate that it is including a Target ++ * Information block in the message. The Target Information block is used in the ++ * calculation of the NTLMv2 response ++ */ int FLAG_NEGOTIATE_TARGET_INFO = 0x00800000; -- // Indicates that 128-bit encryption is supported ++ /** Indicates that 128-bit encryption is supported */ int FLAG_NEGOTIATE_128_BIT_ENCRYPTION = 0x20000000; -- // Indicates that the client will provide an encrypted master key in the "Session Key" -- // field of the Type 3 message ++ /** ++ * Indicates that the client will provide an encrypted master key in the "Session Key" ++ * field of the Type 3 message ++ **/ int FLAG_NEGOTIATE_KEY_EXCHANGE = 0x40000000; -- // Indicates that 56-bit encryption is supported ++ /** Indicates that 56-bit encryption is supported */ int FLAG_NEGOTIATE_56_BIT_ENCRYPTION = 0x80000000; -- // WARN : These flags usage has not been identified ++ /** WARN : These flags usage has not been identified */ int FLAG_UNIDENTIFIED_1 = 0x00000008; -- int FLAG_UNIDENTIFIED_2 = 0x00000100; // Negotiate Netware ??! ++ /** Negotiate Netware ??! */ ++ int FLAG_UNIDENTIFIED_2 = 0x00000100; ++ /** Undefined */ int FLAG_UNIDENTIFIED_3 = 0x00000400; -- int FLAG_UNIDENTIFIED_4 = 0x00100000; // Request Init Response ??! ++ /** Request Init Response ??! */ ++ int FLAG_UNIDENTIFIED_4 = 0x00100000; -- int FLAG_UNIDENTIFIED_5 = 0x00200000; // Request Accept Response ??! ++ /** Request Accept Response ??! */ ++ int FLAG_UNIDENTIFIED_5 = 0x00200000; -- int FLAG_UNIDENTIFIED_6 = 0x00400000; // Request Non-NT Session Key ??! ++ /** Request Non-NT Session Key ??! */ ++ int FLAG_UNIDENTIFIED_6 = 0x00400000; ++ /** Undefined */ int FLAG_UNIDENTIFIED_7 = 0x01000000; ++ /** Undefined */ int FLAG_UNIDENTIFIED_8 = 0x02000000; ++ /** Undefined */ int FLAG_UNIDENTIFIED_9 = 0x04000000; ++ /** Undefined */ int FLAG_UNIDENTIFIED_10 = 0x08000000; ++ /** Undefined */ int FLAG_UNIDENTIFIED_11 = 0x10000000; -- // Default minimal flag set ++ /** Default minimal flag set */ int DEFAULT_FLAGS = FLAG_NEGOTIATE_OEM | FLAG_NEGOTIATE_UNICODE | FLAG_NEGOTIATE_WORKSTATION_SUPPLIED | FLAG_NEGOTIATE_DOMAIN_SUPPLIED; @@@ -160,21 -160,21 +201,21 @@@ * as-yet-unidentified sub block types as well. */ -- // Sub block terminator ++ /** Sub block terminator */ short TARGET_INFORMATION_SUBBLOCK_TERMINATOR_TYPE = 0x0000; -- // Server name ++ /** Server name */ short TARGET_INFORMATION_SUBBLOCK_SERVER_TYPE = 0x0100; -- // Domain name ++ /** Domain name */ short TARGET_INFORMATION_SUBBLOCK_DOMAIN_TYPE = 0x0200; -- // Fully-qualified DNS host name (i.e., server.domain.com) ++ /** Fully-qualified DNS host name (i.e., server.domain.com) */ short TARGET_INFORMATION_SUBBLOCK_FQDNS_HOSTNAME_TYPE = 0x0300; -- // DNS domain name (i.e., domain.com) ++ /** DNS domain name (i.e., domain.com) */ short TARGET_INFORMATION_SUBBLOCK_DNS_DOMAIN_NAME_TYPE = 0x0400; -- // Apparently the "parent" DNS domain for servers in sub domains ++ /** Apparently the "parent" DNS domain for servers in sub domains */ short TARGET_INFORMATION_SUBBLOCK_PARENT_DNS_DOMAIN_NAME_TYPE = 0x0500; } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMResponses.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMResponses.java index 6a3df95,6a3df95..b003998 --- a/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMResponses.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMResponses.java @@@ -41,8 -41,8 +41,7 @@@ import javax.crypto.spec.SecretKeySpec * @since MINA 2.0.0-M3 */ public class NTLMResponses { -- -- // LAN Manager magic constant used in LM Response calculation ++ /** LAN Manager magic constant used in LM Response calculation */ public static final byte[] LM_HASH_MAGIC_CONSTANT = new byte[]{ 'K', 'G', 'S', '!', '@', '#', '$', '%' }; @@@ -58,6 -58,6 +57,7 @@@ */ public static byte[] getLMResponse(String password, byte[] challenge) throws Exception { byte[] lmHash = lmHash(password); ++ return lmResponse(lmHash, challenge); } @@@ -73,6 -73,6 +73,7 @@@ */ public static byte[] getNTLMResponse(String password, byte[] challenge) throws Exception { byte[] ntlmHash = ntlmHash(password); ++ return lmResponse(ntlmHash, challenge); } @@@ -120,6 -120,6 +121,7 @@@ byte[] challenge, byte[] clientNonce, long time) throws Exception { byte[] ntlmv2Hash = ntlmv2Hash(target, user, password); byte[] blob = createBlob(targetInformation, clientNonce, time); ++ return lmv2Response(ntlmv2Hash, blob, challenge); } @@@ -190,6 -190,6 +192,7 @@@ byte[] lmHash = new byte[16]; System.arraycopy(lowHash, 0, lmHash, 0, 8); System.arraycopy(highHash, 0, lmHash, 8, 8); ++ return lmHash; } @@@ -204,6 -204,6 +207,7 @@@ private static byte[] ntlmHash(String password) throws Exception { byte[] unicodePassword = password.getBytes("UnicodeLittleUnmarked"); MessageDigest md4 = MessageDigest.getInstance("MD4"); ++ return md4.digest(unicodePassword); } @@@ -220,6 -220,6 +224,7 @@@ private static byte[] ntlmv2Hash(String target, String user, String password) throws Exception { byte[] ntlmHash = ntlmHash(password); String identity = user.toUpperCase() + target; ++ return hmacMD5(identity.getBytes("UnicodeLittleUnmarked"), ntlmHash); } @@@ -249,6 -249,6 +254,7 @@@ System.arraycopy(lowResponse, 0, lmResponse, 0, 8); System.arraycopy(middleResponse, 0, lmResponse, 8, 8); System.arraycopy(highResponse, 0, lmResponse, 16, 8); ++ return lmResponse; } @@@ -271,6 -271,6 +277,7 @@@ byte[] lmv2Response = new byte[mac.length + clientData.length]; System.arraycopy(mac, 0, lmv2Response, 0, mac.length); System.arraycopy(clientData, 0, lmv2Response, mac.length, clientData.length); ++ return lmv2Response; } @@@ -294,10 -294,10 +301,12 @@@ time *= 10000; // tenths of a microsecond. // convert to little-endian byte array. byte[] timestamp = new byte[8]; ++ for (int i = 0; i < 8; i++) { timestamp[i] = (byte) time; time >>>= 8; } ++ byte[] blob = new byte[blobSignature.length + reserved.length + timestamp.length + clientNonce.length + unknown1.length + targetInformation.length + unknown2.length]; int offset = 0; @@@ -314,6 -314,6 +323,7 @@@ System.arraycopy(targetInformation, 0, blob, offset, targetInformation.length); offset += targetInformation.length; System.arraycopy(unknown2, 0, blob, offset, unknown2.length); ++ return blob; } @@@ -346,10 -346,10 +356,11 @@@ System.arraycopy(ipad, 0, content, 0, 64); System.arraycopy(data, 0, content, 64, data.length); MessageDigest md5 = MessageDigest.getInstance("MD5"); -- data = md5.digest(content); -- content = new byte[data.length + 64]; ++ byte[] digestedData = md5.digest(content); ++ content = new byte[digestedData.length + 64]; System.arraycopy(opad, 0, content, 0, 64); -- System.arraycopy(data, 0, content, 64, data.length); ++ System.arraycopy(digestedData, 0, content, 64, digestedData.length); ++ return md5.digest(content); } @@@ -376,6 -376,6 +387,7 @@@ material[6] = (byte) (keyBytes[5] << 2 | (keyBytes[6] & 0xff) >>> 6); material[7] = (byte) (keyBytes[6] << 1); oddParity(material); ++ return new SecretKeySpec(material, "DES"); } @@@ -389,6 -389,6 +401,7 @@@ for (int i = 0; i < bytes.length; i++) { byte b = bytes[i]; boolean needsParity = (((b >>> 7) ^ (b >>> 6) ^ (b >>> 5) ^ (b >>> 4) ^ (b >>> 3) ^ (b >>> 2) ^ (b >>> 1)) & 0x01) == 0; ++ if (needsParity) { bytes[i] |= (byte) 0x01; } else { http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMUtilities.java index 50c841f,50c841f..627afb3 --- a/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/NTLMUtilities.java @@@ -36,6 -36,6 +36,9 @@@ import org.apache.mina.proxy.utils.Byte * @since MINA 2.0.0-M3 */ public class NTLMUtilities implements NTLMConstants { ++ private NTLMUtilities() { ++ } ++ /** * @see #writeSecurityBuffer(short, short, int, byte[], int) * @@@ -43,7 -43,7 +46,7 @@@ * @param bufferOffset The offset in the security buffer * @return Th created buffer */ -- public final static byte[] writeSecurityBuffer(short length, int bufferOffset) { ++ public static final byte[] writeSecurityBuffer(short length, int bufferOffset) { byte[] b = new byte[8]; writeSecurityBuffer(length, length, bufferOffset, b, 0); @@@ -65,7 -65,7 +68,7 @@@ * @param b the buffer in which we write the security buffer * @param offset the offset at which to write to the b buffer */ -- public final static void writeSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset) { ++ public static final void writeSecurityBuffer(short length, short allocated, int bufferOffset, byte[] b, int offset) { ByteUtilities.writeShort(length, b, offset); ByteUtilities.writeShort(allocated, b, offset + 2); ByteUtilities.writeInt(bufferOffset, b, offset + 4); @@@ -82,7 -82,7 +85,7 @@@ * @param b the target byte array * @param offset the offset at which to write in the array */ -- public final static void writeOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, ++ public static final void writeOSVersion(byte majorVersion, byte minorVersion, short buildNumber, byte[] b, int offset) { b[offset] = majorVersion; b[offset + 1] = minorVersion; @@@ -101,7 -101,7 +104,7 @@@ * * @return a NTLM OS version byte buffer */ -- public final static byte[] getOsVersion() { ++ public static final byte[] getOsVersion() { String os = System.getProperty("os.name"); if ((os == null) || !os.toUpperCase().contains("WINDOWS")) { @@@ -177,9 -177,9 +180,9 @@@ * <code>NTLMConstants.DEFAULT_OS_VERSION</code> is used * @return the type 1 message */ -- public final static byte[] createType1Message(String workStation, String domain, Integer customFlags, ++ public static final byte[] createType1Message(String workStation, String domain, Integer customFlags, byte[] osVersion) { -- byte[] msg = null; ++ byte[] msg; if (osVersion != null && osVersion.length != 8) { throw new IllegalArgumentException("osVersion parameter should be a 8 byte wide array"); @@@ -233,7 -233,7 +236,7 @@@ * @return the position where the next security buffer will be written * @throws IOException if writing to the ByteArrayOutputStream fails */ -- public final static int writeSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos, short len, int pointer) ++ public static final int writeSecurityBufferAndUpdatePointer(ByteArrayOutputStream baos, short len, int pointer) throws IOException { baos.write(writeSecurityBuffer(len, pointer)); @@@ -246,7 -246,7 +249,7 @@@ * @param msg the type 2 message byte array * @return the challenge */ -- public final static byte[] extractChallengeFromType2Message(byte[] msg) { ++ public static final byte[] extractChallengeFromType2Message(byte[] msg) { byte[] challenge = new byte[8]; System.arraycopy(msg, 24, challenge, 0, 8); @@@ -259,7 -259,7 +262,7 @@@ * @param msg the type 2 message byte array * @return the proxy flags as an int */ -- public final static int extractFlagsFromType2Message(byte[] msg) { ++ public static final int extractFlagsFromType2Message(byte[] msg) { byte[] flagsBytes = new byte[4]; System.arraycopy(msg, 20, flagsBytes, 0, 4); @@@ -276,7 -276,7 +279,7 @@@ * @param securityBufferOffset the offset at which to read the security buffer * @return a new byte array holding the data pointed by the security buffer */ -- public final static byte[] readSecurityBufferTarget(byte[] msg, int securityBufferOffset) { ++ public static final byte[] readSecurityBufferTarget(byte[] msg, int securityBufferOffset) { byte[] securityBuffer = new byte[8]; System.arraycopy(msg, securityBufferOffset, securityBuffer, 0, 8); @@@ -300,7 -300,7 +303,7 @@@ * @throws UnsupportedEncodingException if unable to use the * needed UTF-16LE or ASCII charsets */ -- public final static String extractTargetNameFromType2Message(byte[] msg, Integer msgFlags) ++ public static final String extractTargetNameFromType2Message(byte[] msg, Integer msgFlags) throws UnsupportedEncodingException { // Read the security buffer to determine where the target name // is stored and what it's length is @@@ -324,7 -324,7 +327,7 @@@ * type 2 message * @return the target info */ -- public final static byte[] extractTargetInfoFromType2Message(byte[] msg, Integer msgFlags) { ++ public static final byte[] extractTargetInfoFromType2Message(byte[] msg, Integer msgFlags) { int flags = msgFlags == null ? extractFlagsFromType2Message(msg) : msgFlags; if (!ByteUtilities.isFlagSet(flags, FLAG_NEGOTIATE_TARGET_INFO)) { @@@ -347,7 -347,7 +350,7 @@@ * @throws UnsupportedEncodingException if unable to use the * needed UTF-16LE or ASCII charsets */ -- public final static void printTargetInformationBlockFromType2Message(byte[] msg, Integer msgFlags, PrintWriter out) ++ public static final void printTargetInformationBlockFromType2Message(byte[] msg, Integer msgFlags, PrintWriter out) throws UnsupportedEncodingException { int flags = msgFlags == null ? extractFlagsFromType2Message(msg) : msgFlags; @@@ -400,29 -400,29 +403,20 @@@ } /** -- * @see <a -- * href="http://davenport.sourceforge.net/ntlm.html#theType3Message">NTLM -- * message type</a> ++ * @see <a href="http://davenport.sourceforge.net/ntlm.html#theType3Message">NTLM message type</a> * -- * @param user -- * the user name -- * @param password -- * the user password -- * @param challenge -- * the challenge response -- * @param target -- * the target name -- * @param workstation -- * the client workstation's name -- * @param serverFlags -- * the flags set by the client -- * @param osVersion -- * the os version of the client ++ * @param user the user name ++ * @param password the user password ++ * @param challenge the challenge response ++ * @param target the target name ++ * @param workstation the client workstation's name ++ * @param serverFlags the flags set by the client ++ * @param osVersion the os version of the client * @return the type 3 message */ -- public final static byte[] createType3Message(String user, String password, byte[] challenge, String target, ++ public static final byte[] createType3Message(String user, String password, byte[] challenge, String target, String workstation, Integer serverFlags, byte[] osVersion) { -- byte[] msg = null; ++ byte[] msg; if (challenge == null || challenge.length != 8) { throw new IllegalArgumentException("challenge[] should be a 8 byte wide array"); http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java index c589a86,c589a86..1eecb3c --- a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSession.java @@@ -40,10 -40,10 +40,10 @@@ import org.apache.mina.proxy.handlers.h * @since MINA 2.0.0-M3 */ public class ProxyIoSession { ++ /** The proxy session name */ ++ public static final String PROXY_SESSION = ProxyConnector.class.getName() + ".ProxySession"; -- public final static String PROXY_SESSION = ProxyConnector.class.getName() + ".ProxySession"; -- -- private final static String DEFAULT_ENCODING = "ISO-8859-1"; ++ private static final String DEFAULT_ENCODING = "ISO-8859-1"; /** * The list contains the authentication methods to use. http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java index 1c8e357,1c8e357..78116a3 --- a/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/session/ProxyIoSessionInitializer.java @@@ -27,6 -27,6 +27,8 @@@ import org.apache.mina.core.session.IoS * ProxyIoSessionInitializer.java - {@link IoSessionInitializer} wrapper class to inject the * {@link ProxyIoSession} object that contains all the attributes of the target connection * into the {@link IoSession}. ++ * ++ * @param <T> The Connection Future type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M3 @@@ -36,16 -36,16 +38,29 @@@ public class ProxyIoSessionInitializer< private final ProxyIoSession proxyIoSession; ++ /** ++ * Creates a new ProxyIoSessionInitializer instance ++ * ++ * @param wrappedSessionInitializer The wrapped session initializer ++ * @param proxyIoSession The ProxyIoSession instance ++ */ public ProxyIoSessionInitializer(final IoSessionInitializer<T> wrappedSessionInitializer, final ProxyIoSession proxyIoSession) { this.wrappedSessionInitializer = wrappedSessionInitializer; this.proxyIoSession = proxyIoSession; } ++ /** ++ * @return The ProxyIoSession instance ++ */ public ProxyIoSession getProxySession() { return proxyIoSession; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void initializeSession(final IoSession session, T future) { if (wrappedSessionInitializer != null) { wrappedSessionInitializer.initializeSession(session, future); http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java index c03d642,c03d642..b663ee8 --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/ByteUtilities.java @@@ -28,7 -28,7 +28,9 @@@ import java.io.UnsupportedEncodingExcep * @since MINA 2.0.0-M3 */ public class ByteUtilities { -- ++ private ByteUtilities(){ ++ } ++ /** * Returns the integer represented by up to 4 bytes in network byte order. * @@@ -93,7 -93,7 +95,7 @@@ * @param v the short to write * @return the Short in a byte[] */ -- public final static byte[] writeShort(short v) { ++ public static final byte[] writeShort(short v) { return writeShort(v, new byte[2], 0); } @@@ -106,7 -106,7 +108,7 @@@ * @param offset the offset at which to start writing in the array * @return the Short in a byte[] */ -- public final static byte[] writeShort(short v, byte[] b, int offset) { ++ public static final byte[] writeShort(short v, byte[] b, int offset) { b[offset] = (byte) v; b[offset + 1] = (byte) (v >> 8); @@@ -119,7 -119,7 +121,7 @@@ * @param v the int to write * @return the Int in a byte[] */ -- public final static byte[] writeInt(int v) { ++ public static final byte[] writeInt(int v) { return writeInt(v, new byte[4], 0); } @@@ -132,7 -132,7 +134,7 @@@ * @param offset the offset at which to start writing in the array * @return the Int in a byte[] */ -- public final static byte[] writeInt(int v, byte[] b, int offset) { ++ public static final byte[] writeInt(int v, byte[] b, int offset) { b[offset] = (byte) v; b[offset + 1] = (byte) (v >> 8); b[offset + 2] = (byte) (v >> 16); @@@ -151,7 -151,7 +153,7 @@@ * @param length the number of bytes on which to operate * (should be a multiple of 4) */ -- public final static void changeWordEndianess(byte[] b, int offset, int length) { ++ public static final void changeWordEndianess(byte[] b, int offset, int length) { byte tmp; for (int i = offset; i < offset + length; i += 4) { @@@ -174,7 -174,7 +176,7 @@@ * @param length the number of bytes on which to operate * (should be a multiple of 2) */ -- public final static void changeByteEndianess(byte[] b, int offset, int length) { ++ public static final void changeByteEndianess(byte[] b, int offset, int length) { byte tmp; for (int i = offset; i < offset + length; i += 2) { @@@ -192,7 -192,7 +194,7 @@@ * @return the result byte array * @throws UnsupportedEncodingException if the string is not an OEM string */ -- public final static byte[] getOEMStringAsByteArray(String s) throws UnsupportedEncodingException { ++ public static final byte[] getOEMStringAsByteArray(String s) throws UnsupportedEncodingException { return s.getBytes("ASCII"); } @@@ -203,7 -203,7 +205,7 @@@ * @return the result byte array * @throws UnsupportedEncodingException if the string is not an UTF-16LE string */ -- public final static byte[] getUTFStringAsByteArray(String s) throws UnsupportedEncodingException { ++ public static final byte[] getUTFStringAsByteArray(String s) throws UnsupportedEncodingException { return s.getBytes("UTF-16LE"); } @@@ -217,7 -217,7 +219,7 @@@ * @return the encoded string as a byte array * @throws UnsupportedEncodingException if encoding fails */ -- public final static byte[] encodeString(String s, boolean useUnicode) throws UnsupportedEncodingException { ++ public static final byte[] encodeString(String s, boolean useUnicode) throws UnsupportedEncodingException { if (useUnicode) { return getUTFStringAsByteArray(s); } @@@ -326,7 -326,7 +328,7 @@@ * @param testFlag the flag we search the presence of * @return true if testFlag is present in the flagset, false otherwise. */ -- public final static boolean isFlagSet(int flagSet, int testFlag) { ++ public static final boolean isFlagSet(int flagSet, int testFlag) { return (flagSet & testFlag) > 0; } } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java index 148a98a,148a98a..e7a8da4 --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/IoBufferDecoder.java @@@ -49,7 -49,7 +49,7 @@@ public class IoBufferDecoder private IoBuffer delimiter; /** -- * The currently matched bytes of the delimiter. ++ * The number of matched delimiters. */ private int matchCount = 0; @@@ -68,34 -68,34 +68,67 @@@ decodedBuffer = null; } ++ /** ++ * @return The current content length of decoded data if in ++ * content-length mode. ++ */ public int getContentLength() { return contentLength; } ++ /** ++ * Sets the content-length ++ * ++ * @param contentLength current content length of decoded data ++ */ public void setContentLength(int contentLength) { this.contentLength = contentLength; } ++ /** ++ * @return The number of matched delimiters. ++ */ public int getMatchCount() { return matchCount; } ++ /** ++ * Sets the match count ++ * ++ * @param matchCount The number of matched delimiters. ++ */ public void setMatchCount(int matchCount) { this.matchCount = matchCount; } ++ /** ++ * @return The decoded data ++ */ public IoBuffer getDecodedBuffer() { return decodedBuffer; } ++ /** ++ * Sets the decoded data buffer ++ * ++ * @param decodedBuffer The decoded data ++ */ public void setDecodedBuffer(IoBuffer decodedBuffer) { this.decodedBuffer = decodedBuffer; } ++ /** ++ * @return The delimiter ++ */ public IoBuffer getDelimiter() { return delimiter; } ++ /** ++ * Sets the delimiter ++ * ++ * @param delimiter The delimiter ++ */ public void setDelimiter(IoBuffer delimiter) { this.delimiter = delimiter; } @@@ -221,8 -221,8 +254,10 @@@ while (in.hasRemaining()) { byte b = in.get(); ++ if (delimiter.get(matchCount) == b) { matchCount++; ++ if (matchCount == delimiter.limit()) { // Found a match. int pos = in.position(); http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java index 48b2dc1,48b2dc1..efd0b4d --- a/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java +++ b/mina-core/src/main/java/org/apache/mina/proxy/utils/StringUtilities.java @@@ -36,7 -36,7 +36,9 @@@ import javax.security.sasl.SaslExceptio * @since MINA 2.0.0-M3 */ public class StringUtilities { -- ++ private StringUtilities(){ ++ } ++ /** * A directive is a parameter of the digest authentication process. * Returns the value of a directive from the map. If mandatory is true and the @@@ -49,9 -49,9 +51,10 @@@ * @throws AuthenticationException if mandatory is true and if * directivesMap.get(directive) == null */ -- public static String getDirectiveValue(HashMap<String, String> directivesMap, String directive, boolean mandatory) ++ public static String getDirectiveValue(Map<String, String> directivesMap, String directive, boolean mandatory) throws AuthenticationException { String value = directivesMap.get(directive); ++ if (value == null) { if (mandatory) { throw new AuthenticationException("\"" + directive + "\" mandatory directive is missing"); @@@ -71,8 -71,8 +74,9 @@@ * @param sb the output buffer * @param directive the directive name to look for */ -- public static void copyDirective(HashMap<String, String> directives, StringBuilder sb, String directive) { ++ public static void copyDirective(Map<String, String> directives, StringBuilder sb, String directive) { String directiveValue = directives.get(directive); ++ if (directiveValue != null) { sb.append(directive).append(" = \"").append(directiveValue).append("\", "); } @@@ -88,8 -88,8 +92,9 @@@ * @param directive the directive name * @return the value of the copied directive */ -- public static String copyDirective(HashMap<String, String> src, HashMap<String, String> dst, String directive) { ++ public static String copyDirective(Map<String, String> src, Map<String, String> dst, String directive) { String directiveValue = src.get(directive); ++ if (directiveValue != null) { dst.put(directive, directiveValue); } @@@ -105,8 -105,8 +110,8 @@@ * @return A Map containing the aprsed directives * @throws SaslException if the String cannot be parsed according to RFC 2831 */ -- public static HashMap<String, String> parseDirectives(byte[] buf) throws SaslException { -- HashMap<String, String> map = new HashMap<String, String>(); ++ public static Map<String, String> parseDirectives(byte[] buf) throws SaslException { ++ Map<String, String> map = new HashMap<>(); boolean gettingKey = true; boolean gettingQuotedValue = false; boolean expectSeparator = false; @@@ -116,6 -116,6 +121,7 @@@ ByteArrayOutputStream value = new ByteArrayOutputStream(10); int i = skipLws(buf, 0); ++ while (i < buf.length) { bch = buf[i]; @@@ -165,6 -165,6 +171,7 @@@ if (bch == '\\') { // quoted-pair = "\" CHAR ==> CHAR ++i; // Skip escape ++ if (i < buf.length) { value.write(buf[i]); ++i; // Advance @@@ -221,7 -221,7 +228,7 @@@ * @throws SaslException if either the key or the value is null or * if the key already has a value. */ -- private static void extractDirective(HashMap<String, String> map, String key, String value) throws SaslException { ++ private static void extractDirective(Map<String, String> map, String key, String value) throws SaslException { if (map.get(key) != null) { throw new SaslException("Peer sent more than one " + key + " directive"); } @@@ -239,10 -239,10 +246,10 @@@ */ public static boolean isLws(byte b) { switch (b) { -- case 13: // US-ASCII CR, carriage return -- case 10: // US-ASCII LF, line feed -- case 32: // US-ASCII SP, space -- case 9: // US-ASCII HT, horizontal-tab ++ case 13: // US-ASCII CR, carriage return ++ case 10: // US-ASCII LF, line feed ++ case 32: // US-ASCII SP, space ++ case 9: // US-ASCII HT, horizontal-tab return true; } @@@ -321,7 -321,7 +328,7 @@@ List<String> values = headers.get(key); if (values == null) { -- values = new ArrayList<String>(1); ++ values = new ArrayList<>(1); headers.put(key, values); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java index e0564b9,e0564b9..4147066 --- a/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java +++ b/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java @@@ -67,17 -67,17 +67,9 @@@ public class AvailablePortFinder * @throws NoSuchElementException if there are no ports available */ public static int getNextAvailable() { -- ServerSocket serverSocket = null; -- -- try { ++ try (ServerSocket serverSocket = new ServerSocket(0)){ // Here, we simply return an available port found by the system -- serverSocket = new ServerSocket(0); -- int port = serverSocket.getLocalPort(); -- -- // Don't forget to close the socket... -- serverSocket.close(); -- -- return port; ++ return serverSocket.getLocalPort(); } catch (IOException ioe) { throw new NoSuchElementException(ioe.getMessage()); } @@@ -157,7 -157,7 +149,7 @@@ throw new IllegalArgumentException("Invalid port range: " + fromPort + " ~ " + toPort); } -- Set<Integer> result = new TreeSet<Integer>(); ++ Set<Integer> result = new TreeSet<>(); for (int i = fromPort; i <= toPort; i++) { ServerSocket s = null; http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java index 75bddd6,75bddd6..bc86e98 --- a/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/CopyOnWriteMap.java @@@ -32,6 -32,6 +32,9 @@@ import java.util.Set * cases in which the primary function is to read data from the Map, not to * modify the Map. Therefore the operations that do not cause a change to this * class happen quickly and concurrently. ++ * ++ * @param <K> The key type ++ * @param <V> The value type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -40,20 -40,20 +43,18 @@@ public class CopyOnWriteMap<K, V> imple /** * Creates a new instance of CopyOnWriteMap. -- * */ public CopyOnWriteMap() { -- internalMap = new HashMap<K, V>(); ++ internalMap = new HashMap<>(); } /** * Creates a new instance of CopyOnWriteMap with the specified initial size * -- * @param initialCapacity -- * The initial size of the Map. ++ * @param initialCapacity The initial size of the Map. */ public CopyOnWriteMap(int initialCapacity) { -- internalMap = new HashMap<K, V>(initialCapacity); ++ internalMap = new HashMap<>(initialCapacity); } /** @@@ -61,12 -61,12 +62,11 @@@ * initial data being held by this map is contained in * the supplied map. * -- * @param data -- * A Map containing the initial contents to be placed into ++ * @param data A Map containing the initial contents to be placed into * this class. */ public CopyOnWriteMap(Map<K, V> data) { -- internalMap = new HashMap<K, V>(data); ++ internalMap = new HashMap<>(data); } /** @@@ -74,11 -74,11 +74,13 @@@ * * @see java.util.Map#put(java.lang.Object, java.lang.Object) */ ++ @Override public V put(K key, V value) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); V val = newMap.put(key, value); internalMap = newMap; ++ return val; } } @@@ -89,11 -89,11 +91,13 @@@ * * @see java.util.Map#remove(java.lang.Object) */ ++ @Override public V remove(Object key) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); V val = newMap.remove(key); internalMap = newMap; ++ return val; } } @@@ -104,9 -104,9 +108,10 @@@ * * @see java.util.Map#putAll(java.util.Map) */ ++ @Override public void putAll(Map<? extends K, ? extends V> newData) { synchronized (this) { -- Map<K, V> newMap = new HashMap<K, V>(internalMap); ++ Map<K, V> newMap = new HashMap<>(internalMap); newMap.putAll(newData); internalMap = newMap; } @@@ -117,9 -117,9 +122,10 @@@ * * @see java.util.Map#clear() */ ++ @Override public void clear() { synchronized (this) { -- internalMap = new HashMap<K, V>(); ++ internalMap = new HashMap<>(); } } @@@ -132,6 -132,6 +138,7 @@@ * * @see java.util.Map#size() */ ++ @Override public int size() { return internalMap.size(); } @@@ -141,6 -141,6 +148,7 @@@ * * @see java.util.Map#isEmpty() */ ++ @Override public boolean isEmpty() { return internalMap.isEmpty(); } @@@ -151,6 -151,6 +159,7 @@@ * * @see java.util.Map#containsKey(java.lang.Object) */ ++ @Override public boolean containsKey(Object key) { return internalMap.containsKey(key); } @@@ -161,6 -161,6 +170,7 @@@ * * @see java.util.Map#containsValue(java.lang.Object) */ ++ @Override public boolean containsValue(Object value) { return internalMap.containsValue(value); } @@@ -171,6 -171,6 +181,7 @@@ * * @see java.util.Map#get(java.lang.Object) */ ++ @Override public V get(Object key) { return internalMap.get(key); } @@@ -178,6 -178,6 +189,7 @@@ /** * This method will return a read-only {@link Set}. */ ++ @Override public Set<K> keySet() { return internalMap.keySet(); } @@@ -185,6 -185,6 +197,7 @@@ /** * This method will return a read-only {@link Collection}. */ ++ @Override public Collection<V> values() { return internalMap.values(); } @@@ -192,6 -192,6 +205,7 @@@ /** * This method will return a read-only {@link Set}. */ ++ @Override public Set<Entry<K, V>> entrySet() { return internalMap.entrySet(); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java index 7b9d595,7b9d595..989b9b8 --- a/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java +++ b/mina-core/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java @@@ -33,7 -33,7 +33,7 @@@ import org.slf4j.LoggerFactory * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class DefaultExceptionMonitor extends ExceptionMonitor { -- private final static Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMonitor.class); ++ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMonitor.class); /** * {@inheritDoc} http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java index 97cc621,97cc621..da5b644 --- a/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExceptionMonitor.java @@@ -51,10 -51,10 +51,10 @@@ public abstract class ExceptionMonitor */ public static void setInstance(ExceptionMonitor monitor) { if (monitor == null) { -- monitor = new DefaultExceptionMonitor(); ++ instance = new DefaultExceptionMonitor(); ++ } else { ++ instance = monitor; } -- -- instance = monitor; } /** http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java index ec56817,ec56817..51b7673 --- a/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExpirationListener.java @@@ -21,10 -21,10 +21,16 @@@ package org.apache.mina.util /** * A listener for expired object events. ++ * ++ * @param <E> The event type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> -- * TODO Make this a inner interface of ExpiringMap */ public interface ExpirationListener<E> { ++ /** ++ * Adds a given event to the listener ++ * ++ * @param expiredObject The expired event ++ */ void expired(E expiredObject); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java index 3243a61,3243a61..2c7df2d --- a/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/ExpiringMap.java @@@ -31,6 -31,6 +31,9 @@@ import java.util.concurrent.locks.Reent * A map with expiration. This class contains a worker thread that will * periodically check this class in order to determine if any objects * should be removed based on the provided time-to-live value. ++ * ++ * @param <K> The key type ++ * @param <V> The value type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -90,6 -90,6 +93,10 @@@ public class ExpiringMap<K, V> implemen expirer.setExpirationInterval(expirationInterval); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V put(K key, V value) { ExpiringObject answer = delegate.put(key, new ExpiringObject(key, value, System.currentTimeMillis())); @@@ -100,6 -100,6 +107,10 @@@ return answer.getValue(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V get(Object key) { ExpiringObject object = delegate.get(key); @@@ -112,6 -112,6 +123,10 @@@ return null; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V remove(Object key) { ExpiringObject answer = delegate.remove(key); if (answer == null) { @@@ -121,62 -121,62 +136,117 @@@ return answer.getValue(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean containsKey(Object key) { return delegate.containsKey(key); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean containsValue(Object value) { return delegate.containsValue(value); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public int size() { return delegate.size(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public boolean isEmpty() { return delegate.isEmpty(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void clear() { delegate.clear(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public int hashCode() { return delegate.hashCode(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Set<K> keySet() { return delegate.keySet(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean equals(Object obj) { return delegate.equals(obj); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void putAll(Map<? extends K, ? extends V> inMap) { for (Entry<? extends K, ? extends V> e : inMap.entrySet()) { this.put(e.getKey(), e.getValue()); } } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Collection<V> values() { throw new UnsupportedOperationException(); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public Set<Map.Entry<K, V>> entrySet() { throw new UnsupportedOperationException(); } ++ /** ++ * Adds a listener in the expiration listeners ++ * ++ * @param listener The listener to add ++ */ public void addExpirationListener(ExpirationListener<V> listener) { expirationListeners.add(listener); } ++ /** ++ * Removes a listener from the expiration listeners ++ * ++ * @param listener The listener to remove ++ */ public void removeExpirationListener(ExpirationListener<V> listener) { expirationListeners.remove(listener); } ++ /** ++ * @return The Expirer instance ++ */ public Expirer getExpirer() { return expirer; } @@@ -298,6 -298,6 +368,10 @@@ expirerThread.setDaemon(true); } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public void run() { while (running) { processExpires(); @@@ -354,6 -354,6 +428,7 @@@ */ public void startExpiringIfNotStarted() { stateLock.readLock().lock(); ++ try { if (running) { return; @@@ -363,6 -363,6 +438,7 @@@ } stateLock.writeLock().lock(); ++ try { if (!running) { running = true; http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java index c59e41e,c59e41e..a6e5e13 --- a/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java +++ b/mina-core/src/main/java/org/apache/mina/util/IdentityHashSet.java @@@ -25,21 -25,21 +25,35 @@@ import java.util.Set /** * An {@link IdentityHashMap}-backed {@link Set}. ++ * ++ * @param <E> The element type * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public class IdentityHashSet<E> extends MapBackedSet<E> { -- private static final long serialVersionUID = 6948202189467167147L; ++ /** ++ * Creates a new IdentityHashSet instance ++ */ public IdentityHashSet() { super(new IdentityHashMap<E, Boolean>()); } ++ /** ++ * Creates a new IdentityHashSet instance ++ * ++ * @param expectedMaxSize The maximum size for the map ++ */ public IdentityHashSet(int expectedMaxSize) { super(new IdentityHashMap<E, Boolean>(expectedMaxSize)); } ++ /** ++ * Creates a new IdentityHashSet instance ++ * ++ * @param c The elements to put in the map ++ */ public IdentityHashSet(Collection<E> c) { super(new IdentityHashMap<E, Boolean>(), c); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java index 68742fa,68742fa..d38fc61 --- a/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java +++ b/mina-core/src/main/java/org/apache/mina/util/LazyInitializedCacheMap.java @@@ -37,6 -37,6 +37,9 @@@ import org.apache.mina.core.buffer.IoBu * {@link UnsupportedOperationException} on each method that is not intended to * be called by user code for performance reasons. * ++ * @param <K> The key type ++ * @param <V> The value type ++ * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M2 */ @@@ -50,10 -50,10 +53,19 @@@ public class LazyInitializedCacheMap<K public class NoopInitializer extends LazyInitializer<V> { private V value; ++ /** ++ * Create a new NoopInitializer instance ++ * ++ * @param value The value stored in this initializer ++ */ public NoopInitializer(V value) { this.value = value; } ++ /** ++ * {@inheritDoc} ++ */ ++ @Override public V init() { return value; } @@@ -64,7 -64,7 +76,7 @@@ * {@link ConcurrentHashMap}. */ public LazyInitializedCacheMap() { -- this.cache = new ConcurrentHashMap<K, LazyInitializer<V>>(); ++ this.cache = new ConcurrentHashMap<>(); } /** @@@ -73,15 -73,15 +85,17 @@@ * * @param map The map to use as a cache */ -- public LazyInitializedCacheMap(final ConcurrentHashMap<K, LazyInitializer<V>> map) { ++ public LazyInitializedCacheMap(ConcurrentHashMap<K, LazyInitializer<V>> map) { this.cache = map; } /** * {@inheritDoc} */ ++ @Override public V get(Object key) { LazyInitializer<V> c = cache.get(key); ++ if (c != null) { return c.get(); } @@@ -92,8 -92,8 +106,10 @@@ /** * {@inheritDoc} */ ++ @Override public V remove(Object key) { LazyInitializer<V> c = cache.remove(key); ++ if (c != null) { return c.get(); } @@@ -120,8 -120,8 +136,10 @@@ */ public V putIfAbsent(K key, LazyInitializer<V> value) { LazyInitializer<V> v = cache.get(key); ++ if (v == null) { v = cache.putIfAbsent(key, value); ++ if (v == null) { return value.get(); } @@@ -133,8 -133,8 +151,10 @@@ /** * {@inheritDoc} */ ++ @Override public V put(K key, V value) { LazyInitializer<V> c = cache.put(key, new NoopInitializer(value)); ++ if (c != null) { return c.get(); } @@@ -146,6 -146,6 +166,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } @@@ -154,6 -154,6 +175,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public Collection<V> values() { throw new UnsupportedOperationException(); } @@@ -162,6 -162,6 +184,7 @@@ * Throws {@link UnsupportedOperationException} as this method would imply * performance drops. */ ++ @Override public Set<java.util.Map.Entry<K, V>> entrySet() { throw new UnsupportedOperationException(); } @@@ -169,6 -169,6 +192,7 @@@ /** * {@inheritDoc} */ ++ @Override public void putAll(Map<? extends K, ? extends V> m) { for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) { cache.put(e.getKey(), new NoopInitializer(e.getValue())); @@@ -185,6 -185,6 +209,7 @@@ /** * {@inheritDoc} */ ++ @Override public void clear() { cache.clear(); } @@@ -192,6 -192,6 +217,7 @@@ /** * {@inheritDoc} */ ++ @Override public boolean containsKey(Object key) { return cache.containsKey(key); } @@@ -199,6 -199,6 +225,7 @@@ /** * {@inheritDoc} */ ++ @Override public boolean isEmpty() { return cache.isEmpty(); } @@@ -206,6 -206,6 +233,7 @@@ /** * {@inheritDoc} */ ++ @Override public Set<K> keySet() { return cache.keySet(); } @@@ -213,6 -213,6 +241,7 @@@ /** * {@inheritDoc} */ ++ @Override public int size() { return cache.size(); } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java index 924feea,924feea..ccc1684 --- a/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java +++ b/mina-core/src/main/java/org/apache/mina/util/LazyInitializer.java @@@ -24,6 -24,6 +24,8 @@@ package org.apache.mina.util * fully initialized when requested to. It allows to avoid loosing time when * early initializing unnecessary objects. * ++ * @param <V> The value type ++ * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * @since MINA 2.0.0-M2 */ http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java index 455fe0f,455fe0f..7dc1449 --- a/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java +++ b/mina-core/src/main/java/org/apache/mina/util/Log4jXmlFormatter.java @@@ -46,11 -46,11 +46,11 @@@ import org.slf4j.MDC */ public class Log4jXmlFormatter extends Formatter { -- private final int DEFAULT_SIZE = 256; ++ private static final int DEFAULT_SIZE = 256; -- private final int UPPER_LIMIT = 2048; ++ private static final int UPPER_LIMIT = 2048; -- private StringBuffer buf = new StringBuffer(DEFAULT_SIZE); ++ private StringBuilder buf = new StringBuilder(DEFAULT_SIZE); private boolean locationInfo = false; @@@ -99,10 -99,10 +99,11 @@@ // Reset working buffer. If the buffer is too large, then we need a new // one in order to avoid the penalty of creating a large array. if (buf.capacity() > UPPER_LIMIT) { -- buf = new StringBuffer(DEFAULT_SIZE); ++ buf = new StringBuilder(DEFAULT_SIZE); } else { buf.setLength(0); } ++ buf.append("<log4j:event logger=\""); buf.append(Transform.escapeTags(record.getLoggerName())); buf.append("\" timestamp=\""); @@@ -122,12 -122,12 +123,15 @@@ if (record.getThrown() != null) { String[] s = Transform.getThrowableStrRep(record.getThrown()); ++ if (s != null) { buf.append("<log4j:throwable><![CDATA["); ++ for (String value : s) { Transform.appendEscapingCDATA(buf, value); buf.append("\r\n"); } ++ buf.append("]]></log4j:throwable>\r\n"); } } @@@ -146,13 -146,13 +150,13 @@@ if (contextMap != null) { Set<String> keySet = contextMap.keySet(); -- if ((keySet != null) && (keySet.size() > 0)) { ++ if ((keySet != null) && !keySet.isEmpty()) { buf.append("<log4j:properties>\r\n"); Object[] keys = keySet.toArray(); Arrays.sort(keys); for (Object key1 : keys) { -- String key = (key1 == null ? "" : key1.toString()); ++ String key = key1 == null ? "" : key1.toString(); Object val = contextMap.get(key); if (val != null) { @@@ -167,11 -167,11 +171,10 @@@ buf.append("</log4j:properties>\r\n"); } } -- } ++ buf.append("</log4j:event>\r\n\r\n"); return buf.toString(); } -- } http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java index 9198bc2,9198bc2..77d201b --- a/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java +++ b/mina-core/src/main/java/org/apache/mina/util/MapBackedSet.java @@@ -28,6 -28,6 +28,8 @@@ import java.util.Set /** * A {@link Map}-backed {@link Set}. ++ * ++ * @param <E> The element stored in the set * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@@ -37,40 -37,40 +39,69 @@@ public class MapBackedSet<E> extends Ab protected final Map<E, Boolean> map; ++ /** ++ * Creates a new MapBackedSet instance ++ * ++ * @param map The map that we want to back ++ */ public MapBackedSet(Map<E, Boolean> map) { this.map = map; } ++ /** ++ * Creates a new MapBackedSet instance ++ * ++ * @param map The map that we want to back ++ * @param c The elements we want to add in the map ++ */ public MapBackedSet(Map<E, Boolean> map, Collection<E> c) { this.map = map; addAll(c); } ++ /** ++ * {@inheritDoc} ++ */ @Override public int size() { return map.size(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean contains(Object o) { return map.containsKey(o); } ++ /** ++ * {@inheritDoc} ++ */ @Override public Iterator<E> iterator() { return map.keySet().iterator(); } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean add(E o) { return map.put(o, Boolean.TRUE) == null; } ++ /** ++ * {@inheritDoc} ++ */ @Override public boolean remove(Object o) { return map.remove(o) != null; } ++ /** ++ * {@inheritDoc} ++ */ @Override public void clear() { map.clear(); http://git-wip-us.apache.org/repos/asf/mina/blob/cb9bb7cf/mina-core/src/main/java/org/apache/mina/util/Transform.java ---------------------------------------------------------------------- diff --cc mina-core/src/main/java/org/apache/mina/util/Transform.java index ee52a20,ee52a20..90e9b42 --- a/mina-core/src/main/java/org/apache/mina/util/Transform.java +++ b/mina-core/src/main/java/org/apache/mina/util/Transform.java @@@ -54,14 -54,14 +54,11 @@@ public class Transform * @param input The text to be converted. * @return The input string with the special characters replaced. * */ -- static public String escapeTags(final String input) { ++ public static String escapeTags(String input) { // Check if the string is null, zero length or devoid of special characters // if so, return what was sent in. -- if (input == null -- || input.length() == 0 -- || (input.indexOf('"') == -1 && input.indexOf('&') == -1 && input.indexOf('<') == -1 && input -- .indexOf('>') == -1)) { ++ if (input == null || input.length() == 0) { return input; } @@@ -69,22 -69,22 +66,33 @@@ char ch; int len = input.length(); ++ for (int i = 0; i < len; i++) { ch = input.charAt(i); -- if (ch > '>') { -- buf.append(ch); -- } else if (ch == '<') { -- buf.append("<"); -- } else if (ch == '>') { -- buf.append(">"); -- } else if (ch == '&') { -- buf.append("&"); -- } else if (ch == '"') { -- buf.append("""); -- } else { -- buf.append(ch); ++ ++ switch ( ch ) ++ { ++ case '<' : ++ buf.append("<"); ++ break; ++ ++ case '>' : ++ buf.append(">"); ++ break; ++ ++ case '&' : ++ buf.append("&"); ++ break; ++ ++ case '"' : ++ buf.append("""); ++ break; ++ ++ default : ++ buf.append(ch); } } ++ return buf.toString(); } @@@ -97,23 -97,23 +105,27 @@@ * section are the responsibility of the calling method. * @param str The String that is inserted into an existing CDATA Section within buf. * */ -- static public void appendEscapingCDATA(final StringBuffer buf, final String str) { ++ public static void appendEscapingCDATA(final StringBuilder buf, final String str) { if (str != null) { int end = str.indexOf(CDATA_END); ++ if (end < 0) { buf.append(str); } else { int start = 0; ++ while (end > -1) { buf.append(str.substring(start, end)); buf.append(CDATA_EMBEDED_END); start = end + CDATA_END_LEN; ++ if (start < str.length()) { end = str.indexOf(CDATA_END, start); } else { return; } } ++ buf.append(str.substring(start)); } } @@@ -130,9 -130,9 +142,11 @@@ throwable.printStackTrace(pw); pw.flush(); LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString())); -- ArrayList<String> lines = new ArrayList<String>(); ++ ArrayList<String> lines = new ArrayList<>(); ++ try { String line = reader.readLine(); ++ while (line != null) { lines.add(line); line = reader.readLine(); @@@ -140,9 -140,9 +154,10 @@@ } catch (IOException ex) { lines.add(ex.toString()); } ++ String[] rep = new String[lines.size()]; lines.toArray(rep); ++ return rep; } -- }
