1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 }