Author: mwebb
Date: Fri Sep 14 08:09:49 2007
New Revision: 575715
URL: http://svn.apache.org/viewvc?rev=575715&view=rev
Log:
Updated the code to match the MINA coding style conventions
Modified:
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClient.java
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClientCallback.java
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/HttpIoHandler.java
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/SimpleTrustManagerFactory.java
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AbstractTest.java
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AsyncHttpClientTest.java
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/ChunkedTest.java
Modified:
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClient.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClient.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClient.java
(original)
+++
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClient.java
Fri Sep 14 08:09:49 2007
@@ -19,7 +19,6 @@
*/
package org.apache.mina.protocol.http.client;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URL;
@@ -35,119 +34,98 @@
import org.apache.mina.filter.ssl.SSLFilter;
import org.apache.mina.transport.socket.nio.SocketConnector;
-
-public class AsyncHttpClient
-{
+public class AsyncHttpClient {
public static int DEFAULT_CONNECTION_TIMEOUT = 30;
+
public static String DEFAULT_SSL_PROTOCOL = "TLS";
private URL url;
+
private boolean followRedirects = true;
+
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
+
private String sslProtocol = DEFAULT_SSL_PROTOCOL;
+
private IoSession session;
- private AsyncHttpClientCallback callback;
+ private AsyncHttpClientCallback callback;
- public AsyncHttpClient( URL url, AsyncHttpClientCallback callback )
- {
+ public AsyncHttpClient(URL url, AsyncHttpClientCallback callback) {
this.url = url;
this.callback = callback;
}
-
- public void connect() throws Exception
- {
+ public void connect() throws Exception {
SocketConnector connector = new SocketConnector();
- connector.setConnectTimeout( connectionTimeout );
+ connector.setConnectTimeout(connectionTimeout);
String scheme = url.getProtocol();
int port = url.getPort();
- if ( scheme.toLowerCase().equals( "https" ) )
- {
- SSLFilter filter = new SSLFilter( createClientSSLContext() );
- filter.setUseClientMode( true );
- connector.getFilterChain().addLast( "SSL", filter );
- if ( port == -1 )
- {
+ if (scheme.toLowerCase().equals("https")) {
+ SSLFilter filter = new SSLFilter(createClientSSLContext());
+ filter.setUseClientMode(true);
+ connector.getFilterChain().addLast("SSL", filter);
+ if (port == -1) {
port = 443;
}
}
- if ( scheme.toLowerCase().equals( "http" ) && ( port == -1 ) )
- {
+ if (scheme.toLowerCase().equals("http") && (port == -1)) {
port = 80;
}
- connector.getFilterChain().addLast( "protocolFilter", new
ProtocolCodecFilter( new HttpProtocolCodecFactory( url ) ) );
- connector.setHandler( new HttpIoHandler(callback) );
- ConnectFuture future = connector.connect( new InetSocketAddress(
url.getHost(), port ) );
+ connector.getFilterChain().addLast("protocolFilter",
+ new ProtocolCodecFilter(new HttpProtocolCodecFactory(url)));
+ connector.setHandler(new HttpIoHandler(callback));
+ ConnectFuture future = connector.connect(new InetSocketAddress(url
+ .getHost(), port));
future.awaitUninterruptibly();
- if ( !future.isConnected() )
- {
- throw new IOException( "Cannot connect to " + url.toString() );
+ if (!future.isConnected()) {
+ throw new IOException("Cannot connect to " + url.toString());
}
session = future.getSession();
}
-
- public void disconnect()
- {
- if ( session != null && session.isConnected() )
- {
+ public void disconnect() {
+ if (session != null && session.isConnected()) {
session.close();
}
session = null;
}
-
- public void sendRequest( HttpRequestMessage message )
- {
- session.write( message );
+ public void sendRequest(HttpRequestMessage message) {
+ session.write(message);
}
-
- public int getConnectionTimeout()
- {
+ public int getConnectionTimeout() {
return connectionTimeout;
}
-
- public void setConnectionTimeout( int connectionTimeout )
- {
+ public void setConnectionTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
-
- public boolean isFollowRedirects()
- {
+ public boolean isFollowRedirects() {
return followRedirects;
}
-
- public void setFollowRedirects( boolean followRedirects )
- {
+ public void setFollowRedirects(boolean followRedirects) {
this.followRedirects = followRedirects;
}
-
- public String getSslProtocol()
- {
+ public String getSslProtocol() {
return sslProtocol;
}
-
- public void setSslProtocol( String sslProtocol )
- {
+ public void setSslProtocol(String sslProtocol) {
this.sslProtocol = sslProtocol;
}
-
- private SSLContext createClientSSLContext() throws GeneralSecurityException
- {
- SSLContext context = SSLContext.getInstance( sslProtocol );
- context.init( null, SimpleTrustManagerFactory.X509_MANAGERS, null );
+ private SSLContext createClientSSLContext() throws
GeneralSecurityException {
+ SSLContext context = SSLContext.getInstance(sslProtocol);
+ context.init(null, SimpleTrustManagerFactory.X509_MANAGERS, null);
return context;
}
Modified:
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClientCallback.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClientCallback.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClientCallback.java
(original)
+++
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/AsyncHttpClientCallback.java
Fri Sep 14 08:09:49 2007
@@ -19,17 +19,12 @@
*/
package org.apache.mina.protocol.http.client;
-
import org.apache.mina.filter.codec.http.HttpResponseMessage;
+public interface AsyncHttpClientCallback {
+ public void onResponse(HttpResponseMessage message);
-public interface AsyncHttpClientCallback
-{
- public void onResponse( HttpResponseMessage message );
-
-
- public void onException( Throwable cause );
-
+ public void onException(Throwable cause);
public void onClosed();
}
Modified:
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/HttpIoHandler.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/HttpIoHandler.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/HttpIoHandler.java
(original)
+++
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/HttpIoHandler.java
Fri Sep 14 08:09:49 2007
@@ -19,53 +19,42 @@
*/
package org.apache.mina.protocol.http.client;
-
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.http.HttpResponseDecoder;
import org.apache.mina.filter.codec.http.HttpResponseMessage;
-
-public class HttpIoHandler extends IoHandlerAdapter
-{
+public class HttpIoHandler extends IoHandlerAdapter {
private AsyncHttpClientCallback callback;
-
- public HttpIoHandler( AsyncHttpClientCallback callback )
- {
+ public HttpIoHandler(AsyncHttpClientCallback callback) {
this.callback = callback;
}
-
@Override
- public void sessionOpened( IoSession ioSession ) throws Exception
- {
- super.sessionOpened( ioSession );
+ public void sessionOpened(IoSession ioSession) throws Exception {
+ super.sessionOpened(ioSession);
}
-
@Override
- public void messageReceived( IoSession ioSession, Object object ) throws
Exception
- {
- HttpResponseMessage message = ( HttpResponseMessage ) object;
- callback.onResponse( message );
+ public void messageReceived(IoSession ioSession, Object object)
+ throws Exception {
+ HttpResponseMessage message = (HttpResponseMessage) object;
+ callback.onResponse(message);
}
-
@Override
- public void exceptionCaught( IoSession ioSession, Throwable throwable )
throws Exception
- {
+ public void exceptionCaught(IoSession ioSession, Throwable throwable)
+ throws Exception {
//Clean up if any in-proccess decoding was occurring
- ioSession.removeAttribute( HttpResponseDecoder.CURRENT_RESPONSE );
- callback.onException( throwable );
+ ioSession.removeAttribute(HttpResponseDecoder.CURRENT_RESPONSE);
+ callback.onException(throwable);
}
-
@Override
- public void sessionClosed( IoSession ioSession ) throws Exception
- {
+ public void sessionClosed(IoSession ioSession) throws Exception {
//Clean up if any in-proccess decoding was occurring
- ioSession.removeAttribute( HttpResponseDecoder.CURRENT_RESPONSE );
+ ioSession.removeAttribute(HttpResponseDecoder.CURRENT_RESPONSE);
callback.onClosed();
}
}
Modified:
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/SimpleTrustManagerFactory.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/SimpleTrustManagerFactory.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/SimpleTrustManagerFactory.java
(original)
+++
mina/trunk/protocol-http-client/src/main/java/org/apache/mina/protocol/http/client/SimpleTrustManagerFactory.java
Fri Sep 14 08:09:49 2007
@@ -32,17 +32,16 @@
public class SimpleTrustManagerFactory extends TrustManagerFactorySpi {
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 {
}
-
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
@@ -51,13 +50,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:
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AbstractTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AbstractTest.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AbstractTest.java
(original)
+++
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AbstractTest.java
Fri Sep 14 08:09:49 2007
@@ -19,7 +19,6 @@
*/
package org.apache.mina.protocol.http.client;
-
import java.io.File;
import junit.framework.TestCase;
@@ -31,77 +30,74 @@
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.startup.Embedded;
-
-public abstract class AbstractTest extends TestCase
-{
+public abstract 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 Embedded server;
+ 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 void setUp() throws Exception
- {
- System.out.println( "BASEDIR = " + BASEDIR.getAbsolutePath() );
+ protected final File ROOT = new File(WEBAPPS, "ROOT");
+
+ protected Embedded server;
+
+ protected void setUp() throws Exception {
+ System.out.println("BASEDIR = " + BASEDIR.getAbsolutePath());
server = new Embedded();
- server.setCatalinaHome( CATALINAHOME.getAbsolutePath() );
+ server.setCatalinaHome(CATALINAHOME.getAbsolutePath());
Engine engine = server.createEngine();
- engine.setDefaultHost( "localhost" );
+ engine.setDefaultHost("localhost");
- Host host = server.createHost( "localhost", WEBAPPS.getAbsolutePath()
);
- ( ( StandardHost ) host ).setWorkDir( WORK.getAbsolutePath() );
- engine.addChild( host );
+ Host host = server.createHost("localhost", WEBAPPS.getAbsolutePath());
+ ((StandardHost) host).setWorkDir(WORK.getAbsolutePath());
+ engine.addChild(host);
+
+ Context context = server.createContext("", ROOT.getAbsolutePath());
+ context.setParentClassLoader(Thread.currentThread()
+ .getContextClassLoader());
+ host.addChild(context);
- Context context = server.createContext( "", ROOT.getAbsolutePath() );
- context.setParentClassLoader(
Thread.currentThread().getContextClassLoader() );
- host.addChild( context );
-
- server.addEngine( engine );
+ server.addEngine(engine);
//Http
- Connector http = server.createConnector( "localhost", 8282, false );
- server.addConnector( http );
+ Connector http = server.createConnector("localhost", 8282, false);
+ server.addConnector(http);
//Https
- Connector https = server.createConnector( "localhost", 8383, true );
- https.setAttribute( "keystoreFile", KEYSTORE.getAbsolutePath() );
- server.addConnector( https );
+ Connector https = server.createConnector("localhost", 8383, true);
+ https.setAttribute("keystoreFile", KEYSTORE.getAbsolutePath());
+ server.addConnector(https);
server.start();
}
-
- protected void tearDown() throws Exception
- {
- if ( server != null )
+ protected void tearDown() throws Exception {
+ if (server != null)
server.stop();
}
-
- protected final File getBaseDir()
- {
+ protected final File getBaseDir() {
File dir;
// If ${basedir} is set, then honor it
- String tmp = System.getProperty( "basedir" );
- if ( tmp != null )
- {
- dir = new File( tmp );
- }
- else
- {
+ String tmp = System.getProperty("basedir");
+ if (tmp != null) {
+ 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 = getClass().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();
+ dir = new File(path).getParentFile().getParentFile();
// Set ${basedir} which is needed by logging to initialize
- System.setProperty( "basedir", dir.getPath() );
+ System.setProperty("basedir", dir.getPath());
}
return dir;
Modified:
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AsyncHttpClientTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AsyncHttpClientTest.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AsyncHttpClientTest.java
(original)
+++
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/AsyncHttpClientTest.java
Fri Sep 14 08:09:49 2007
@@ -19,7 +19,6 @@
*/
package org.apache.mina.protocol.http.client;
-
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
@@ -30,228 +29,185 @@
import org.apache.mina.protocol.http.client.AsyncHttpClient;
import org.apache.mina.protocol.http.client.AsyncHttpClientCallback;
-
-public class AsyncHttpClientTest extends AbstractTest
-{
+public class AsyncHttpClientTest extends AbstractTest {
protected static final Object semaphore = new Object();
-
- public void testHtmlConnection() throws Exception
- {
+ 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() );
+ assertEquals("\nHello World!", msg.getStringContent());
}
-
- public void testSSLHtmlConnection() throws Exception
- {
+ 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() );
+ assertEquals("\nHello World!", msg.getStringContent());
}
-
- public void testBinaryRequest() throws Exception
- {
+ public void testBinaryRequest() throws Exception {
//Get the real file
- File file = new File( ROOT, "pwrd_apache.gif" );
- FileInputStream fis = new FileInputStream( file );
- byte realFile[] = new byte[( int ) file.length()];
- fis.read( realFile );
+ File file = new File(ROOT, "pwrd_apache.gif");
+ 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
- {
+ public void testSSLBinaryRequest() throws Exception {
//Get the real file
- File file = new File( ROOT, "pwrd_apache.gif" );
- FileInputStream fis = new FileInputStream( file );
- byte realFile[] = new byte[( int ) file.length()];
- fis.read( realFile );
+ File file = new File(ROOT, "pwrd_apache.gif");
+ FileInputStream fis = new FileInputStream(file);
+ byte realFile[] = new byte[(int) file.length()];
+ 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
- {
+ 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() );
+ assertEquals("Test One Test Two", msg.getStringContent());
}
-
- public void testPostParameters() throws Exception
- {
+ 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() );
+ assertEquals("Test One Test Two", msg.getStringContent());
}
-
- 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" );
- doConnection( callback, url, request, testForException );
+ 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");
+ doConnection(callback, url, request, testForException);
}
-
- 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.setRequestMethod( HttpRequestMessage.REQUEST_POST );
- doConnection( callback, url, request, testForException );
+ 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.setRequestMethod(HttpRequestMessage.REQUEST_POST);
+ doConnection(callback, url, request, testForException);
}
+ 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 url_connect = new URL( url );
-
- AsyncHttpClient ahc = new AsyncHttpClient( url_connect, callback );
+ AsyncHttpClient ahc = new AsyncHttpClient(url_connect, callback);
ahc.connect();
- ahc.sendRequest( request );
+ 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 );
+ semaphore.wait(5000);
}
- if ( !testForException )
- {
- if ( callback.isException() )
- throw new Exception( callback.getThrowable() );
+ if (!testForException) {
+ if (callback.isException())
+ throw new Exception(callback.getThrowable());
}
}
- class TestCallback implements AsyncHttpClientCallback
- {
+ class TestCallback implements AsyncHttpClientCallback {
private boolean closed = false;
+
private boolean exception = false;
+
private Throwable throwable = null;
- private HttpResponseMessage message = null;
+ private HttpResponseMessage message = null;
- public TestCallback()
- {
+ public TestCallback() {
clear();
}
-
- public void onResponse( HttpResponseMessage message )
- {
+ public void onResponse(HttpResponseMessage message) {
this.message = message;
- synchronized ( semaphore )
- {
+ synchronized (semaphore) {
semaphore.notify();
}
}
-
- public void onException( Throwable cause )
- {
+ public void onException(Throwable cause) {
throwable = cause;
exception = true;
- synchronized ( semaphore )
- {
+ synchronized (semaphore) {
semaphore.notify();
}
}
-
- public void onClosed()
- {
+ public void onClosed() {
closed = true;
- synchronized ( semaphore )
- {
+ synchronized (semaphore) {
semaphore.notify();
}
}
-
- public Throwable getThrowable()
- {
+ public Throwable getThrowable() {
return throwable;
}
-
- public void clear()
- {
+ public void clear() {
closed = false;
exception = false;
message = null;
}
-
- public boolean isClosed()
- {
+ public boolean isClosed() {
return closed;
}
-
- public void setClosed( boolean closed )
- {
+ public void setClosed(boolean closed) {
this.closed = closed;
}
-
- public boolean isException()
- {
+ public boolean isException() {
return exception;
}
-
- public void setException( boolean exception )
- {
+ public void setException(boolean exception) {
this.exception = exception;
}
-
- public HttpResponseMessage getMessage()
- {
+ public HttpResponseMessage getMessage() {
return message;
}
-
- public void setMessage( HttpResponseMessage message )
- {
+ public void setMessage(HttpResponseMessage message) {
this.message = message;
}
}
Modified:
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/ChunkedTest.java
URL:
http://svn.apache.org/viewvc/mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/ChunkedTest.java?rev=575715&r1=575714&r2=575715&view=diff
==============================================================================
---
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/ChunkedTest.java
(original)
+++
mina/trunk/protocol-http-client/src/test/java/org/apache/mina/protocol/http/client/ChunkedTest.java
Fri Sep 14 08:09:49 2007
@@ -19,7 +19,6 @@
*/
package org.apache.mina.protocol.http.client;
-
import java.util.Arrays;
import junit.framework.TestCase;
@@ -29,46 +28,48 @@
import org.apache.mina.filter.codec.http.HttpResponseDecoder;
import org.apache.mina.filter.codec.http.HttpResponseMessage;
+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 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;
+ + "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() );
+ public void testChunking() throws Exception {
+ ByteBuffer buffer = ByteBuffer.allocate(fakeHttp.length());
+ buffer.put(fakeHttp.getBytes());
buffer.flip();
ProtocolCodecSession session = new ProtocolCodecSession();
HttpResponseDecoder decoder = new HttpResponseDecoder();
- decoder.decode( session, buffer, session.getDecoderOutput() );
+ decoder.decode(session, buffer, session.getDecoderOutput());
- HttpResponseMessage response = (HttpResponseMessage)
session.getDecoderOutputQueue().poll();
- assertTrue( Arrays.equals( response.getContent(),
"abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes() ) );
+ HttpResponseMessage response = (HttpResponseMessage) session
+ .getDecoderOutputQueue().poll();
+ 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(fakeHttpContinue.length());
+ buffer.put(fakeHttp.getBytes());
buffer.flip();
ProtocolCodecSession session = new ProtocolCodecSession();
HttpResponseDecoder decoder = new HttpResponseDecoder();
- decoder.decode( session, buffer, session.getDecoderOutput() );
+ decoder.decode(session, buffer, session.getDecoderOutput());
- HttpResponseMessage response = (HttpResponseMessage)
session.getDecoderOutputQueue().poll();
- assertTrue( Arrays.equals( response.getContent(),
"abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes() ) );
+ HttpResponseMessage response = (HttpResponseMessage) session
+ .getDecoderOutputQueue().poll();
+ assertTrue(Arrays.equals(response.getContent(),
+ "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
}
}