01: package com.caucho.protocols.flash;
02:
03: import java.io.*;
04:
05: import com.caucho.server.connection.Connection;
06: import com.caucho.server.dispatch.DispatchServer;
07: import com.caucho.server.port.ServerRequest;
08: import com.caucho.server.http.HttpRequest;
09: import com.caucho.vfs.*;
10: import com.caucho.util.*;
11:
12: public class SocketPolicyRequest extends HttpRequest {
13: private final static L10N L = new L10N(SocketPolicyRequest.class);
14:
15: private final Path _policy;
16: private final Connection _connection;
17:
18: public SocketPolicyRequest(DispatchServer server,
19: Connection connection, Path policy) {
20: super (server, connection);
21:
22: _policy = policy;
23: _connection = connection;
24: }
25:
26: /**
27: * Initialize the connection. At this point, the current thread is the
28: * connection thread.
29: */
30: public void init() {
31: super .init();
32: }
33:
34: /**
35: * Handles a new connection. The controlling TcpServer may call
36: * handleConnection again after the connection completes, so
37: * the implementation must initialize any variables for each connection.
38: */
39: public boolean handleRequest() throws IOException {
40: ReadStream is = _connection.getReadStream();
41:
42: int ch = is.read();
43:
44: if (ch == '<') {
45: OutputStream out = _connection.getWriteStream();
46: _policy.writeToStream(out);
47: out.write(0); // null byte required
48: out.flush();
49:
50: return false;
51: } else {
52: is.unread();
53:
54: return super.handleRequest();
55: }
56: }
57: }
|