Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<artifactId>jcip-annotations</artifactId> <artifactId>jcip-annotations</artifactId>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.6.3</version>
</dependency>
<dependency> <dependency>
<groupId>org.mortbay.jetty</groupId> <groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-embedded</artifactId> <artifactId>jetty-embedded</artifactId>
Expand All @@ -52,6 +47,11 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20090211</version> <version>20090211</version>
</dependency> </dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.6</version>
</dependency>
<dependency> <dependency>
<groupId>rhino</groupId> <groupId>rhino</groupId>
<artifactId>js</artifactId> <artifactId>js</artifactId>
Expand Down
64 changes: 55 additions & 9 deletions src/main/java/com/github/rnewson/couchdb/lucene/HC.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder; import java.nio.charset.CharsetDecoder;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;


import javax.net.ssl.SSLContext; 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.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;


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


public class HC { 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 static class MyConsumingNHttpEntity implements ConsumingNHttpEntity {


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


public void consumeContent() throws IOException { public void consumeContent() throws IOException {
} }
Expand All @@ -72,8 +104,20 @@ public void consumeContent(final ContentDecoder decoder,
buffer.flip(); buffer.flip();
final CharsetDecoder charsetDecoder = Charset.forName("US-ASCII") final CharsetDecoder charsetDecoder = Charset.forName("US-ASCII")
.newDecoder(); .newDecoder();
final CharBuffer charBuffer = charsetDecoder.decode(buffer); final String str = charsetDecoder.decode(buffer).toString();
System.out.println(charBuffer); 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 { 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) { public void connectionClosed(final NHttpConnection conn) {
System.out.println("Connection closed: " + 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; 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.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
params.setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1"); params.setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");


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


final HttpProcessor httpproc = new ImmutableHttpProcessor( final HttpProcessor httpproc = new ImmutableHttpProcessor(
new HttpRequestInterceptor[] { new RequestContent(), 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 // I/O event and main threads
final CountDownLatch requestCount = new CountDownLatch(1); final CountDownLatch requestCount = new CountDownLatch(1);


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


final SSLContext sslcontext; final SSLContext sslcontext;
if (ssl) { if (ssl) {
sslcontext = SSLContext.getInstance("TLS"); sslcontext = SSLContext.getInstance("TLS");
// TODO allow toggle between default trust and custom file.
sslcontext sslcontext
.init(null, new TrustManager[] { new BlindTrust() }, null); .init(null, new TrustManager[] { new BlindTrust() }, null);
} else { } else {
Expand All @@ -299,7 +345,7 @@ httpproc, new MyHttpRequestExecutionHandler(requestCount),
final IOEventDispatch ioEventDispatch; final IOEventDispatch ioEventDispatch;
if (ssl) { if (ssl) {
ioEventDispatch = new SSLClientIOEventDispatch(handler, sslcontext, ioEventDispatch = new SSLClientIOEventDispatch(handler, sslcontext,
params); new MySSLSetupHandler(), params);
} else { } else {
ioEventDispatch = new DefaultClientIOEventDispatch(handler, params); 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.