avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bru...@apache.org
Subject svn commit: r1074237 - in /avro/trunk: CHANGES.txt lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java lang/java/ipc/src/test/keystore lang/java/ipc/src/test/truststore
Date Thu, 24 Feb 2011 17:56:09 GMT
Author: brucem
Date: Thu Feb 24 17:56:08 2011
New Revision: 1074237

URL: http://svn.apache.org/viewvc?rev=1074237&view=rev
Log:
AVRO-701 + AVRO-772: Extensions to HttpServer to let you specify bind address as well as add
arbitrary Jetty connectors (useful for Avro HTTP RPC over SSL).

Added:
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java
    avro/trunk/lang/java/ipc/src/test/keystore
    avro/trunk/lang/java/ipc/src/test/truststore
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1074237&r1=1074236&r2=1074237&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Feb 24 17:56:08 2011
@@ -96,6 +96,9 @@ Avro 1.5.0 (unreleased)
 
     AVRO-711. JSON encoder and decoder for C++.
 
+    AVRO-701 and AVRO-772. Java: Add new constructors for HttpServer and an example
+    of using SSL for the HTTP RPC. (brucem)
+
   IMPROVEMENTS
 
     AVRO-771. Java: Update dependency versions

Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java?rev=1074237&r1=1074236&r2=1074237&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java (original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/HttpServer.java Thu Feb 24
17:56:08 2011
@@ -22,6 +22,8 @@ import java.io.IOException;
 
 import org.apache.avro.AvroRuntimeException;
 
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.nio.SelectChannelConnector;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
 
@@ -31,15 +33,51 @@ public class HttpServer implements Serve
 
   /** Constructs a server to run on the named port. */
   public HttpServer(Responder responder, int port) throws IOException {
-    this(new ResponderServlet(responder), port);
+    this(new ResponderServlet(responder), null, port);
   }
 
   /** Constructs a server to run on the named port. */
   public HttpServer(ResponderServlet servlet, int port) throws IOException {
-    this.server = new org.mortbay.jetty.Server(port);
+    this(servlet, null, port);
+  }
+
+  /** Constructs a server to run on the named port on the specified address. */
+  public HttpServer(Responder responder, String bindAddress, int port) throws IOException
{
+    this(new ResponderServlet(responder), bindAddress, port);
+  }
+
+  /** Constructs a server to run on the named port on the specified address. */
+  public HttpServer(ResponderServlet servlet, String bindAddress, int port) throws IOException
{
+    this.server = new org.mortbay.jetty.Server();
+    SelectChannelConnector connector = new SelectChannelConnector();
+    connector.setLowResourceMaxIdleTime(10000);
+    connector.setAcceptQueueSize(128);
+    connector.setResolveNames(false);
+    connector.setUseDirectBuffers(false);
+    if (bindAddress != null) {
+      connector.setHost(bindAddress);
+    }
+    connector.setPort(port);
+    server.addConnector(connector);
+    new Context(server, "/").addServlet(new ServletHolder(servlet), "/*");
+  }
+
+  /** Constructs a server to run with the given connector. */
+  public HttpServer(Responder responder, Connector connector) throws IOException {
+    this(new ResponderServlet(responder), connector);
+  }
+
+  /** Constructs a server to run with the given connector. */
+  public HttpServer(ResponderServlet servlet, Connector connector) throws IOException {
+    this.server = new org.mortbay.jetty.Server();
+    server.addConnector(connector);
     new Context(server, "/").addServlet(new ServletHolder(servlet), "/*");
   }
 
+  public void addConnector(Connector connector) {
+    server.addConnector(connector);
+  }
+
   @Override
   public int getPort() { return server.getConnectors()[0].getLocalPort(); }
 

Added: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java?rev=1074237&view=auto
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java (added)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolHttps.java Thu Feb
24 17:56:08 2011
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro;
+
+import org.apache.avro.Schema;
+import org.apache.avro.Schema.Field;
+import org.apache.avro.ipc.Server;
+import org.apache.avro.ipc.Transceiver;
+import org.apache.avro.ipc.Responder;
+import org.apache.avro.ipc.HttpServer;
+import org.apache.avro.ipc.HttpTransceiver;
+import org.apache.avro.ipc.generic.GenericRequestor;
+import org.apache.avro.ipc.specific.SpecificRequestor;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.test.Simple;
+
+import org.junit.Test;
+
+import org.mortbay.jetty.security.SslSocketConnector;
+
+import java.net.URL;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.ArrayList;
+
+public class TestProtocolHttps extends TestProtocolSpecific {
+
+  @Override
+  public Server createServer(Responder testResponder) throws Exception {
+    System.setProperty("javax.net.ssl.keyStore", "src/test/keystore");
+    System.setProperty("javax.net.ssl.keyStorePassword", "avrotest");
+    System.setProperty("javax.net.ssl.password", "avrotest");
+    System.setProperty("javax.net.ssl.trustStore", "src/test/truststore");
+    System.setProperty("javax.net.ssl.trustStorePassword", "avrotest");
+    SslSocketConnector connector = new SslSocketConnector();
+    connector.setPort(18443);
+    connector.setKeystore(System.getProperty("javax.net.ssl.keyStore"));
+    connector.setPassword(System.getProperty("javax.net.ssl.password"));
+    connector.setKeyPassword(System.getProperty("javax.net.ssl.keyStorePassword"));
+    connector.setHost("localhost");
+    connector.setNeedClientAuth(false);
+    return new HttpServer(testResponder, connector);
+  }
+  
+  @Override
+  public Transceiver createTransceiver() throws Exception{
+    return new HttpTransceiver(new URL("https://localhost:"+server.getPort()+"/"));
+  }
+ 
+  protected int getExpectedHandshakeCount() {
+    return REPEATING;
+  }
+
+}

Added: avro/trunk/lang/java/ipc/src/test/keystore
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/keystore?rev=1074237&view=auto
==============================================================================
Files avro/trunk/lang/java/ipc/src/test/keystore (added) and avro/trunk/lang/java/ipc/src/test/keystore
Thu Feb 24 17:56:08 2011 differ

Added: avro/trunk/lang/java/ipc/src/test/truststore
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/truststore?rev=1074237&view=auto
==============================================================================
Files avro/trunk/lang/java/ipc/src/test/truststore (added) and avro/trunk/lang/java/ipc/src/test/truststore
Thu Feb 24 17:56:08 2011 differ



Mime
View raw message