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.List;
22 import java.util.ServiceLoader;
23
24 import javax.websocket.Extension;
25 import javax.websocket.HandshakeResponse;
26 import javax.websocket.server.HandshakeRequest;
27 import javax.websocket.server.ServerEndpointConfig;
28 import javax.websocket.server.ServerEndpointConfig.Configurator;
29
30 import org.eclipse.jetty.util.log.Log;
31 import org.eclipse.jetty.util.log.Logger;
32 import org.eclipse.jetty.websocket.api.util.QuoteUtil;
33
34
35
36
37
38
39 public final class ContainerDefaultConfigurator extends Configurator
40 {
41 private static final Logger LOG = Log.getLogger(ContainerDefaultConfigurator.class);
42 private static final String NO_SUBPROTOCOL = "";
43
44
45
46
47
48
49 public ContainerDefaultConfigurator()
50 {
51 super();
52 }
53
54 @Override
55 public boolean checkOrigin(String originHeaderValue)
56 {
57 return true;
58 }
59
60 @Override
61 public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException
62 {
63 if (LOG.isDebugEnabled())
64 {
65 LOG.debug(".getEndpointInstance({})",endpointClass);
66 }
67
68 try
69 {
70
71
72 return endpointClass.newInstance();
73 }
74 catch (IllegalAccessException e)
75 {
76 throw new InstantiationException(String.format("%s: %s",e.getClass().getName(),e.getMessage()));
77 }
78 }
79
80 @Override
81 public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested)
82 {
83 return requested;
84 }
85
86 @Override
87 public String getNegotiatedSubprotocol(List<String> supported, List<String> requested)
88 {
89 if ((requested == null) || (requested.size() == 0))
90 {
91
92 return NO_SUBPROTOCOL;
93 }
94
95
96 if ((supported == null) || (supported.isEmpty()))
97 {
98
99 LOG.warn("Client requested Subprotocols on endpoint with none supported: {}",QuoteUtil.join(requested,","));
100 return NO_SUBPROTOCOL;
101 }
102
103
104 for (String possible : requested)
105 {
106 if (possible == null)
107 {
108
109 continue;
110 }
111
112 if (supported.contains(possible))
113 {
114 return possible;
115 }
116 }
117
118 LOG.warn("Client requested subprotocols {} do not match any endpoint supported subprotocols {}",QuoteUtil.join(requested,","),
119 QuoteUtil.join(supported,","));
120 return NO_SUBPROTOCOL;
121 }
122
123 @Override
124 public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response)
125 {
126
127 }
128 }