View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Intalio, Inc.
3    * ======================================================================
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * and Apache License v2.0 which accompanies this distribution.
7    *
8    *   The Eclipse Public License is available at
9    *   http://www.eclipse.org/legal/epl-v10.html
10   *
11   *   The Apache License v2.0 is available at
12   *   http://www.opensource.org/licenses/apache2.0.php
13   *
14   * You may elect to redistribute this code under either of these licenses.
15   *******************************************************************************/
16  // ========================================================================
17  // Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
18  // ------------------------------------------------------------------------
19  // All rights reserved. This program and the accompanying materials
20  // are made available under the terms of the Eclipse Public License v1.0
21  // and Apache License v2.0 which accompanies this distribution.
22  // The Eclipse Public License is available at 
23  // http://www.eclipse.org/legal/epl-v10.html
24  // The Apache License v2.0 is available at
25  // http://www.opensource.org/licenses/apache2.0.php
26  // You may elect to redistribute this code under either of these licenses. 
27  // ========================================================================
28  
29  package org.eclipse.jetty.websocket;
30  
31  import java.io.IOException;
32  
33  import javax.servlet.ServletException;
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  
37  import org.eclipse.jetty.server.Request;
38  import org.eclipse.jetty.server.handler.HandlerWrapper;
39  
40  public abstract class WebSocketHandler extends HandlerWrapper implements WebSocketFactory.Acceptor
41  {
42      private final WebSocketFactory _webSocketFactory=new WebSocketFactory(this,32*1024);
43      
44      public WebSocketFactory getWebSocketFactory()
45      {
46          return _webSocketFactory;
47      }
48  
49      /* ------------------------------------------------------------ */
50      @Override
51      public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
52      {
53          if (_webSocketFactory.acceptWebSocket(request,response) || response.isCommitted())
54              return;
55          super.handle(target,baseRequest,request,response);
56      }
57      
58      /* ------------------------------------------------------------ */
59      public boolean checkOrigin(HttpServletRequest request, String origin)
60      {
61          return true;
62      }
63      
64  }