All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webbitserver.netty.FlashPolicyFileHandler Maven / Gradle / Ivy

There is a newer version: 0.4.15
Show newest version
package org.webbitserver.netty;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.util.CharsetUtil;

/**
 * Responds with a Flash socket policy file.
 * 
 * 

* This implementation is based on the * waywardmonkeys/netty-flash-crossdomain-policy-server project and the * Setting up a socket policy file server article. *

*/ public class FlashPolicyFileHandler extends SimpleChannelUpstreamHandler { private final int publicPort; public FlashPolicyFileHandler(int publicPort) { super(); this.publicPort = publicPort; } @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Channel ch = e.getChannel(); ChannelBuffer response = getPolicyFileContents(); ChannelFuture future = ch.write(response); future.addListener(ChannelFutureListener.CLOSE); ctx.getPipeline().remove(this); } private ChannelBuffer getPolicyFileContents() throws Exception { return ChannelBuffers.copiedBuffer( "\r\n" + "\r\n" + "\r\n" + " \r\n" + " \r\n" + "\r\n", CharsetUtil.US_ASCII); } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { e.getCause().printStackTrace(); e.getChannel().close(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy