let jetty handle flex policy-file-request
jetty : org.eclipse.jetty.project-jetty-8.0.4.v20111024
1. http
a. jetty-http
add class name FlashPolicyException in package org.eclipse.jetty.http
org.eclipse.jetty.http.HttpParser add codes: line 310
// EventHandler header
byte ch;
byte[] array=_buffer.array();
try
{
if(new String(array).startsWith("<policy-file-request"))
throw new FlashPolicyException();
}
catch(FlashPolicyException e)
{
throw e;
}
catch(Exception e)
{
// no big deal
}
b. jetty-server
org.eclipse.jetty.server.AsyncHttpConnection add codes: line 69
catch (FlashPolicyException e)
{
_endp.flush(new ByteArrayBuffer("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0"));
_parser.reset();
_endp.close();
}
2.https:
a. jetty-io
org.eclipse.jetty.io.nio.ChannelEndPoint add codes: line 167
private String xml = "<?xml version=\"1.0\"?><cross-domain-policy><site-control permitted-cross-domain-policies=\"all\"/><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0";
/* (non-Javadoc)
* @see org.eclipse.io.EndPoint#fill(org.eclipse.io.Buffer)
*/
public int fill(Buffer buffer) throws IOException
{
Buffer buf = buffer.buffer();
int len=0;
if (buf instanceof NIOBuffer)
{
final NIOBuffer nbuf = (NIOBuffer)buf;
final ByteBuffer bbuf=nbuf.getByteBuffer();
//noinspection SynchronizationOnLocalVariableOrMethodParameter
try
{
synchronized(bbuf)
{
try
{
bbuf.position(buffer.putIndex());
len=_channel.read(bbuf);
}
finally
{
String s = new String(Arrays.copyOfRange(bbuf.array(),0,bbuf.position()));
if (s.startsWith("<policy-file-request")) {
_channel.write(ByteBuffer.wrap(xml.getBytes()));
}
buffer.setPutIndex(bbuf.position());
bbuf.position(0);
}
}
if (len<0 && isOpen())
{
if (!isInputShutdown())
shutdownInput();
else if (isOutputShutdown())
_channel.close();
}
}
catch (IOException x)
{
LOG.debug(x);
try
{
close();
}
catch (IOException xx)
{
LOG.ignore(xx);
}
if (len>0)
throw x;
len=-1;
}
}
else
{
throw new IOException("Not Implemented");
}
return len;
}