001package com.facebook.swift.service;
002
003import org.jboss.netty.channel.ChannelDownstreamHandler;
004import org.jboss.netty.channel.ChannelEvent;
005import org.jboss.netty.channel.ChannelHandlerContext;
006import org.jboss.netty.channel.ChannelUpstreamHandler;
007
008/**
009 * A combination of {@link ThriftXHRDecoder} and {@link ThriftXHREncoder}
010 * which enables easier server side HTTP implementation.
011 * @see org.jboss.netty.handler.codec.http.HttpServerCodec
012 * @author guyadong
013 *
014 */
015public class ThriftServerXHRCodec implements ChannelUpstreamHandler,ChannelDownstreamHandler{
016    private final ThriftXHRDecoder decoder = new ThriftXHRDecoder();
017    private final ThriftXHREncoder encoder = new ThriftXHREncoder(decoder);
018        public ThriftServerXHRCodec() {
019        }
020
021        @Override
022        public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
023                 decoder.handleUpstream(ctx, e);
024        }
025
026        @Override
027        public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
028                encoder.handleDownstream(ctx, e);
029        }
030
031}