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