You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ed...@apache.org on 2009/04/17 15:19:46 UTC
svn commit: r765985 - in
/mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http:
AbstractHttpLogicHandler.java basic/HttpBasicAuthLogicHandler.java
digest/HttpDigestAuthLogicHandler.java ntlm/HttpNTLMAuthLogicHandler.java
Author: edeoliveira
Date: Fri Apr 17 13:19:46 2009
New Revision: 765985
URL: http://svn.apache.org/viewvc?rev=765985&view=rev
Log:
Removed some unnecessary checks added new method to the parent class to help into adding keep alive headers
Modified:
mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/AbstractHttpLogicHandler.java
mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/basic/HttpBasicAuthLogicHandler.java
mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java
mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/HttpNTLMAuthLogicHandler.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/AbstractHttpLogicHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/AbstractHttpLogicHandler.java?rev=765985&r1=765984&r2=765985&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/AbstractHttpLogicHandler.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/AbstractHttpLogicHandler.java Fri Apr 17 13:19:46 2009
@@ -32,7 +32,6 @@
import org.apache.mina.core.session.IoSessionInitializer;
import org.apache.mina.proxy.AbstractProxyLogicHandler;
import org.apache.mina.proxy.ProxyAuthException;
-import org.apache.mina.proxy.ProxyConnector;
import org.apache.mina.proxy.session.ProxyIoSession;
import org.apache.mina.proxy.utils.IoBufferDecoder;
import org.apache.mina.proxy.utils.StringUtilities;
@@ -108,7 +107,7 @@
/**
* Creates a new {@link AbstractHttpLogicHandler}.
*
- * @param proxyIoSession {@link ProxyIoSession} in use.
+ * @param proxyIoSession the {@link ProxyIoSession} in use.
* @param request the requested url to negotiate with the proxy.
*/
public AbstractHttpLogicHandler(final ProxyIoSession proxyIoSession) {
@@ -116,8 +115,11 @@
}
/**
- * Handle incoming data during the handshake process. Should consume only the
+ * Handles incoming data during the handshake process. Should consume only the
* handshake data from the buffer, leaving any extra data in place.
+ *
+ * @param nextFilter the next filter
+ * @param buf the buffer holding received data
*/
public synchronized void messageReceived(final NextFilter nextFilter,
final IoBuffer buf) throws ProxyAuthException {
@@ -295,7 +297,7 @@
}
/**
- * Handle a HTTP response from the proxy server.
+ * Handles a HTTP response from the proxy server.
*
* @param response The response.
*/
@@ -305,9 +307,12 @@
/**
* Calls{@link #writeRequest0(NextFilter, HttpProxyRequest)} to write the request.
* If needed a reconnection to the proxy is done previously.
+ *
+ * @param nextFilter the next filter
+ * @param request the http request
*/
public void writeRequest(final NextFilter nextFilter,
- final HttpProxyRequest request) throws ProxyAuthException {
+ final HttpProxyRequest request) {
ProxyIoSession proxyIoSession = getProxyIoSession();
if (proxyIoSession.isReconnectionNeeded()) {
@@ -318,7 +323,10 @@
}
/**
- * Encode a HTTP request and send it to the proxy server.
+ * Encodes a HTTP request and sends it to the proxy server.
+ *
+ * @param nextFilter the next filter
+ * @param request the http request
*/
private void writeRequest0(final NextFilter nextFilter,
final HttpProxyRequest request) {
@@ -338,32 +346,41 @@
}
/**
- * Method to reconnect to proxy when it decides not to maintain the connection during handshake.
- * @throws ProxyAuthException
+ * Method to reconnect to the proxy when it decides not to maintain the connection
+ * during handshake.
+ *
+ * @param nextFilter the next filter
+ * @param request the http request
*/
private void reconnect(final NextFilter nextFilter,
- final HttpProxyRequest request) throws ProxyAuthException {
+ final HttpProxyRequest request) {
logger.debug("Reconnecting to proxy ...");
final ProxyIoSession proxyIoSession = getProxyIoSession();
- final ProxyConnector connector = proxyIoSession.getConnector();
- connector.connect(new IoSessionInitializer<ConnectFuture>() {
- public void initializeSession(final IoSession session,
- ConnectFuture future) {
- logger.debug("Initializing new session: " + session);
- session.setAttribute(ProxyIoSession.PROXY_SESSION,
- proxyIoSession);
- proxyIoSession.setSession(session);
- logger.debug(" setting proxyIoSession: " + proxyIoSession);
- future.addListener(new IoFutureListener<ConnectFuture>() {
- public void operationComplete(ConnectFuture future) {
- proxyIoSession.setReconnectionNeeded(false);
- writeRequest0(nextFilter, request);
- }
- });
- }
- });
+ // Fires reconnection
+ proxyIoSession.getConnector().connect(
+ new IoSessionInitializer<ConnectFuture>() {
+ public void initializeSession(final IoSession session,
+ ConnectFuture future) {
+ logger.debug("Initializing new session: {}", session);
+ session.setAttribute(ProxyIoSession.PROXY_SESSION,
+ proxyIoSession);
+ proxyIoSession.setSession(session);
+ logger.debug(" setting up proxyIoSession: {}", proxyIoSession);
+ future
+ .addListener(new IoFutureListener<ConnectFuture>() {
+ public void operationComplete(
+ ConnectFuture future) {
+ // Reconnection is done so we send the
+ // request to the proxy
+ proxyIoSession
+ .setReconnectionNeeded(false);
+ writeRequest0(nextFilter, request);
+ }
+ });
+ }
+ });
}
/**
@@ -379,8 +396,8 @@
String[] responseLines = response.split(HttpProxyConstants.CRLF);
// Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
- // BUG FIX : Trimed to prevent failures with some proxies that add extra space chars
- // like "Microsoft-IIS/5.0" ...
+ // BUG FIX : Trimed to prevent failures with some proxies that add
+ // extra space chars like "Microsoft-IIS/5.0" ...
String[] statusLine = responseLines[0].trim().split(" ", 2);
if (statusLine.length < 2) {
Modified: mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/basic/HttpBasicAuthLogicHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/basic/HttpBasicAuthLogicHandler.java?rev=765985&r1=765984&r2=765985&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/basic/HttpBasicAuthLogicHandler.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/basic/HttpBasicAuthLogicHandler.java Fri Apr 17 13:19:46 2009
@@ -53,11 +53,6 @@
throws ProxyAuthException {
super(proxyIoSession);
- if (request == null || !(request instanceof HttpProxyRequest)) {
- throw new IllegalArgumentException(
- "request parameter should be a non null HttpProxyRequest instance");
- }
-
((HttpProxyRequest) request).checkRequiredProperties(
HttpProxyConstants.USER_PROPERTY,
HttpProxyConstants.PWD_PROPERTY);
@@ -88,10 +83,7 @@
StringUtilities.addValueToHeader(headers, "Proxy-Authorization",
"Basic " + createAuthorization(username, password), true);
- StringUtilities.addValueToHeader(headers, "Keep-Alive",
- HttpProxyConstants.DEFAULT_KEEP_ALIVE_TIME, true);
- StringUtilities.addValueToHeader(headers, "Proxy-Connection",
- "keep-Alive", true);
+ addKeepAliveHeaders(headers);
req.setHeaders(headers);
writeRequest(nextFilter, req);
Modified: mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java?rev=765985&r1=765984&r2=765985&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/digest/HttpDigestAuthLogicHandler.java Fri Apr 17 13:19:46 2009
@@ -77,11 +77,6 @@
throws ProxyAuthException {
super(proxyIoSession);
- if (request == null || !(request instanceof HttpProxyRequest)) {
- throw new IllegalArgumentException(
- "request parameter should be a non null HttpProxyRequest instance");
- }
-
((HttpProxyRequest) request).checkRequiredProperties(
HttpProxyConstants.USER_PROPERTY,
HttpProxyConstants.PWD_PROPERTY);
@@ -102,6 +97,7 @@
if (step > 0) {
logger.debug(" sending DIGEST challenge response");
+ // Build a challenge response
HashMap<String, String> map = new HashMap<String, String>();
map.put("username", req.getProperties().get(
HttpProxyConstants.USER_PROPERTY));
@@ -177,7 +173,8 @@
"Digest response computing failed", e);
}
- // Prepare the challenge response header and add it to the request we will send
+ // Prepare the challenge response header and add it to the
+ // request we will send
StringBuilder sb = new StringBuilder("Digest ");
boolean addSeparator = false;
@@ -203,10 +200,7 @@
"Proxy-Authorization", sb.toString(), true);
}
- StringUtilities.addValueToHeader(headers, "Keep-Alive",
- HttpProxyConstants.DEFAULT_KEEP_ALIVE_TIME, true);
- StringUtilities.addValueToHeader(headers, "Proxy-Connection",
- "keep-Alive", true);
+ addKeepAliveHeaders(headers);
req.setHeaders(headers);
writeRequest(nextFilter, req);
@@ -227,7 +221,7 @@
+ response.getStatusLine() + ").");
}
- // Header should be like this
+ // Header should look like this
// Proxy-Authenticate: Digest still_some_more_stuff
List<String> values = response.getHeaders().get(
"Proxy-Authenticate");
Modified: mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/HttpNTLMAuthLogicHandler.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/HttpNTLMAuthLogicHandler.java?rev=765985&r1=765984&r2=765985&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/HttpNTLMAuthLogicHandler.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/proxy/handlers/http/ntlm/HttpNTLMAuthLogicHandler.java Fri Apr 17 13:19:46 2009
@@ -60,11 +60,6 @@
throws ProxyAuthException {
super(proxyIoSession);
- if (request == null || !(request instanceof HttpProxyRequest)) {
- throw new IllegalArgumentException(
- "request parameter should be a non null HttpProxyRequest instance");
- }
-
((HttpProxyRequest) request).checkRequiredProperties(
HttpProxyConstants.USER_PROPERTY,
HttpProxyConstants.PWD_PROPERTY,
@@ -80,7 +75,7 @@
logger.debug(" doHandshake()");
if (step > 0 && challengePacket == null) {
- throw new IllegalStateException("Challenge packet not received");
+ throw new IllegalStateException("NTLM Challenge packet not received");
} else {
HttpProxyRequest req = (HttpProxyRequest) request;
Map<String, List<String>> headers = req.getHeaders() != null ? req
@@ -109,13 +104,13 @@
serverFlags, null);
StringUtilities.addValueToHeader(headers,
- "Proxy-Authorization", "NTLM "
- + new String(Base64
+ "Proxy-Authorization",
+ "NTLM "+ new String(Base64
.encodeBase64(authenticationPacket)),
true);
} else {
- logger.debug(" sending HTTP request");
+ logger.debug(" sending NTLM negotiation packet");
byte[] negotiationPacket = NTLMUtilities.createType1Message(
workstation, domain, null, null);
@@ -123,17 +118,12 @@
.addValueToHeader(
headers,
"Proxy-Authorization",
- "NTLM "
- + new String(
- Base64
- .encodeBase64(negotiationPacket)),
+ "NTLM "+ new String(Base64
+ .encodeBase64(negotiationPacket)),
true);
}
- StringUtilities.addValueToHeader(headers, "Keep-Alive",
- HttpProxyConstants.DEFAULT_KEEP_ALIVE_TIME, true);
- StringUtilities.addValueToHeader(headers, "Proxy-Connection",
- "keep-Alive", true);
+ addKeepAliveHeaders(headers);
req.setHeaders(headers);
writeRequest(nextFilter, req);
@@ -143,6 +133,8 @@
/**
* Returns the value of the NTLM Proxy-Authenticate header.
+ *
+ * @param response the proxy response
*/
private String getNTLMHeader(final HttpProxyResponse response) {
List<String> values = response.getHeaders().get("Proxy-Authenticate");