Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Apr 19, 2011
1 parent 41b59d1 commit 342c7cc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 210 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Expand Up @@ -27,11 +27,6 @@
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-embedded</artifactId>
Expand All @@ -52,6 +47,11 @@
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
Expand Down
64 changes: 55 additions & 9 deletions src/main/java/com/github/rnewson/couchdb/lucene/HC.java
Expand Up @@ -6,14 +6,18 @@
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

Expand All @@ -27,6 +31,7 @@
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.nio.DefaultClientIOEventDispatch;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.SSLSetupHandler;
import org.apache.http.impl.nio.ssl.SSLClientIOEventDispatch;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.nio.ContentDecoder;
Expand All @@ -39,6 +44,7 @@
import org.apache.http.nio.protocol.NHttpRequestExecutionHandler;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionRequest;
import org.apache.http.nio.reactor.SessionRequestCallback;
import org.apache.http.params.CoreConnectionPNames;
Expand All @@ -55,12 +61,38 @@
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.map.ObjectMapper;

public class HC {

private static class MySSLSetupHandler implements SSLSetupHandler {

public void initalize(SSLEngine sslengine, HttpParams params)
throws SSLException {
System.err.println(Arrays.toString(sslengine
.getEnabledCipherSuites()));

// TODO make configurable in ini file
sslengine.setEnabledProtocols(new String[] { "TLSv1" });

// TODO make configurable in ini file
sslengine.setEnabledCipherSuites(new String[] {
"TLS_RSA_WITH_AES_256_CBC_SHA",
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA" });
}

public void verify(IOSession iosession, SSLSession sslsession)
throws SSLException {
}

}

private static class MyConsumingNHttpEntity implements ConsumingNHttpEntity {

private final ByteBuffer buffer = ByteBuffer.allocate(4096);
private final ObjectMapper mapper = new ObjectMapper();
private String remainder = "";

public void consumeContent() throws IOException {
}
Expand All @@ -72,8 +104,20 @@ public void consumeContent(final ContentDecoder decoder,
buffer.flip();
final CharsetDecoder charsetDecoder = Charset.forName("US-ASCII")
.newDecoder();
final CharBuffer charBuffer = charsetDecoder.decode(buffer);
System.out.println(charBuffer);
final String str = charsetDecoder.decode(buffer).toString();
final String[] changes = str.split("\n");
for (int i = 0, len = changes.length - 1; i < len; i++) {
final String line = i == 0 ? remainder + changes[i]
: changes[i];
if (line.startsWith("{") && line.endsWith("}")) {
System.out.print("valid : ");
} else {
System.out.print("invalid: ");
}
System.out.println(line);
}
remainder = changes[changes.length-1];

}

public void finish() throws IOException {
Expand Down Expand Up @@ -120,7 +164,7 @@ public void writeTo(final OutputStream outstream) throws IOException {

}

static class EventLogger implements EventListener {
private static class EventLogger implements EventListener {

public void connectionClosed(final NHttpConnection conn) {
System.out.println("Connection closed: " + conn);
Expand Down Expand Up @@ -226,7 +270,8 @@ public HttpRequest submitRequest(final HttpContext context) {

}

static class MySessionRequestCallback implements SessionRequestCallback {
private static class MySessionRequestCallback implements
SessionRequestCallback {

private final CountDownLatch requestCount;

Expand Down Expand Up @@ -269,8 +314,8 @@ public static void main(final String[] args) throws Exception {
params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
params.setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");

final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(2,
params);
final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
Runtime.getRuntime().availableProcessors(), params);

final HttpProcessor httpproc = new ImmutableHttpProcessor(
new HttpRequestInterceptor[] { new RequestContent(),
Expand All @@ -281,11 +326,12 @@ public static void main(final String[] args) throws Exception {
// I/O event and main threads
final CountDownLatch requestCount = new CountDownLatch(1);

final boolean ssl = true;
final boolean ssl = false;

final SSLContext sslcontext;
if (ssl) {
sslcontext = SSLContext.getInstance("TLS");
// TODO allow toggle between default trust and custom file.
sslcontext
.init(null, new TrustManager[] { new BlindTrust() }, null);
} else {
Expand All @@ -299,7 +345,7 @@ httpproc, new MyHttpRequestExecutionHandler(requestCount),
final IOEventDispatch ioEventDispatch;
if (ssl) {
ioEventDispatch = new SSLClientIOEventDispatch(handler, sslcontext,
params);
new MySSLSetupHandler(), params);
} else {
ioEventDispatch = new DefaultClientIOEventDispatch(handler, params);
}
Expand Down
75 changes: 0 additions & 75 deletions src/main/java/com/github/rnewson/couchdb/lucene/Ning.java

This file was deleted.

121 changes: 0 additions & 121 deletions src/main/java/com/github/rnewson/couchdb/lucene/SSLNio.java

This file was deleted.

0 comments on commit 342c7cc

Please sign in to comment.