View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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.jsr356.server;
20  
21  import java.util.LinkedList;
22  
23  import javax.websocket.DeploymentException;
24  import javax.websocket.server.ServerEndpoint;
25  import javax.websocket.server.ServerEndpointConfig;
26  
27  import org.eclipse.jetty.websocket.api.InvalidWebSocketException;
28  import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
29  import org.eclipse.jetty.websocket.jsr356.annotations.AnnotatedEndpointMetadata;
30  import org.eclipse.jetty.websocket.jsr356.annotations.IJsrParamId;
31  
32  public class AnnotatedServerEndpointMetadata extends AnnotatedEndpointMetadata<ServerEndpoint,ServerEndpointConfig> implements ServerEndpointMetadata
33  {
34      private final ServerEndpoint endpoint;
35      private final AnnotatedServerEndpointConfig config;
36  
37      protected AnnotatedServerEndpointMetadata(WebSocketContainerScope containerScope, Class<?> websocket, ServerEndpointConfig baseConfig) throws DeploymentException
38      {
39          super(websocket);
40  
41          ServerEndpoint anno = websocket.getAnnotation(ServerEndpoint.class);
42          if (anno == null)
43          {
44              throw new InvalidWebSocketException("Unsupported WebSocket object, missing @" + ServerEndpoint.class + " annotation");
45          }
46  
47          this.endpoint = anno;
48          this.config = new AnnotatedServerEndpointConfig(containerScope,websocket,anno,baseConfig);
49          
50          getDecoders().addAll(anno.decoders());  
51          getEncoders().addAll(anno.encoders());
52      }
53  
54      @Override
55      public void customizeParamsOnClose(LinkedList<IJsrParamId> params)
56      {
57          super.customizeParamsOnClose(params);
58          params.addFirst(JsrPathParamId.INSTANCE);
59      }
60  
61      @Override
62      public void customizeParamsOnError(LinkedList<IJsrParamId> params)
63      {
64          super.customizeParamsOnError(params);
65          params.addFirst(JsrPathParamId.INSTANCE);
66      }
67      
68      @Override
69      public void customizeParamsOnOpen(LinkedList<IJsrParamId> params)
70      {
71          super.customizeParamsOnOpen(params);
72          params.addFirst(JsrPathParamId.INSTANCE);
73      }
74      
75      @Override
76      public void customizeParamsOnMessage(LinkedList<IJsrParamId> params)
77      {
78          super.customizeParamsOnMessage(params);
79          params.addFirst(JsrPathParamId.INSTANCE);
80      }
81  
82      @Override
83      public ServerEndpoint getAnnotation()
84      {
85          return endpoint;
86      }
87  
88      public AnnotatedServerEndpointConfig getConfig()
89      {
90          return config;
91      }
92  
93      public String getPath()
94      {
95          return config.getPath();
96      }
97  
98      @Override
99      public String toString()
100     {
101         StringBuilder builder = new StringBuilder();
102         builder.append("AnnotatedServerEndpointMetadata[endpoint=");
103         builder.append(endpoint);
104         builder.append(",config=");
105         builder.append(config);
106         builder.append("]");
107         return builder.toString();
108     }
109 }