You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2007/09/17 02:25:08 UTC
svn commit: r576224 - in /geronimo/sandbox/AsyncHttpClient/src:
main/java/org/apache/ahc/ main/java/org/apache/ahc/codec/
main/java/org/apache/ahc/ssl/ main/java/org/apache/ahc/util/
test/java/org/apache/ahc/
Author: jgenender
Date: Sun Sep 16 17:25:07 2007
New Revision: 576224
URL: http://svn.apache.org/viewvc?rev=576224&view=rev
Log:
Clean up code with checkstyle
Modified:
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Cookie.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/DateUtil.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/EncodingUtil.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/LangUtils.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/NameValuePair.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/ChunkedTest.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeIoSession.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.java Sun Sep 16 17:25:07 2007
@@ -19,6 +19,12 @@
*/
package org.apache.ahc;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.security.GeneralSecurityException;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import javax.net.ssl.SSLContext;
+
import org.apache.ahc.codec.HttpIoHandler;
import org.apache.ahc.codec.HttpProtocolCodecFactory;
import org.apache.ahc.codec.HttpRequestMessage;
@@ -30,20 +36,11 @@
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.SocketConnector;
-import javax.net.ssl.SSLContext;
-import java.net.InetSocketAddress;
-import java.net.URL;
-import java.security.GeneralSecurityException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
public class AsyncHttpClient {
- public static int DEFAULT_REQUEST_TIMEOUT = 30000;
- public static int DEFAULT_CONNECTION_TIMEOUT = 30000;
- public static String DEFAULT_SSL_PROTOCOL = "TLS";
+ public static final int DEFAULT_REQUEST_TIMEOUT = 30000;
+ public static final int DEFAULT_CONNECTION_TIMEOUT = 30000;
+ public static final String DEFAULT_SSL_PROTOCOL = "TLS";
private URL url;
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
@@ -52,7 +49,8 @@
private IoSession session;
private AsyncHttpClientCallback callback;
private int requestTimeout = DEFAULT_REQUEST_TIMEOUT;
- private ConcurrentLinkedQueue<HttpRequestMessage> sendQueue = new ConcurrentLinkedQueue<HttpRequestMessage>();
+ private ConcurrentLinkedQueue<HttpRequestMessage> sendQueue
+ = new ConcurrentLinkedQueue<HttpRequestMessage>();
private ConnectionListener connectionListener = new ConnectionListener();
public AsyncHttpClient(URL url, AsyncHttpClientCallback callback) {
@@ -63,7 +61,8 @@
this(url, callback, connectionTimeout, DEFAULT_REQUEST_TIMEOUT);
}
- public AsyncHttpClient(URL url, AsyncHttpClientCallback callback, int connectionTimeout, int requestTimeout) {
+ public AsyncHttpClient(URL url, AsyncHttpClientCallback callback, int connectionTimeout,
+ int requestTimeout) {
this.url = url;
this.callback = callback;
this.connectionTimeout = connectionTimeout;
@@ -72,7 +71,7 @@
public void connect() throws Exception {
sendQueue.clear();
- SocketConnector connector = new SocketConnector();
+ connector = new SocketConnector();
IoConnectorConfig cfg = connector.getDefaultConfig();
cfg.setConnectTimeout(connectionTimeout / 1000);
@@ -91,9 +90,11 @@
port = 80;
}
- cfg.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new HttpProtocolCodecFactory(url)));
+ cfg.getFilterChain()
+ .addLast("protocolFilter", new ProtocolCodecFilter(new HttpProtocolCodecFactory(url)));
- ConnectFuture future = connector.connect(new InetSocketAddress(url.getHost(), port), new HttpIoHandler(connectionListener, callback, requestTimeout));
+ ConnectFuture future = connector.connect(new InetSocketAddress(url.getHost(), port),
+ new HttpIoHandler(connectionListener, callback, requestTimeout));
}
public void disconnect() {
@@ -129,8 +130,9 @@
while (true) {
//Process messages in FIFO
HttpRequestMessage message = sendQueue.poll();
- if (message == null)
+ if (message == null) {
break;
+ }
session.write(message);
}
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java Sun Sep 16 17:25:07 2007
@@ -22,8 +22,8 @@
import org.apache.ahc.codec.HttpResponseMessage;
public interface AsyncHttpClientCallback {
- public void onResponse(HttpResponseMessage message);
- public void onException(Throwable cause);
- public void onClosed();
- public void onTimeout();
+ void onResponse(HttpResponseMessage message);
+ void onException(Throwable cause);
+ void onClosed();
+ void onTimeout();
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Cookie.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Cookie.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Cookie.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Cookie.java Sun Sep 16 17:25:07 2007
@@ -29,7 +29,7 @@
private String value;
private String path;
private boolean secure;
- private int version = 0;
+ private int version;
private Date expires;
public Cookie(String name, String value) {
@@ -92,7 +92,6 @@
public void setVersion(int version) {
this.version = version;
}
-
public Date getExpires() {
return expires;
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java Sun Sep 16 17:25:07 2007
@@ -19,18 +19,32 @@
*/
package org.apache.ahc.codec;
-import org.apache.ahc.codec.HttpResponseMessage;
-import org.apache.ahc.codec.Cookie;
-import org.apache.ahc.codec.HttpMessage;
-import org.apache.ahc.util.DateUtil;
-import org.apache.mina.common.ByteBuffer;
-
import java.io.IOException;
-import java.util.Date;
-import java.nio.charset.CharsetDecoder;
import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.util.Date;
+
+import org.apache.ahc.util.DateUtil;
+import org.apache.mina.common.ByteBuffer;
public class HttpDecoder {
+
+ public static final String CHUNKED = "chunked";
+
+ public static final String CONNECTION = "Connection";
+
+ public static final String COOKIE_COMMENT = "comment";
+ public static final String COOKIE_DOMAIN = "domain";
+ public static final String COOKIE_EXPIRES = "expires";
+ public static final String COOKIE_MAX_AGE = "max-age";
+ public static final String COOKIE_PATH = "path";
+ public static final String COOKIE_SECURE = "secure";
+ public static final String COOKIE_VERSION = "version";
+
+ public static final String LOCATION = "Location";
+ public static final String SET_COOKIE = "Set-Cookie";
+ public static final String TRANSFER_ENCODING = "Transfer-Encoding";
+
/**
* Carriage return character
*/
@@ -41,19 +55,7 @@
*/
private static final byte LF = 10;
- public final static String COOKIE_COMMENT = "comment";
- public final static String COOKIE_DOMAIN = "domain";
- public final static String COOKIE_EXPIRES = "expires";
- public final static String COOKIE_MAX_AGE = "max-age";
- public final static String COOKIE_PATH = "path";
- public final static String COOKIE_SECURE = "secure";
- public final static String COOKIE_VERSION = "version";
-
- public final static String SET_COOKIE = "Set-Cookie";
- public final static String CONNECTION = "Connection";
- public final static String LOCATION = "Location";
- public final static String TRANSFER_ENCODING = "Transfer-Encoding";
- public final static String CHUNKED = "chunked";
+
private CharsetDecoder decoder = Charset.defaultCharset().newDecoder();
@@ -77,8 +79,9 @@
}
//Check if we don't have enough data to process or found a full readable line
- if (terminatorPos == -1)
+ if (terminatorPos == -1) {
return null;
+ }
String result = null;
if (terminatorPos > 1) {
@@ -94,8 +97,9 @@
public void decodeStatus(String line, HttpResponseMessage msg) throws Exception {
String magic = line.substring(0, 8);
- if (!magic.equals("HTTP/1.1") && !magic.equals("HTTP/1.0"))
+ if (!magic.equals("HTTP/1.1") && !magic.equals("HTTP/1.0")) {
throw new IOException("Invalid HTTP response");
+ }
String status = line.substring(9, 12);
msg.setStatusCode(Integer.parseInt(status));
@@ -110,7 +114,9 @@
if (name.equalsIgnoreCase(SET_COOKIE)) {
Cookie cookie = decodeCookie(value);
- if (cookie != null) msg.addCookie(cookie);
+ if (cookie != null) {
+ msg.addCookie(cookie);
+ }
}
if (name.equalsIgnoreCase(HttpMessage.CONTENT_TYPE)) {
@@ -140,7 +146,7 @@
for (int i = 0; i < strippedLine.length(); i++) {
char ch = strippedLine.charAt(i);
//Once we hit a non-numeric character, parse the number we have
- if ((ch < '0' || (ch > '9' && ch < 'a') || ch > 'f')) {
+ if (ch < '0' || (ch > '9' && ch < 'a') || ch > 'f') {
return Integer.parseInt(strippedLine.substring(0, i), 16);
}
}
@@ -149,7 +155,7 @@
return Integer.parseInt(strippedLine, 16);
}
- public void decodeContent(ByteBuffer in, HttpResponseMessage msg) throws Exception{
+ public void decodeContent(ByteBuffer in, HttpResponseMessage msg) throws Exception {
byte content[] = new byte[msg.getContentLength()];
in.get(content);
msg.addContent(content);
@@ -157,7 +163,7 @@
public void decodeChunkedContent(ByteBuffer in, HttpResponseMessage msg) throws Exception {
int toRead = msg.getExpectedToRead();
- if ((in.get(in.position() + toRead) != CR) && (in.get(in.position() + toRead + 1)!= LF)) {
+ if ((in.get(in.position() + toRead) != CR) && (in.get(in.position() + toRead + 1) != LF)) {
throw new IOException("Invalid HTTP response - chunk does not end with CRLF");
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java Sun Sep 16 17:25:07 2007
@@ -19,28 +19,31 @@
*/
package org.apache.ahc.codec;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ahc.AsyncHttpClient;
+import org.apache.ahc.AsyncHttpClientCallback;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
-import org.apache.ahc.AsyncHttpClientCallback;
-import org.apache.ahc.AsyncHttpClient;
-
-import java.util.LinkedList;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.*;
public class HttpIoHandler extends IoHandlerAdapter {
- public final static int DEFAULT_THREAD_POOL_SIZE = 10;
- public final static String CONNECTION_CLOSE = "close";
+ public static final int DEFAULT_THREAD_POOL_SIZE = 10;
+ public static final String CONNECTION_CLOSE = "close";
private AsyncHttpClientCallback callback;
- private ConcurrentLinkedQueue<HttpRequestMessage> sentQueue = new ConcurrentLinkedQueue<HttpRequestMessage>();
- private ScheduledExecutorService scheduler = null;
+ private ConcurrentLinkedQueue<HttpRequestMessage> sentQueue
+ = new ConcurrentLinkedQueue<HttpRequestMessage>();
+ private ScheduledExecutorService scheduler;
private int timeoutDelay;
- private AsyncHttpClient.ConnectionListener connectionListener = null;
+ private AsyncHttpClient.ConnectionListener connectionListener;
- public HttpIoHandler(AsyncHttpClient.ConnectionListener connectionListener, AsyncHttpClientCallback callback, int timeoutDelay) {
+ public HttpIoHandler(AsyncHttpClient.ConnectionListener connectionListener,
+ AsyncHttpClientCallback callback, int timeoutDelay) {
this.connectionListener = connectionListener;
this.callback = callback;
this.timeoutDelay = timeoutDelay;
@@ -55,7 +58,7 @@
public void messageReceived(IoSession ioSession, Object object) throws Exception {
//For each send, we should have a response
- HttpResponseMessage response = (HttpResponseMessage) object;
+ HttpResponseMessage response = (HttpResponseMessage)object;
//Remove the sent message
HttpRequestMessage request = sentQueue.poll();
ScheduledFuture handle = request.getTimeoutHandle();
@@ -97,7 +100,7 @@
}
public void messageSent(IoSession ioSession, Object object) throws Exception {
- HttpRequestMessage msg = (HttpRequestMessage) object;
+ HttpRequestMessage msg = (HttpRequestMessage)object;
if (timeoutDelay > 0) {
TimeoutTask task = new TimeoutTask(ioSession);
scheduler.schedule(task, timeoutDelay, TimeUnit.MILLISECONDS);
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java Sun Sep 16 17:25:07 2007
@@ -19,17 +19,17 @@
*/
package org.apache.ahc.codec;
-import org.apache.ahc.util.NameValuePair;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.ahc.util.NameValuePair;
+
public class HttpMessage {
- public final static String CONTENT_TYPE = "Content-Type";
- public final static String CONTENT_LENGTH = "Content-Length";
+ public static final String CONTENT_TYPE = "Content-Type";
+ public static final String CONTENT_LENGTH = "Content-Length";
protected List<NameValuePair> headers = new ArrayList<NameValuePair>();
protected List<Cookie> cookies = new ArrayList<Cookie>();
@@ -38,24 +38,27 @@
protected ByteArrayOutputStream content;
public String getStringContent() {
- if (content == null)
+ if (content == null) {
return null;
+ }
return new String(content.toByteArray());
}
public byte[] getContent() {
- if (content == null)
+ if (content == null) {
return null;
+ }
return content.toByteArray();
}
- public void addContent(byte[] content) throws IOException {
- if (this.content == null)
+ public void addContent(byte[] byteContent) throws IOException {
+ if (this.content == null) {
this.content = new ByteArrayOutputStream();
+ }
- this.content.write(content);
+ this.content.write(byteContent);
}
public List<Cookie> getCookies() {
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java Sun Sep 16 17:25:07 2007
@@ -19,18 +19,19 @@
*/
package org.apache.ahc.codec;
-import org.apache.mina.filter.codec.ProtocolCodecFactory;
-import org.apache.mina.filter.codec.ProtocolEncoder;
-import org.apache.mina.filter.codec.ProtocolDecoder;
import java.net.URL;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
public class HttpProtocolCodecFactory implements ProtocolCodecFactory {
private final ProtocolEncoder encoder;
private final ProtocolDecoder decoder;
- public HttpProtocolCodecFactory(URL url) {
+ public HttpProtocolCodecFactory(final URL url) {
encoder = new HttpRequestEncoder(url);
decoder = new HttpResponseDecoder();
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java Sun Sep 16 17:25:07 2007
@@ -19,24 +19,26 @@
*/
package org.apache.ahc.codec;
-import org.apache.mina.filter.codec.demux.MessageEncoder;
-import org.apache.mina.filter.codec.ProtocolEncoderOutput;
-import org.apache.mina.filter.codec.ProtocolEncoder;
-import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.ahc.util.NameValuePair;
-import org.apache.ahc.util.EncodingUtil;
-
-import java.util.*;
-import java.nio.charset.CharsetEncoder;
+import java.net.URL;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
-import java.net.URL;
+import java.nio.charset.CharsetEncoder;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ahc.util.EncodingUtil;
+import org.apache.ahc.util.NameValuePair;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
public class HttpRequestEncoder extends ProtocolEncoderAdapter {
private static final Set TYPES;
- private static final byte[] CRLF = new byte[]{0x0D, 0x0A};
+ private static final byte[] CRLF = new byte[] {0x0D, 0x0A};
private static final String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
private URL url;
@@ -55,7 +57,7 @@
}
public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput out) throws Exception {
- HttpRequestMessage msg = (HttpRequestMessage) message;
+ HttpRequestMessage msg = (HttpRequestMessage)message;
ByteBuffer buf = ByteBuffer.allocate(256);
@@ -66,11 +68,11 @@
//If we have content, lets create the query string
int attrCount = msg.getParameters().size();
String urlAttrs = "";
- if (attrCount > 0){
+ if (attrCount > 0) {
NameValuePair attrs[] = new NameValuePair[attrCount];
- Set<Map.Entry<String,String>> set = msg.getParameters().entrySet();
+ Set<Map.Entry<String, String>> set = msg.getParameters().entrySet();
int i = 0;
- for (Map.Entry<String, String> entry: set){
+ for (Map.Entry<String, String> entry : set) {
attrs[i++] = new NameValuePair(entry.getKey(), entry.getValue());
}
urlAttrs = EncodingUtil.formUrlEncode(attrs, Charset.defaultCharset().toString());
@@ -83,7 +85,7 @@
//If its a GET, append the attributes
if (msg.getRequestMethod().equals(HttpRequestMessage.REQUEST_GET) && attrCount > 0) {
//If there is not already a ? in the query, append one, otherwise append a &
- if (!msg.getPath().contains("?")){
+ if (!msg.getPath().contains("?")) {
buf.putString("?", encoder);
} else {
buf.putString("&", encoder);
@@ -96,50 +98,28 @@
//This header is required for HTTP/1.1
buf.putString("Host: ", encoder);
buf.putString(url.getHost(), encoder);
- if ((url.getProtocol().equals("http") && url.getPort() != 80 && url.getPort() != -1) &&
- (url.getProtocol().equals("https") && url.getPort() != 443 && url.getPort() != -1)) {
+ if ((url.getProtocol().equals("http") && url.getPort() != 80 && url.getPort() != -1)
+ && (url.getProtocol().equals("https") && url.getPort() != 443 && url.getPort() != -1)) {
buf.putString(":", encoder);
buf.putString(url.getPort() + "", encoder);
}
buf.put(CRLF);
//User agent
- if (msg.getUserAgent() != null){
+ if (msg.getUserAgent() != null) {
buf.putString("User-Agent: ", encoder);
buf.putString(msg.getUserAgent(), encoder);
buf.put(CRLF);
}
//Process any headers we have
- List<NameValuePair> headers = msg.getHeaders();
- for (NameValuePair header : headers) {
- String name = header.getName();
- String value = header.getValue();
-
- buf.putString(name, encoder);
- buf.putString(": ", encoder);
- buf.putString(value, encoder);
- buf.put(CRLF);
- }
+ processHeaders(msg, buf, encoder);
//Process cookies
//NOTE: I am just passing the name value pairs and not doing management of the expiration or path
//As that will be left up to the user. A possible enhancement is to make use of a CookieManager
//to handle these issues for the request
- List<Cookie> cookies = msg.getCookies();
- if (cookies.size() > 0) {
- buf.putString("Cookie: ", encoder);
- for (Cookie cookie : cookies) {
- String name = cookie.getName();
- String value = cookie.getValue();
-
- buf.putString(name, encoder);
- buf.putString("=", encoder);
- buf.putString(value, encoder);
- buf.putString("; ", encoder);
- }
- buf.put(CRLF);
- }
+ processCookies(msg, buf, encoder);
//If this is a POST, then we need a content length and type
if (msg.getRequestMethod().equals(HttpRequestMessage.REQUEST_POST)) {
@@ -171,6 +151,38 @@
buf.flip();
out.write(buf);
+ }
+
+ private void processHeaders(HttpRequestMessage msg, ByteBuffer buf, CharsetEncoder encoder)
+ throws Exception {
+ List<NameValuePair> headers = msg.getHeaders();
+ for (NameValuePair header : headers) {
+ String name = header.getName();
+ String value = header.getValue();
+
+ buf.putString(name, encoder);
+ buf.putString(": ", encoder);
+ buf.putString(value, encoder);
+ buf.put(CRLF);
+ }
+ }
+
+ private void processCookies(HttpRequestMessage msg, ByteBuffer buf, CharsetEncoder encoder)
+ throws Exception {
+ List<Cookie> cookies = msg.getCookies();
+ if (cookies.size() > 0) {
+ buf.putString("Cookie: ", encoder);
+ for (Cookie cookie : cookies) {
+ String name = cookie.getName();
+ String value = cookie.getValue();
+
+ buf.putString(name, encoder);
+ buf.putString("=", encoder);
+ buf.putString(value, encoder);
+ buf.putString("; ", encoder);
+ }
+ buf.put(CRLF);
+ }
}
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java Sun Sep 16 17:25:07 2007
@@ -20,26 +20,26 @@
package org.apache.ahc.codec;
import java.net.ProtocolException;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
import java.util.concurrent.ScheduledFuture;
-public class HttpRequestMessage extends HttpMessage{
+public class HttpRequestMessage extends HttpMessage {
- public static String REQUEST_GET = "GET";
- public static String REQUEST_POST = "POST";
- public static String REQUEST_HEAD = "HEAD";
- public static String REQUEST_OPTIONS = "OPTIONS";
- public static String REQUEST_PUT = "PUT";
- public static String REQUEST_DELETE = "DELETE";
- public static String REQUEST_TRACE = "TRACE";
+ public static final String REQUEST_GET = "GET";
+ public static final String REQUEST_POST = "POST";
+ public static final String REQUEST_HEAD = "HEAD";
+ public static final String REQUEST_OPTIONS = "OPTIONS";
+ public static final String REQUEST_PUT = "PUT";
+ public static final String REQUEST_DELETE = "DELETE";
+ public static final String REQUEST_TRACE = "TRACE";
private String requestMethod = REQUEST_GET;
private String path;
- private Map<String, String> parameters = new HashMap<String,String>();
+ private Map<String, String> parameters = new HashMap<String, String>();
private String userAgent = "AsyncHttpClient 1.0";
private boolean followRedirects = true;
- private ScheduledFuture timeoutHandle = null;
+ private ScheduledFuture timeoutHandle;
public HttpRequestMessage(String path) {
this.path = path;
@@ -59,13 +59,13 @@
public void setRequestMethod(String requestMethod) throws ProtocolException {
- if (requestMethod.equals(REQUEST_GET) ||
- requestMethod.equals(REQUEST_POST) ||
- requestMethod.equals(REQUEST_HEAD) ||
- requestMethod.equals(REQUEST_OPTIONS) ||
- requestMethod.equals(REQUEST_PUT) ||
- requestMethod.equals(REQUEST_DELETE) ||
- requestMethod.equals(REQUEST_TRACE)) {
+ if (requestMethod.equals(REQUEST_GET)
+ || requestMethod.equals(REQUEST_POST)
+ || requestMethod.equals(REQUEST_HEAD)
+ || requestMethod.equals(REQUEST_OPTIONS)
+ || requestMethod.equals(REQUEST_PUT)
+ || requestMethod.equals(REQUEST_DELETE)
+ || requestMethod.equals(REQUEST_TRACE)) {
this.requestMethod = requestMethod;
return;
}
@@ -78,12 +78,13 @@
}
public void setPath(String path) {
- if (path == null || path.trim().length() == 0)
+ if (path == null || path.trim().length() == 0) {
path = "/";
+ }
this.path = path;
}
- public String getParameter(String name){
+ public String getParameter(String name) {
return parameters.get(name);
}
@@ -95,7 +96,7 @@
this.parameters.putAll(parameters);
}
- public void setParameter(String name, String value){
+ public void setParameter(String name, String value) {
parameters.put(name, value);
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java Sun Sep 16 17:25:07 2007
@@ -19,7 +19,7 @@
*/
package org.apache.ahc.codec;
-import org.apache.ahc.codec.HttpDecoder;
+import org.apache.ahc.util.NeedMoreDataException;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
@@ -27,94 +27,105 @@
public class HttpResponseDecoder extends CumulativeProtocolDecoder {
- public final static String CURRENT_RESPONSE = "CURRENT_RESPONSE";
+ public static final String CURRENT_RESPONSE = "CURRENT_RESPONSE";
private HttpDecoder httpDecoder = new HttpDecoder();
- protected boolean doDecode(IoSession ioSession, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
+ protected boolean doDecode(IoSession ioSession, ByteBuffer in, ProtocolDecoderOutput out)
+ throws Exception {
- HttpResponseMessage response = (HttpResponseMessage) ioSession.getAttribute(CURRENT_RESPONSE);
- if (response == null) {
- response = new HttpResponseMessage();
- ioSession.setAttribute(CURRENT_RESPONSE, response);
- }
+ try {
+ HttpResponseMessage response = (HttpResponseMessage)ioSession.getAttribute(CURRENT_RESPONSE);
+ if (response == null) {
+ response = new HttpResponseMessage();
+ ioSession.setAttribute(CURRENT_RESPONSE, response);
+ }
- //Test if we need the response...
- if (response.getState() == HttpResponseMessage.STATE_START) {
+ //Test if we need the response...
+ if (response.getState() == HttpResponseMessage.STATE_START) {
- if (!processStatus(response, in)) {
- return false;
- }
+ if (!processStatus(response, in)) {
+ throw new NeedMoreDataException();
+ }
- //Handle HTTP/1.1 100 Continue
- if (response.getStatusCode() == 100) {
- response.setState(HttpResponseMessage.STATE_STATUS_CONTINUE);
- } else {
- response.setState(HttpResponseMessage.STATE_STATUS_READ);
+ //Handle HTTP/1.1 100 Continue
+ if (response.getStatusCode() == 100) {
+ response.setState(HttpResponseMessage.STATE_STATUS_CONTINUE);
+ } else {
+ response.setState(HttpResponseMessage.STATE_STATUS_READ);
+ }
}
- }
-
- //If we are in a 100 Continue, read until we get the real header
- if (response.getState() == HttpResponseMessage.STATE_STATUS_CONTINUE) {
- //Continue reading until we get a blank line
- while (true) {
- String line = httpDecoder.decodeLine(in);
- //Check if the entire response has been read
- if (line == null)
- return false;
+ //If we are in a 100 Continue, read until we get the real header
+ if (response.getState() == HttpResponseMessage.STATE_STATUS_CONTINUE) {
+ //Continue reading until we get a blank line
+ while (true) {
+ String line = httpDecoder.decodeLine(in);
- //Check if the entire response headers have been read
- if (line.length() == 0) {
- response.setState(HttpResponseMessage.STATE_STATUS_READ);
+ //Check if the entire response has been read
+ if (line == null) {
+ throw new NeedMoreDataException();
+ }
- //The next line should be a header
- if (!processStatus(response, in)) {
- return false;
+ //Check if the entire response headers have been read
+ if (line.length() == 0) {
+ response.setState(HttpResponseMessage.STATE_STATUS_READ);
+
+ //The next line should be a header
+ if (!processStatus(response, in)) {
+ throw new NeedMoreDataException();
+ }
+ break;
}
- break;
}
}
- }
- //Are we reading headers?
- if (response.getState() == HttpResponseMessage.STATE_STATUS_READ) {
- if (processHeaders(response, in) == false)
- return false;
- }
+ //Are we reading headers?
+ if (response.getState() == HttpResponseMessage.STATE_STATUS_READ) {
+ if (!processHeaders(response, in)) {
+ throw new NeedMoreDataException();
+ }
+ }
- //Are we reading content?
- if (response.getState() == HttpResponseMessage.STATE_HEADERS_READ) {
- if (processContent(response, in) == false)
- return false;
- }
+ //Are we reading content?
+ if (response.getState() == HttpResponseMessage.STATE_HEADERS_READ) {
+ if (!processContent(response, in)) {
+ throw new NeedMoreDataException();
+ }
+ }
- //If we are chunked and we have read all the content, then read the footers if there are any
- if (response.isChunked() && response.getState() == HttpResponseMessage.STATE_CONTENT_READ) {
- if (processFooters(response, in) == false)
- return false;
- }
+ //If we are chunked and we have read all the content, then read the footers if there are any
+ if (response.isChunked() && response.getState() == HttpResponseMessage.STATE_CONTENT_READ) {
+ if (!processFooters(response, in)) {
+ throw new NeedMoreDataException();
+ }
+ }
- response.setState(HttpResponseMessage.STATE_FINISHED);
+ response.setState(HttpResponseMessage.STATE_FINISHED);
- out.write(response);
+ out.write(response);
- ioSession.removeAttribute(CURRENT_RESPONSE);
+ ioSession.removeAttribute(CURRENT_RESPONSE);
- return true;
+ return true;
+ } catch (NeedMoreDataException e) {
+ return false;
+ }
}
private boolean processHeaders(HttpResponseMessage response, ByteBuffer in) throws Exception {
- if (!findHeaders(response, in))
+ if (!findHeaders(response, in)) {
return false;
+ }
response.setState(HttpResponseMessage.STATE_HEADERS_READ);
return true;
}
private boolean processFooters(HttpResponseMessage response, ByteBuffer in) throws Exception {
- if (!findHeaders(response, in))
+ if (!findHeaders(response, in)) {
return false;
+ }
response.setState(HttpResponseMessage.STATE_FOOTERS_READ);
return true;
@@ -126,8 +137,9 @@
String line = httpDecoder.decodeLine(in);
//Check if the entire response has been read
- if (line == null)
+ if (line == null) {
return false;
+ }
//Check if the entire response headers have been read
if (line.length() == 0) {
@@ -148,13 +160,14 @@
String line = httpDecoder.decodeLine(in);
//Check if the entire line has been read
- if (line == null)
+ if (line == null) {
return false;
+ }
response.setExpectedToRead(httpDecoder.decodeSize(line));
//Are we done reading the chunked content? (A zero means we are done)
- if (response.getExpectedToRead() == 0){
+ if (response.getExpectedToRead() == 0) {
break;
}
}
@@ -162,7 +175,7 @@
//Now read the content chunk
//Be sure all of the data is there for us to retrieve + the CRLF...
- if (response.getExpectedToRead() + 2 > in.remaining()){
+ if (response.getExpectedToRead() + 2 > in.remaining()) {
//Need more data
return false;
}
@@ -177,8 +190,9 @@
} else if (response.getContentLength() > 0) {
//Do we have enough data?
- if ((response.getContentLength()) > in.remaining())
+ if ((response.getContentLength()) > in.remaining()) {
return false;
+ }
httpDecoder.decodeContent(in, response);
}
@@ -190,8 +204,9 @@
private boolean processStatus(HttpResponseMessage response, ByteBuffer in) throws Exception {
//Read the status header
String header = httpDecoder.decodeLine(in);
- if (header == null)
+ if (header == null) {
return false;
+ }
httpDecoder.decodeStatus(header, response);
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java Sun Sep 16 17:25:07 2007
@@ -19,12 +19,10 @@
*/
package org.apache.ahc.codec;
-import java.io.ByteArrayOutputStream;
-
public class HttpResponseMessage extends HttpMessage {
static final int EXPECTED_NOT_READ = -1;
-
+
static final int STATE_START = 0;
static final int STATE_STATUS_CONTINUE = 1;
static final int STATE_STATUS_READ = 2;
@@ -32,15 +30,15 @@
static final int STATE_CONTENT_READ = 4;
static final int STATE_FOOTERS_READ = 5;
static final int STATE_FINISHED = 6;
-
+
private int statusCode;
private String statusMessage;
private String connection;
- private boolean chunked = false;
+ private boolean chunked;
private int expectedToRead = -1;
private int state = STATE_START;
- private String location = null;
+ private String location;
public int getStatusCode() {
return statusCode;
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java Sun Sep 16 17:25:07 2007
@@ -19,26 +19,28 @@
*/
package org.apache.ahc.ssl;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactorySpi;
import javax.net.ssl.X509TrustManager;
-import javax.net.ssl.ManagerFactoryParameters;
-import java.security.cert.X509Certificate;
-import java.security.cert.CertificateException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.InvalidAlgorithmParameterException;
public class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
- static final X509TrustManager X509 = new X509TrustManager() {
+ public static final X509TrustManager X509 = new X509TrustManager() {
- public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+ public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
+ throws CertificateException {
}
- public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+ public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
+ throws CertificateException {
}
@@ -51,13 +53,13 @@
};
- public static final TrustManager[] X509_MANAGERS = new TrustManager[]{X509};
-
+ public static final TrustManager[] X509_MANAGERS = new TrustManager[] {X509};
protected void engineInit(KeyStore keyStore) throws KeyStoreException {
}
- protected void engineInit(ManagerFactoryParameters managerFactoryParameters) throws InvalidAlgorithmParameterException {
+ protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
+ throws InvalidAlgorithmParameterException {
}
protected TrustManager[] engineGetTrustManagers() {
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java Sun Sep 16 17:25:07 2007
@@ -19,7 +19,7 @@
*/
package org.apache.ahc.util;
-public class AsyncHttpClientException extends Error{
+public class AsyncHttpClientException extends Error {
public AsyncHttpClientException() {
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/DateUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/DateUtil.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/DateUtil.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/DateUtil.java Sun Sep 16 17:25:07 2007
@@ -37,7 +37,7 @@
* @author Christopher Brown
* @author Michael Becke
*/
-public class DateUtil {
+public final class DateUtil {
/**
* Date format pattern used to parse HTTP date headers in RFC 1123 format.
@@ -56,7 +56,7 @@
public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
private static final Collection DEFAULT_PATTERNS = Arrays.asList(
- new String[] { PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123 } );
+ new String[] {PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123});
private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
@@ -69,15 +69,20 @@
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
/**
+ * This class should not be instantiated.
+ */
+ private DateUtil() {
+ }
+
+
+ /**
* Parses a date value. The formats used for parsing the date value are retrieved from
* the default http params.
*
* @param dateValue the date value to parse
- *
* @return the parsed date
- *
* @throws DateParseException if the value could not be parsed using any of the
- * supported date formats
+ * supported date formats
*/
public static Date parseDate(String dateValue) throws DateParseException {
return parseDate(dateValue, null, null);
@@ -86,11 +91,9 @@
/**
* Parses the date value using the given date formats.
*
- * @param dateValue the date value to parse
+ * @param dateValue the date value to parse
* @param dateFormats the date formats to use
- *
* @return the parsed date
- *
* @throws DateParseException if none of the dataFormats could parse the dateValue
*/
public static Date parseDate(String dateValue, Collection dateFormats)
@@ -101,15 +104,13 @@
/**
* Parses the date value using the given date formats.
*
- * @param dateValue the date value to parse
+ * @param dateValue the date value to parse
* @param dateFormats the date formats to use
- * @param startDate During parsing, two digit years will be placed in the range
- * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
- * be <code>null</code>. When <code>null</code> is given as a parameter, year
- * <code>2000</code> will be used.
- *
+ * @param startDate During parsing, two digit years will be placed in the range
+ * <code>startDate</code> to <code>startDate + 100 years</code>. This value may
+ * be <code>null</code>. When <code>null</code> is given as a parameter, year
+ * <code>2000</code> will be used.
* @return the parsed date
- *
* @throws DateParseException if none of the dataFormats could parse the dateValue
*/
public static Date parseDate(
@@ -122,7 +123,7 @@
throw new IllegalArgumentException("dateValue is null");
}
if (dateFormats == null) {
- dateFormats = DEFAULT_PATTERNS;
+ dateFormats = DEFAULT_PATTERNS;
}
if (startDate == null) {
startDate = DEFAULT_TWO_DIGIT_YEAR_START;
@@ -132,15 +133,15 @@
if (dateValue.length() > 1
&& dateValue.startsWith("'")
&& dateValue.endsWith("'")
- ) {
- dateValue = dateValue.substring (1, dateValue.length() - 1);
+ ) {
+ dateValue = dateValue.substring(1, dateValue.length() - 1);
}
SimpleDateFormat dateParser = null;
Iterator formatIter = dateFormats.iterator();
while (formatIter.hasNext()) {
- String format = (String) formatIter.next();
+ String format = (String)formatIter.next();
if (dateParser == null) {
dateParser = new SimpleDateFormat(format, Locale.US);
dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
@@ -164,7 +165,6 @@
*
* @param date The date to format.
* @return An RFC 1123 formatted date string.
- *
* @see #PATTERN_RFC1123
*/
public static String formatDate(Date date) {
@@ -176,24 +176,23 @@
* must conform to that used by the {@link SimpleDateFormat simple date
* format} class.
*
- * @param date The date to format.
+ * @param date The date to format.
* @param pattern The pattern to use for formatting the date.
* @return A formatted date string.
- *
* @throws IllegalArgumentException If the given date pattern is invalid.
- *
* @see SimpleDateFormat
*/
public static String formatDate(Date date, String pattern) {
- if (date == null) throw new IllegalArgumentException("date is null");
- if (pattern == null) throw new IllegalArgumentException("pattern is null");
+ if (date == null) {
+ throw new IllegalArgumentException("date is null");
+ }
+ if (pattern == null) {
+ throw new IllegalArgumentException("pattern is null");
+ }
SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
formatter.setTimeZone(GMT);
return formatter.format(date);
}
-
- /** This class should not be instantiated. */
- private DateUtil() { }
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/EncodingUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/EncodingUtil.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/EncodingUtil.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/EncodingUtil.java Sun Sep 16 17:25:07 2007
@@ -19,51 +19,56 @@
*/
package org.apache.ahc.util;
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-import org.apache.commons.codec.net.URLCodec;
-
import java.io.UnsupportedEncodingException;
+import org.apache.commons.codec.net.URLCodec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* The home for utility methods that handle various encoding tasks.
*
* @author Michael Becke
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
- *
* @since 2.0 final
*/
-public class EncodingUtil {
+public final class EncodingUtil {
- final static Logger LOG = LoggerFactory.getLogger(EncodingUtil.class);
+ static final Logger LOG = LoggerFactory.getLogger(EncodingUtil.class);
- /** Default content encoding chatset */
+ /**
+ * Default content encoding chatset
+ */
private static final String DEFAULT_CHARSET = "ISO-8859-1";
/**
+ * This class should not be instantiated.
+ */
+ private EncodingUtil() {
+ }
+
+ /**
* Form-urlencoding routine.
- *
+ * <p/>
* The default encoding for all forms is `application/x-www-form-urlencoded'.
* A form data set is represented in this media type as follows:
- *
+ * <p/>
* The form field names and values are escaped: space characters are replaced
* by `+', and then reserved characters are escaped as per [URL]; that is,
* non-alphanumeric characters are replaced by `%HH', a percent sign and two
* hexadecimal digits representing the ASCII code of the character. Line breaks,
* as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
- *
- * <p>
+ * <p/>
+ * <p/>
* if the given charset is not supported, ISO-8859-1 is used instead.
* </p>
*
- * @param pairs the values to be encoded
+ * @param pairs the values to be encoded
* @param charset the character set of pairs to be encoded
- *
* @return the urlencoded pairs
- *
* @since 2.0 final
*/
- public static String formUrlEncode(NameValuePair[] pairs, String charset) {
+ public static String formUrlEncode(NameValuePair[] pairs, String charset) {
try {
return doFormUrlEncode(pairs, charset);
} catch (UnsupportedEncodingException e) {
@@ -72,35 +77,32 @@
return doFormUrlEncode(pairs, DEFAULT_CHARSET);
} catch (UnsupportedEncodingException fatal) {
// Should never happen. ISO-8859-1 must be supported on all JVMs
- throw new AsyncHttpClientException("Encoding not supported: " +
- DEFAULT_CHARSET);
+ throw new AsyncHttpClientException("Encoding not supported: "
+ + DEFAULT_CHARSET);
}
}
}
/**
* Form-urlencoding routine.
- *
+ * <p/>
* The default encoding for all forms is `application/x-www-form-urlencoded'.
* A form data set is represented in this media type as follows:
- *
+ * <p/>
* The form field names and values are escaped: space characters are replaced
* by `+', and then reserved characters are escaped as per [URL]; that is,
* non-alphanumeric characters are replaced by `%HH', a percent sign and two
* hexadecimal digits representing the ASCII code of the character. Line breaks,
* as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
*
- * @param pairs the values to be encoded
+ * @param pairs the values to be encoded
* @param charset the character set of pairs to be encoded
- *
* @return the urlencoded pairs
* @throws UnsupportedEncodingException if charset is not supported
- *
* @since 2.0 final
*/
- private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
- throws UnsupportedEncodingException
- {
+ private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
+ throws UnsupportedEncodingException {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < pairs.length; i++) {
URLCodec codec = new URLCodec();
@@ -124,12 +126,11 @@
* the specified charset is not supported, default system encoding
* is used.
*
- * @param data the byte array to be encoded
- * @param offset the index of the first byte to encode
- * @param length the number of bytes to encode
+ * @param data the byte array to be encoded
+ * @param offset the index of the first byte to encode
+ * @param length the number of bytes to encode
* @param charset the desired character encoding
* @return The result of the conversion.
- *
* @since 3.0
*/
public static String getString(
@@ -164,10 +165,9 @@
* the specified charset is not supported, default system encoding
* is used.
*
- * @param data the byte array to be encoded
+ * @param data the byte array to be encoded
* @param charset the desired character encoding
* @return The result of the conversion.
- *
* @since 3.0
*/
public static String getString(final byte[] data, String charset) {
@@ -178,10 +178,9 @@
* Converts the specified string to a byte array. If the charset is not supported the
* default system charset is used.
*
- * @param data the string to be encoded
+ * @param data the string to be encoded
* @param charset the desired character encoding
* @return The resulting byte array.
- *
* @since 3.0
*/
public static byte[] getBytes(final String data, String charset) {
@@ -211,7 +210,6 @@
*
* @param data the string to be encoded
* @return The string as a byte array.
- *
* @since 3.0
*/
public static byte[] getAsciiBytes(final String data) {
@@ -232,11 +230,10 @@
* to be used when decoding content of HTTP elements (such as response
* headers)
*
- * @param data the byte array to be encoded
+ * @param data the byte array to be encoded
* @param offset the index of the first byte to encode
* @param length the number of bytes to encode
* @return The string representation of the byte array
- *
*/
public static String getAsciiString(final byte[] data, int offset, int length) {
@@ -258,17 +255,11 @@
*
* @param data the byte array to be encoded
* @return The string representation of the byte array
- *
*/
public static String getAsciiString(final byte[] data) {
return getAsciiString(data, 0, data.length);
}
- /**
- * This class should not be instantiated.
- */
- private EncodingUtil() {
- }
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/LangUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/LangUtils.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/LangUtils.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/LangUtils.java Sun Sep 16 17:25:07 2007
@@ -26,7 +26,7 @@
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*/
-public class LangUtils {
+public final class LangUtils {
public static final int HASH_SEED = 17;
public static final int HASH_OFFSET = 37;
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/NameValuePair.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/NameValuePair.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/NameValuePair.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/util/NameValuePair.java Sun Sep 16 17:25:07 2007
@@ -21,21 +21,29 @@
import java.io.Serializable;
-public class NameValuePair implements Serializable {
+public class NameValuePair implements Serializable {
+ /**
+ * Name.
+ */
+ private String name;
+
+ /**
+ * Value.
+ */
+ private String value;
- // ----------------------------------------------------------- Constructors
/**
* Default constructor.
- *
*/
public NameValuePair() {
- this (null, null);
+ this(null, null);
}
/**
* Constructor.
- * @param name The name.
+ *
+ * @param name The name.
* @param value The value.
*/
public NameValuePair(String name, String value) {
@@ -43,19 +51,6 @@
this.value = value;
}
- // ----------------------------------------------------- Instance Variables
-
- /**
- * Name.
- */
- private String name = null;
-
- /**
- * Value.
- */
- private String value = null;
-
- // ------------------------------------------------------------- Properties
/**
* Set the name.
@@ -102,19 +97,24 @@
/**
* Get a String representation of this pair.
+ *
* @return A string representation.
*/
public String toString() {
- return ("name=" + name + ", " + "value=" + value);
+ return "name=" + name + ", " + "value=" + value;
}
public boolean equals(final Object object) {
- if (object == null) return false;
- if (this == object) return true;
+ if (object == null) {
+ return false;
+ }
+ if (this == object) {
+ return true;
+ }
if (object instanceof NameValuePair) {
- NameValuePair that = (NameValuePair) object;
+ NameValuePair that = (NameValuePair)object;
return LangUtils.equals(this.name, that.name)
- && LangUtils.equals(this.value, that.value);
+ && LangUtils.equals(this.value, that.value);
} else {
return false;
}
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AbstractTest.java Sun Sep 16 17:25:07 2007
@@ -19,27 +19,28 @@
*/
package org.apache.ahc;
+import java.io.File;
+
import junit.framework.TestCase;
-import org.apache.catalina.startup.Embedded;
-import org.apache.catalina.connector.Connector;
+
+import org.apache.ahc.codec.HttpResponseMessage;
+import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
-import org.apache.catalina.Context;
+import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardHost;
-import org.apache.ahc.codec.HttpResponseMessage;
-
-import java.io.File;
+import org.apache.catalina.startup.Embedded;
public class AbstractTest extends TestCase {
- protected final File BASEDIR = getBaseDir();
- protected final File CATALINAHOME = new File(BASEDIR, "src/test/catalina");
- protected final File WORK = new File(BASEDIR, "target/work");
- protected final File KEYSTORE = new File(CATALINAHOME, "conf/keystore");
- protected final File WEBAPPS = new File(CATALINAHOME, "webapps");
- protected final File ROOT = new File(WEBAPPS, "ROOT");
+ protected static final File BASEDIR = getBaseDir();
+ protected static final File CATALINAHOME = new File(BASEDIR, "src/test/catalina");
+ protected static final File KEYSTORE = new File(CATALINAHOME, "conf/keystore");
+ protected static final File WEBAPPS = new File(CATALINAHOME, "webapps");
+ protected static final File ROOT = new File(WEBAPPS, "ROOT");
+ protected static Object semaphore = new Object();
+ protected static final File WORK = new File(BASEDIR, "target/work");
protected Embedded server;
- protected static final Object semaphore = new Object();
protected void setUp() throws Exception {
System.out.println("BASEDIR = " + BASEDIR.getAbsolutePath());
@@ -50,7 +51,7 @@
engine.setDefaultHost("localhost");
Host host = server.createHost("localhost", WEBAPPS.getAbsolutePath());
- ((StandardHost) host).setWorkDir(WORK.getAbsolutePath());
+ ((StandardHost)host).setWorkDir(WORK.getAbsolutePath());
engine.addChild(host);
Context context = server.createContext("", ROOT.getAbsolutePath());
@@ -72,11 +73,12 @@
protected void tearDown() throws Exception {
- if (server != null)
+ if (server != null) {
server.stop();
+ }
}
- protected final File getBaseDir() {
+ protected static final File getBaseDir() {
File dir;
// If ${basedir} is set, then honor it
@@ -85,7 +87,7 @@
dir = new File(tmp);
} else {
// Find the directory which this class (or really the sub-class of TestSupport) is defined in.
- String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
+ String path = AbstractTest.class.getProtectionDomain().getCodeSource().getLocation().getFile();
// We expect the file to be in target/test-classes, so go up 2 dirs
dir = new File(path).getParentFile().getParentFile();
@@ -97,20 +99,21 @@
return dir;
}
- class TestCallback implements AsyncHttpClientCallback {
+ class TestCallback implements AsyncHttpClientCallback {
+
+ private boolean timeout;
+ private boolean closed;
+ private boolean exception;
+ private Throwable throwable;
+ private HttpResponseMessage message;
- private boolean timeout = false;
- private boolean closed = false;
- private boolean exception = false;
- private Throwable throwable = null;
- private HttpResponseMessage message = null;
public TestCallback() {
clear();
}
- public void onResponse(HttpResponseMessage message) {
- this.message = message;
- synchronized(semaphore){
+ public void onResponse(HttpResponseMessage response) {
+ this.message = response;
+ synchronized (semaphore) {
semaphore.notify();
}
}
@@ -118,21 +121,21 @@
public void onException(Throwable cause) {
throwable = cause;
exception = true;
- synchronized(semaphore){
+ synchronized (semaphore) {
semaphore.notify();
}
}
public void onClosed() {
closed = true;
- synchronized(semaphore){
+ synchronized (semaphore) {
semaphore.notify();
}
}
public void onTimeout() {
timeout = true;
- synchronized(semaphore){
+ synchronized (semaphore) {
semaphore.notify();
}
}
@@ -141,7 +144,7 @@
return throwable;
}
- public void clear(){
+ public void clear() {
closed = false;
timeout = false;
exception = false;
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java Sun Sep 16 17:25:07 2007
@@ -19,20 +19,20 @@
*/
package org.apache.ahc;
-import org.apache.ahc.codec.HttpRequestMessage;
-import org.apache.ahc.codec.HttpResponseMessage;
-
-import java.net.URL;
import java.io.File;
import java.io.FileInputStream;
+import java.net.URL;
import java.util.Arrays;
+import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.codec.HttpResponseMessage;
+
public class AsyncHttpClientTest extends AbstractTest {
public void testHtmlConnection() throws Exception {
TestCallback callback = new TestCallback();
- doGetConnection(callback, "http://localhost:8282","/", false);
+ doGetConnection(callback, "http://localhost:8282", "/", false);
HttpResponseMessage msg = callback.getMessage();
assertEquals("\nHello World!", msg.getStringContent());
@@ -40,7 +40,7 @@
public void testSSLHtmlConnection() throws Exception {
TestCallback callback = new TestCallback();
- doGetConnection(callback, "https://localhost:8383","/", false);
+ doGetConnection(callback, "https://localhost:8383", "/", false);
HttpResponseMessage msg = callback.getMessage();
assertEquals("\nHello World!", msg.getStringContent());
@@ -53,13 +53,13 @@
FileInputStream fis = new FileInputStream(file);
byte realFile[] = new byte[(int)file.length()];
fis.read(realFile);
-
+
TestCallback callback = new TestCallback();
- doGetConnection(callback, "http://localhost:8282","/pwrd_apache.gif", false);
+ doGetConnection(callback, "http://localhost:8282", "/pwrd_apache.gif", false);
HttpResponseMessage msg = callback.getMessage();
- assertTrue(Arrays.equals(realFile,msg.getContent()));
+ assertTrue(Arrays.equals(realFile, msg.getContent()));
}
public void testSSLBinaryRequest() throws Exception {
@@ -71,16 +71,16 @@
fis.read(realFile);
TestCallback callback = new TestCallback();
- doGetConnection(callback, "https://localhost:8383","/pwrd_apache.gif", false);
+ doGetConnection(callback, "https://localhost:8383", "/pwrd_apache.gif", false);
HttpResponseMessage msg = callback.getMessage();
- assertTrue(Arrays.equals(realFile,msg.getContent()));
+ assertTrue(Arrays.equals(realFile, msg.getContent()));
}
public void testGetParameters() throws Exception {
TestCallback callback = new TestCallback();
- doGetConnection(callback, "http://localhost:8282","/params.jsp", false);
+ doGetConnection(callback, "http://localhost:8282", "/params.jsp", false);
HttpResponseMessage msg = callback.getMessage();
assertEquals("Test One Test Two", msg.getStringContent());
@@ -88,45 +88,49 @@
public void testPostParameters() throws Exception {
TestCallback callback = new TestCallback();
- doPostConnection(callback, "http://localhost:8282","/params.jsp", false);
+ doPostConnection(callback, "http://localhost:8282", "/params.jsp", false);
HttpResponseMessage msg = callback.getMessage();
assertEquals("Test One Test Two", msg.getStringContent());
}
- private void doGetConnection(TestCallback callback, String url, String uri, boolean testForException) throws Exception {
+ private void doGetConnection(TestCallback callback, String url, String uri, boolean testForException)
+ throws Exception {
HttpRequestMessage request = new HttpRequestMessage(uri);
- request.setParameter("TEST1","Test One");
- request.setParameter("TEST2","Test Two");
+ request.setParameter("TEST1", "Test One");
+ request.setParameter("TEST2", "Test Two");
doConnection(callback, url, request, false);
}
- private void doPostConnection(TestCallback callback, String url, String uri, boolean testForException) throws Exception {
+ private void doPostConnection(TestCallback callback, String url, String uri, boolean testForException)
+ throws Exception {
HttpRequestMessage request = new HttpRequestMessage(uri);
- request.setParameter("TEST1","Test One");
- request.setParameter("TEST2","Test Two");
+ request.setParameter("TEST1", "Test One");
+ request.setParameter("TEST2", "Test Two");
request.setRequestMethod(HttpRequestMessage.REQUEST_POST);
doConnection(callback, url, request, false);
}
- private void doConnection(TestCallback callback, String url, HttpRequestMessage request, boolean testForException) throws Exception {
- URL url_connect = new URL(url);
+ private void doConnection(TestCallback callback, String url, HttpRequestMessage request,
+ boolean testForException) throws Exception {
+ URL urlConnect = new URL(url);
- AsyncHttpClient ahc = new AsyncHttpClient(url_connect, callback);
+ AsyncHttpClient ahc = new AsyncHttpClient(urlConnect, callback);
ahc.connect();
ahc.sendRequest(request);
//We are done...Thread would normally end...
//So this little wait simulates the thread going back in the pool
- synchronized(semaphore){
+ synchronized (semaphore) {
//5 second timeout due to no response
semaphore.wait(5000);
}
- if (!testForException){
- if (callback.isException())
+ if (!testForException) {
+ if (callback.isException()) {
throw new Exception(callback.getThrowable());
+ }
}
}
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/ChunkedTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/ChunkedTest.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/ChunkedTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/ChunkedTest.java Sun Sep 16 17:25:07 2007
@@ -19,55 +19,56 @@
*/
package org.apache.ahc;
+import java.util.Arrays;
+
import junit.framework.TestCase;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
import org.apache.ahc.codec.HttpResponseDecoder;
import org.apache.ahc.codec.HttpResponseMessage;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
-import java.util.Arrays;
-
-public class ChunkedTest extends TestCase {
+public class ChunkedTest extends TestCase {
- private final static String fakeHttp =
- "HTTP/1.1 200 OK\r\n" +
- "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n" +
- "Content-Type: text/plain\r\n" +
- "Transfer-Encoding: chunked\r\n" +
- "\r\n" +
- "1a; ignore-stuff-here\r\n" +
- "abcdefghijklmnopqrstuvwxyz\r\n" +
- "10\r\n" +
- "1234567890abcdef\r\n" +
- "0\r\n" +
- "some-footer: some-value\r\n" +
- "another-footer: another-value\r\n\r\n";
-
-
- private final static String fakeHttpContinue =
- "HTTP/1.1 100 Continue\r\n" +
- "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n" +
- "Content-Type: text/plain\r\n" +
- "\r\n" + fakeHttp;
-
- public void testChunking() throws Exception{
- ByteBuffer buffer = ByteBuffer.allocate(fakeHttp.length());
- buffer.put(fakeHttp.getBytes());
+ private static final String FAKE_HTTP =
+ "HTTP/1.1 200 OK\r\n"
+ + "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "Transfer-Encoding: chunked\r\n"
+ + "\r\n"
+ + "1a; ignore-stuff-here\r\n"
+ + "abcdefghijklmnopqrstuvwxyz\r\n"
+ + "10\r\n"
+ + "1234567890abcdef\r\n"
+ + "0\r\n"
+ + "some-footer: some-value\r\n"
+ + "another-footer: another-value\r\n\r\n";
+
+
+ private static final String FAKE_HTTP_CONTINUE =
+ "HTTP/1.1 100 Continue\r\n"
+ + "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\n" + FAKE_HTTP;
+
+ public void testChunking() throws Exception {
+ ByteBuffer buffer = ByteBuffer.allocate(FAKE_HTTP.length());
+ buffer.put(FAKE_HTTP.getBytes());
buffer.flip();
IoSession session = new FakeIoSession();
HttpResponseDecoder decoder = new HttpResponseDecoder();
FakeProtocolDecoderOutput out = new FakeProtocolDecoderOutput();
decoder.decode(session, buffer, out);
-
- HttpResponseMessage response = (HttpResponseMessage) out.getObject();
- assertTrue(Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
+
+ HttpResponseMessage response = (HttpResponseMessage)out.getObject();
+ assertTrue(
+ Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
}
- public void testChunkingContinue() throws Exception{
- ByteBuffer buffer = ByteBuffer.allocate(fakeHttpContinue.length());
- buffer.put(fakeHttp.getBytes());
+ public void testChunkingContinue() throws Exception {
+ ByteBuffer buffer = ByteBuffer.allocate(FAKE_HTTP_CONTINUE.length());
+ buffer.put(FAKE_HTTP.getBytes());
buffer.flip();
IoSession session = new FakeIoSession();
@@ -75,8 +76,9 @@
FakeProtocolDecoderOutput out = new FakeProtocolDecoderOutput();
decoder.decode(session, buffer, out);
- HttpResponseMessage response = (HttpResponseMessage) out.getObject();
- assertTrue(Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
+ HttpResponseMessage response = (HttpResponseMessage)out.getObject();
+ assertTrue(
+ Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
}
}
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeIoSession.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeIoSession.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeIoSession.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeIoSession.java Sun Sep 16 17:25:07 2007
@@ -20,12 +20,22 @@
package org.apache.ahc;
-import org.apache.mina.common.*;
-
-import java.util.Set;
-import java.util.Map;
-import java.util.HashMap;
import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoServiceConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.TrafficMask;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
public class FakeIoSession implements IoSession {
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java Sun Sep 16 17:25:07 2007
@@ -24,10 +24,10 @@
public class FakeProtocolDecoderOutput implements ProtocolDecoderOutput {
- private Object object = null;
+ private Object object;
- public void write(Object object) {
- this.object = object;
+ public void write(Object obj) {
+ this.object = obj;
}
public void flush() {
Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java?rev=576224&r1=576223&r2=576224&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/TimeoutTest.java Sun Sep 16 17:25:07 2007
@@ -20,13 +20,13 @@
package org.apache.ahc;
-import org.apache.ahc.codec.HttpRequestMessage;
-
import java.net.URL;
+import org.apache.ahc.codec.HttpRequestMessage;
+
public class TimeoutTest extends AbstractTest {
- public void testTimeout() throws Exception{
+ public void testTimeout() throws Exception {
TestCallback callback = new TestCallback();
@@ -40,7 +40,7 @@
//We are done...Thread would normally end...
//So this little wait simulates the thread going back in the pool
- synchronized(semaphore){
+ synchronized (semaphore) {
//5 second timeout due to no response
semaphore.wait(5000);
}