-
Notifications
You must be signed in to change notification settings - Fork 39
/
DefaultServerEndpointConfig.java
143 lines (129 loc) · 4.76 KB
/
DefaultServerEndpointConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.websocket.server;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jakarta.websocket.Decoder;
import jakarta.websocket.Encoder;
import jakarta.websocket.Endpoint;
import jakarta.websocket.Extension;
/**
* The DefaultServerEndpointConfig is a concrete class that embodies all the configuration parameters for an endpoint
* that is to be published as a server endpoint. Developers may subclass this class in order to override the
* configuration behavior.
*
* @author dannycoward
*/
final class DefaultServerEndpointConfig implements ServerEndpointConfig {
private String path;
private Class<?> endpointClass;
private List<String> subprotocols;
private List<Extension> extensions;
private List<Class<? extends Encoder>> encoders;
private List<Class<? extends Decoder>> decoders;
private Map<String, Object> userProperties = new HashMap<>();
private ServerEndpointConfig.Configurator serverEndpointConfigurator;
// The builder ensures nothing except configurator can be {@code null}.
DefaultServerEndpointConfig(Class<?> endpointClass, String path, List<String> subprotocols,
List<Extension> extensions, List<Class<? extends Encoder>> encoders,
List<Class<? extends Decoder>> decoders, ServerEndpointConfig.Configurator serverEndpointConfigurator) {
this.path = path;
this.endpointClass = endpointClass;
this.subprotocols = Collections.unmodifiableList(subprotocols);
this.extensions = Collections.unmodifiableList(extensions);
this.encoders = Collections.unmodifiableList(encoders);
this.decoders = Collections.unmodifiableList(decoders);
if (serverEndpointConfigurator == null) {
this.serverEndpointConfigurator = ServerEndpointConfig.Configurator.fetchContainerDefaultConfigurator();
} else {
this.serverEndpointConfigurator = serverEndpointConfigurator;
}
}
/**
* Returns the class of the Endpoint that this configuration configures.
*
* @return the class of the Endpoint.
*/
@Override
public Class<?> getEndpointClass() {
return this.endpointClass;
}
/**
* Creates a server configuration with the given path
*
* @param path the URI or URI template.
*/
DefaultServerEndpointConfig(Class<? extends Endpoint> endpointClass, String path) {
this.path = path;
this.endpointClass = endpointClass;
}
/**
* Return the Encoder implementation classes configured. These will be used by the container to encode outgoing
* messages.
*
* @return the encoder implementation classes, in an unmodifiable list, empty if there are none.
*/
@Override
public List<Class<? extends Encoder>> getEncoders() {
return this.encoders;
}
/**
* Return the Decoder implementation classes configured. These will be used by the container to decode incoming
* messages into the expected custom objects on MessageHandler callbacks.
*
* @return the decoder implementation classes, in an unmodifiable list.
*/
@Override
public List<Class<? extends Decoder>> getDecoders() {
return this.decoders;
}
/**
* Return the path of this server configuration. The path is a relative URI or URI-template.
*
* @return the path
*/
@Override
public String getPath() {
return path;
}
/**
* Return the ServerEndpointConfigurator
*
* @return the ServerEndpointConfigurator
*/
@Override
public ServerEndpointConfig.Configurator getConfigurator() {
return this.serverEndpointConfigurator;
}
/**
* Editable map of user properties.
*/
@Override
public final Map<String, Object> getUserProperties() {
return this.userProperties;
}
@Override
public final List<String> getSubprotocols() {
return this.subprotocols;
}
@Override
public final List<Extension> getExtensions() {
return this.extensions;
}
}