HTTP: Rest API should support receiving HTTP. Closes #8.

This commit is contained in:
kimchy 2010-02-13 23:44:37 +02:00
parent 14f2445e2a
commit 5ac51ee93f
2 changed files with 13 additions and 24 deletions

View File

@ -24,6 +24,7 @@ import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.http.*;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.BindTransportException;
import org.elasticsearch.util.SizeUnit;
import org.elasticsearch.util.SizeValue;
import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.component.AbstractComponent;
@ -36,6 +37,7 @@ import org.elasticsearch.util.transport.PortsRange;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.timeout.ReadTimeoutException;
@ -73,6 +75,8 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
private final ThreadPool threadPool;
private final SizeValue maxContentLength;
private final int workerCount;
private final String port;
@ -108,6 +112,7 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
@Inject public NettyHttpServerTransport(Settings settings, ThreadPool threadPool) {
super(settings);
this.threadPool = threadPool;
SizeValue maxContentLength = componentSettings.getAsSize("maxContentLength", new SizeValue(100, SizeUnit.MB));
this.workerCount = componentSettings.getAsInt("workerCount", Runtime.getRuntime().availableProcessors());
this.port = componentSettings.get("port", "9200-9300");
this.bindHost = componentSettings.get("bindHost");
@ -123,6 +128,13 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
if ((httpKeepAliveTickDuration.millis() * 10) > httpKeepAlive.millis()) {
logger.warn("Suspicious keep alive settings, httpKeepAlive set to [{}], while httpKeepAliveTickDuration is set to [{}]", httpKeepAlive, httpKeepAliveTickDuration);
}
// validate max content length
if (maxContentLength.bytes() > Integer.MAX_VALUE) {
logger.warn("maxContentLength[" + maxContentLength + "] set to high value, resetting it to [100mb]");
maxContentLength = new SizeValue(100, SizeUnit.MB);
}
this.maxContentLength = maxContentLength;
}
@Override public Lifecycle.State lifecycleState() {
@ -154,6 +166,7 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
pipeline.addLast("openChannels", serverOpenChannels);
pipeline.addLast("keepAliveTimeout", new ReadTimeoutHandler(keepAliveTimer, httpKeepAlive.millis(), TimeUnit.MILLISECONDS));
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator((int) maxContentLength.bytes()));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("handler", requestHandler);
return pipeline;

View File

@ -1,24 +0,0 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.elasticsearch.http.netty;
public class SimpleNettyHttpTransportTests {
}