Author: jgenender
Date: Tue Sep 25 15:21:24 2007
New Revision: 579400
URL: http://svn.apache.org/viewvc?rev=579400&view=rev
Log:
More javadoc and remove unnecessary url usages
Modified:
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/AsyncHttpClient.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
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=579400&r1=579399&r2=579400&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 Tue
Sep 25 15:21:24 2007
@@ -190,7 +190,11 @@
this.request = request;
}
- /* (non-Javadoc)
+ /**
+ * Event notification that the conection has completed, either by a successful connection
or
+ * by an error.
+ *
+ * @param future the {@link org.apache.mina.common.IoFuture} representing the <code>ConnectFuture</code>.
* @see org.apache.mina.common.IoFutureListener#operationComplete(org.apache.mina.common.IoFuture)
*/
public void operationComplete(IoFuture future) {
@@ -218,7 +222,7 @@
sess.getFilterChain()
.addLast("protocolFilter", new ProtocolCodecFilter(
- new HttpProtocolCodecFactory(request.getUrl())));
+ new HttpProtocolCodecFactory()));
sess.setAttribute(HttpIoHandler.CURRENT_REQUEST, request);
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=579400&r1=579399&r2=579400&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
Tue Sep 25 15:21:24 2007
@@ -30,27 +30,55 @@
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
+/**
+ * The Class HttpIoHandler. Implements the MINA IoHandler interface as the primary
+ * event processor for the HTTP communication.
+ */
public class HttpIoHandler extends IoHandlerAdapter {
+ /** The Constant CURRENT_REQUEST. */
public static final String CURRENT_REQUEST = "CURRENT_REQUEST";
+
+ /** The Constant CURRENT_RESPONSE. */
public static final String CURRENT_RESPONSE = "CURRENT_RESPONSE";
+ /** The Constant DEFAULT_THREAD_POOL_SIZE. */
public static final int DEFAULT_THREAD_POOL_SIZE = 10;
+
+ /** The Constant CONNECTION_CLOSE. */
public static final String CONNECTION_CLOSE = "close";
+ /** The scheduler service to handle timeouts. */
private ScheduledExecutorService scheduler;
+ /**
+ * Instantiates a new HttpIoHandler.
+ */
public HttpIoHandler() {
scheduler = Executors.newSingleThreadScheduledExecutor();
}
+ /**
+ * Destroys the handler and shuts down the scheduler.
+ */
public void destroy(){
scheduler.shutdownNow();
}
+ /**
+ * Stub for handling sessionOpened events.
+ * @see org.apache.mina.common.IoHandlerAdapter#sessionOpened(org.apache.mina.common.IoSession)
+ */
public void sessionOpened(IoSession ioSession) throws Exception {
}
+ /**
+ * Handler for receiving a response from a remote server.
+ *
+ * @param ioSession the {@link org.apache.mina.common.IoSession} representing the connection
to the server.
+ * @param object the {@link HttpResponseMessage} object
+ * @see org.apache.mina.common.IoHandlerAdapter#messageReceived(org.apache.mina.common.IoSession,
java.lang.Object)
+ */
public void messageReceived(IoSession ioSession, Object object) throws Exception {
HttpResponseMessage response = (HttpResponseMessage)object;
@@ -84,6 +112,13 @@
ioSession.close();
}
+ /**
+ * Handler for receiving a notification that an Exception occurred in the communication
with the server
+ *
+ * @param ioSession the {@link org.apache.mina.common.IoSession} representing the connection
to the server.
+ * @param object the {@link java.lang.Throwable} object representing the exception that
occurred
+ * @see org.apache.mina.common.IoHandlerAdapter#exceptionCaught(org.apache.mina.common.IoSession,
java.lang.Throwable)
+ */
public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception
{
//Clean up if any in-proccess decoding was occurring
ioSession.removeAttribute(CURRENT_RESPONSE);
@@ -98,6 +133,12 @@
ioSession.close();
}
+ /**
+ * Handler for notifying that a connection was closed to the remote server.
+ *
+ * @param ioSession the {@link org.apache.mina.common.IoSession} representing the connection
to the server.
+ * @see org.apache.mina.common.IoHandlerAdapter#sessionClosed(org.apache.mina.common.IoSession)
+ */
public void sessionClosed(IoSession ioSession) throws Exception {
//Clean up if any in-proccess decoding was occurring
ioSession.removeAttribute(CURRENT_RESPONSE);
@@ -107,6 +148,14 @@
callback.onClosed();
}
+ /**
+ * Handler for notifying that a message was sent to a remote server. It is responsible
for setting up the
+ * timeout for a response from the remote server.
+ *
+ * @param ioSession the {@link org.apache.mina.common.IoSession} representing the connection
to the server.
+ * @param object the {@link HttpRequestMessage} object
+ * @see org.apache.mina.common.IoHandlerAdapter#messageSent(org.apache.mina.common.IoSession,
java.lang.Object)
+ */
public void messageSent(IoSession ioSession, Object object) throws Exception {
HttpRequestMessage msg = (HttpRequestMessage)object;
@@ -118,6 +167,11 @@
}
}
+ /**
+ * Utility function to cancel a request timeout task.
+ *
+ * @param request the {@link HttpRequestMessage} request
+ */
private void cancelTasks(HttpRequestMessage request){
ScheduledFuture handle = request.getTimeoutHandle();
if (handle != null){
@@ -131,14 +185,28 @@
}
}
+ /**
+ * The Class TimeoutTask. Subclass that encapsulates handler for timeouts for the scheduler.
+ */
class TimeoutTask implements Runnable {
+ /** The session object. */
private IoSession sess;
+ /**
+ * Instantiates a new timeout task.
+ *
+ * @param sess the {@link org.apache.mina.common.IoSession} representing the connection
to the server.
+ */
public TimeoutTask(IoSession sess) {
this.sess = sess;
}
+ /**
+ * The running task which handles timing out the connection.
+ *
+ * @see java.lang.Runnable#run()
+ */
public void run() {
HttpRequestMessage request = (HttpRequestMessage)sess.getAttribute(CURRENT_REQUEST);
AsyncHttpClientCallback callback = request.getCallback();
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=579400&r1=579399&r2=579400&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 Tue
Sep 25 15:21:24 2007
@@ -26,17 +26,38 @@
import org.apache.ahc.util.NameValuePair;
+/**
+ * The Class HttpMessage. The base class for {@link HttpRequestMessage} and {@link HttpResponseMessage}.
+ */
public class HttpMessage {
+ /** The Constant CONTENT_TYPE. */
public static final String CONTENT_TYPE = "Content-Type";
+
+ /** The Constant CONTENT_LENGTH. */
public static final String CONTENT_LENGTH = "Content-Length";
+ /** The headers associated with the message. */
protected List<NameValuePair> headers = new ArrayList<NameValuePair>();
+
+ /** The cookies associated with the message. */
protected List<Cookie> cookies = new ArrayList<Cookie>();
+
+ /** The content type. */
protected String contentType;
+
+ /** The content length. */
protected int contentLength;
+
+ /** The content container. */
protected ByteArrayOutputStream content;
+ /**
+ * Gets the <code>String</code> content. This method should only be
+ * used if the content is certain to be of type html or text as determined by the {@link
#getContentType}.
+ *
+ * @return the <code>String</code> content or <code>null</code>
if there is no content.
+ */
public String getStringContent() {
if (content == null) {
return null;
@@ -45,6 +66,11 @@
return new String(content.toByteArray());
}
+ /**
+ * Gets the content as a <code>byte[]</code> array.
+ *
+ * @return the <code>byte[]</code> content or <code>null</code>
if there is no content.
+ */
public byte[] getContent() {
if (content == null) {
return null;
@@ -53,6 +79,13 @@
return content.toByteArray();
}
+ /**
+ * Appends <code>byte[]</code> to the content.
+ *
+ * @param byteContent the byte content
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
public void addContent(byte[] byteContent) throws IOException {
if (this.content == null) {
this.content = new ByteArrayOutputStream();
@@ -61,47 +94,104 @@
this.content.write(byteContent);
}
+ /**
+ * Gets the cookies.
+ *
+ * @return the cookies
+ */
public List<Cookie> getCookies() {
return cookies;
}
+ /**
+ * Sets the cookies.
+ *
+ * @param cookies the new cookies
+ */
public void setCookies(List<Cookie> cookies) {
this.cookies = cookies;
}
+ /**
+ * Adds a cookie to the {@link Cookie} list.
+ *
+ * @param cookie the cookie
+ */
public void addCookie(Cookie cookie) {
this.cookies.add(cookie);
}
+ /**
+ * Gets the headers.
+ *
+ * @return the headers
+ */
public List<NameValuePair> getHeaders() {
return headers;
}
+ /**
+ * Sets the headers.
+ *
+ * @param headers the new headers
+ */
public void setHeaders(List<NameValuePair> headers) {
this.headers = headers;
}
+ /**
+ * Adds a header to the {@link org.apache.ahc.util.NameValuePair} header list.
+ *
+ * @param header the header
+ */
public void addHeader(NameValuePair header) {
headers.add(header);
}
+ /**
+ * Adds the header as a <code>String</code> name/value pair to the
+ * {@link org.apache.ahc.util.NameValuePair} header list.
+ *
+ * @param name the name
+ * @param value the value
+ */
public void addHeader(String name, String value) {
headers.add(new NameValuePair(name, value));
}
+ /**
+ * Gets the content type.
+ *
+ * @return the content type
+ */
public String getContentType() {
return contentType;
}
+ /**
+ * Sets the content type.
+ *
+ * @param contentType the new content type
+ */
public void setContentType(String contentType) {
this.contentType = contentType;
}
+ /**
+ * Gets the content length.
+ *
+ * @return the content length
+ */
public int getContentLength() {
return contentLength;
}
+ /**
+ * Sets the content length.
+ *
+ * @param contentLength the new content length
+ */
public void setContentLength(int contentLength) {
this.contentLength = contentLength;
}
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=579400&r1=579399&r2=579400&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
Tue Sep 25 15:21:24 2007
@@ -19,27 +19,43 @@
*/
package org.apache.ahc.codec;
-
-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;
+/**
+ * A factory for creating {@link HttpRequestEncoder} and {@link HttpResponseDecoder} objects.
+ */
public class HttpProtocolCodecFactory implements ProtocolCodecFactory {
+ /** The encoder. */
private final ProtocolEncoder encoder;
+
+ /** The decoder. */
private final ProtocolDecoder decoder;
- public HttpProtocolCodecFactory(final URL url) {
- encoder = new HttpRequestEncoder(url);
+ /**
+ * Instantiates a new HttpProtocolCodecFactory.
+ */
+ public HttpProtocolCodecFactory() {
+ encoder = new HttpRequestEncoder();
decoder = new HttpResponseDecoder();
}
+ /**
+ * Returns the {@link org.apache.mina.filter.codec.ProtocolEncoder} encoder.
+ *
+ * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder()
+ */
public ProtocolEncoder getEncoder() throws Exception {
return encoder;
}
+ /**
+ * Returns the {@link org.apache.mina.filter.codec.ProtocolDecoder} encoder.
+ *
+ * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder()
+ */
public ProtocolDecoder getDecoder() throws Exception {
return decoder;
}
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=579400&r1=579399&r2=579400&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
Tue Sep 25 15:21:24 2007
@@ -40,7 +40,6 @@
private static final Set TYPES;
private static final byte[] CRLF = new byte[] {0x0D, 0x0A};
private static final String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
- private URL url;
static {
Set types = new HashSet();
@@ -48,8 +47,7 @@
TYPES = Collections.unmodifiableSet(types);
}
- public HttpRequestEncoder(URL url) {
- this.url = url;
+ public HttpRequestEncoder() {
}
public Set<Class<?>> getMessageTypes() {
@@ -97,11 +95,11 @@
//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)) {
+ buf.putString(msg.getHost(), encoder);
+ if ((msg.getProtocol().equals("http") && msg.getPort() != 80)
+ || (msg.getProtocol().equals("https") && msg.getPort() != 443)) {
buf.putString(":", encoder);
- buf.putString(url.getPort() + "", encoder);
+ buf.putString(msg.getPort() + "", encoder);
}
buf.put(CRLF);
|