01: //========================================================================
02: // Parts Copyright 2006 Mort Bay Consulting Pty. Ltd.
03: //------------------------------------------------------------------------
04: // Licensed under the Apache License, Version 2.0 (the "License");
05: // you may not use this file except in compliance with the License.
06: // You may obtain a copy of the License at
07: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: //========================================================================
14:
15: package org.mortbay.jetty.grizzly;
16:
17: import com.sun.enterprise.web.connector.grizzly.DefaultReadTask;
18: import com.sun.enterprise.web.portunif.ProtocolHandler;
19: import com.sun.enterprise.web.portunif.util.ProtocolInfo;
20: import java.io.IOException;
21:
22: /**
23: * Simple Protocol handler that redirect http request from GlassFish to Jetty.
24: *
25: * @author Jeanfrancois Arcand
26: */
27: public class JettyProtocolHandler implements ProtocolHandler {
28:
29: private String[] protocols = new String[] { "jetty-http" };
30:
31: private JettyEmbedder embedded;
32:
33: /** Creates a new instance of JettyProtocolHandler */
34: public JettyProtocolHandler() {
35: }
36:
37: public String[] getProtocols() {
38: return protocols;
39: }
40:
41: public void handle(ProtocolInfo protocolInfo) throws IOException {
42: if (embedded == null) {
43: embedded = new JettyEmbedder(protocolInfo.socketChannel
44: .socket().getLocalPort());
45: try {
46: embedded.start();
47: } catch (Exception ex) {
48: ex.printStackTrace();
49: }
50: }
51:
52: JettySelectorThread selectorThread = embedded.getConnector()
53: .getSelectorThread();
54: DefaultReadTask readTask = (DefaultReadTask) selectorThread
55: .getReadTask();
56:
57: readTask.setBytesAvailable(true);
58: readTask.setByteBuffer(protocolInfo.byteBuffer);
59: readTask.setSelectionKey(protocolInfo.key);
60: readTask.doTask();
61: selectorThread.returnTask(readTask);
62: }
63:
64: }
|