This repository has been archived by the owner on Jan 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of smart http netty implementation
Signed-off-by: Denis Bardadym <denis.bardadym@acenture.com>
- Loading branch information
Denis Bardadym
committed
Apr 10, 2012
1 parent
ada9033
commit d0bebdf
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2012 Denis Bardadym | ||
Licensed 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 daemon.http | ||
|
||
import net.liftweb.common.Loggable | ||
|
||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory | ||
import org.jboss.netty.channel.{ChannelPipelineFactory, Channels, SimpleChannelHandler,ChannelHandlerContext, ExceptionEvent, MessageEvent} | ||
import org.jboss.netty.handler.codec.http.{HttpServerCodec, HttpChunkAggregator, HttpRequest} | ||
import org.jboss.netty.bootstrap.ServerBootstrap | ||
import org.jboss.netty.util.CharsetUtil | ||
|
||
import java.net.InetSocketAddress | ||
import java.util.concurrent.Executors | ||
|
||
import code.model.RepositoryDoc | ||
|
||
object SmartHttpDaemon extends daemon.Service with Loggable { | ||
|
||
var inited = false | ||
|
||
def init() { | ||
val factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool, Executors.newCachedThreadPool) | ||
|
||
val bootstrap = new ServerBootstrap(factory) | ||
|
||
bootstrap.setPipelineFactory(new ChannelPipelineFactory() { | ||
def getPipeline() = { | ||
val pipeline = Channels.pipeline | ||
|
||
pipeline.addLast("codec", new HttpServerCodec ) | ||
pipeline.addLast("aggregator", new HttpChunkAggregator(5242880)) | ||
pipeline.addLast("authHandler", new SmartHttpMessageHandler ) | ||
|
||
pipeline | ||
} | ||
}) | ||
|
||
//b.setOption("localAddress", new InetSocketAddress(8080)) | ||
|
||
bootstrap.setOption("reuseAddress", true) | ||
bootstrap.setOption("child.tcpNoDelay", true) | ||
bootstrap.setOption("child.keepAlive", true) | ||
|
||
bootstrap.bind(new InetSocketAddress(80)); | ||
|
||
|
||
} | ||
|
||
def shutdown() {} | ||
|
||
|
||
|
||
def repoUrlForCurrentUser(r: RepositoryDoc) = "" | ||
|
||
} | ||
|
||
class SmartHttpMessageHandler extends SimpleChannelHandler with Loggable { | ||
override def exceptionCaught(ctx: ChannelHandlerContext, e: ExceptionEvent) { | ||
logger.error("Exception recieved in smart http daemon", e.getCause) | ||
ctx.getChannel.close | ||
} | ||
|
||
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) { | ||
val httpResponse = e.getMessage.asInstanceOf[HttpRequest] | ||
val json = httpResponse.getContent.toString(CharsetUtil.UTF_8) | ||
logger.debug(json) | ||
} | ||
} |