View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2015 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.common.extensions.identity;
20  
21  import org.eclipse.jetty.util.QuotedStringTokenizer;
22  import org.eclipse.jetty.util.annotation.ManagedObject;
23  import org.eclipse.jetty.websocket.api.BatchMode;
24  import org.eclipse.jetty.websocket.api.WriteCallback;
25  import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
26  import org.eclipse.jetty.websocket.api.extensions.Frame;
27  import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
28  
29  @ManagedObject("Identity Extension")
30  public class IdentityExtension extends AbstractExtension
31  {
32      private String id;
33  
34      public String getParam(String key)
35      {
36          return getConfig().getParameter(key,"?");
37      }
38      
39      @Override
40      public String getName()
41      {
42          return "identity";
43      }
44  
45      @Override
46      public void incomingError(Throwable e)
47      {
48          // pass through
49          nextIncomingError(e);
50      }
51  
52      @Override
53      public void incomingFrame(Frame frame)
54      {
55          // pass through
56          nextIncomingFrame(frame);
57      }
58  
59      @Override
60      public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode)
61      {
62          // pass through
63          nextOutgoingFrame(frame,callback, batchMode);
64      }
65  
66      @Override
67      public void setConfig(ExtensionConfig config)
68      {
69          super.setConfig(config);
70          StringBuilder s = new StringBuilder();
71          s.append(config.getName());
72          s.append("@").append(Integer.toHexString(hashCode()));
73          s.append("[");
74          boolean delim = false;
75          for (String param : config.getParameterKeys())
76          {
77              if (delim)
78              {
79                  s.append(';');
80              }
81              s.append(param).append('=').append(QuotedStringTokenizer.quoteIfNeeded(config.getParameter(param,""),";="));
82              delim = true;
83          }
84          s.append("]");
85          id = s.toString();
86      }
87  
88      @Override
89      public String toString()
90      {
91          return id;
92      }
93  }