View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.server.mux;
20  
21  import java.io.IOException;
22  import java.nio.ByteBuffer;
23  
24  import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
25  import org.eclipse.jetty.io.EofException;
26  import org.eclipse.jetty.server.HttpTransport;
27  import org.eclipse.jetty.util.BlockingCallback;
28  import org.eclipse.jetty.util.Callback;
29  import org.eclipse.jetty.util.log.Log;
30  import org.eclipse.jetty.util.log.Logger;
31  import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
32  import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
33  
34  /**
35   * Take {@link ResponseInfo} objects and convert to bytes for response.
36   */
37  public class HttpTransportOverMux implements HttpTransport
38  {
39      private static final Logger LOG = Log.getLogger(HttpTransportOverMux.class);
40      private final BlockingCallback streamBlocker = new BlockingCallback();
41  
42      public HttpTransportOverMux(Muxer muxer, MuxChannel channel)
43      {
44          // TODO Auto-generated constructor stub
45      }
46  
47      @Override
48      public void completed()
49      {
50          LOG.debug("completed");
51      }
52  
53      /**
54       * Process ResponseInfo object into AddChannelResponse
55       */
56      @Override
57      public void send(ResponseInfo info, ByteBuffer responseBodyContent, boolean lastContent) throws IOException
58      {
59          send(info,responseBodyContent,lastContent,streamBlocker);
60          try
61          {
62              streamBlocker.block();
63          }
64          catch (IOException e)
65          {
66              throw e;
67          }
68          catch (Exception e)
69          {
70              throw new EofException(e);
71          }
72      }
73  
74      @Override
75      public void send(ResponseInfo info, ByteBuffer responseBodyContent, boolean lastContent, Callback callback)
76      {
77          if (lastContent == false)
78          {
79              // throw error
80          }
81  
82          if (info.getContentLength() > 0)
83          {
84              // throw error
85          }
86  
87          // prepare the AddChannelResponse
88          // TODO: look at HttpSender in jetty-client for generator loop logic
89      }
90  }