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
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package javax.websocket;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public interface ClientEndpointConfig extends EndpointConfig {
List<String> getPreferredSubprotocols();
List<Extension> getExtensions();
public Configurator getConfigurator();
public final class Builder {
private static final Configurator DEFAULT_CONFIGURATOR =
new Configurator() {};
public static Builder create() {
return new Builder();
}
private Builder() {
// Hide default constructor
}
private Configurator configurator = DEFAULT_CONFIGURATOR;
private List<String> preferredSubprotocols = Collections.emptyList();
private List<Extension> extensions = Collections.emptyList();
private List<Class<? extends Encoder>> encoders =
Collections.emptyList();
private List<Class<? extends Decoder>> decoders =
Collections.emptyList();
public ClientEndpointConfig build() {
return new DefaultClientEndpointConfig(preferredSubprotocols,
extensions, encoders, decoders, configurator);
}
public Builder configurator(Configurator configurator) {
if (configurator == null) {
this.configurator = DEFAULT_CONFIGURATOR;
} else {
this.configurator = configurator;
}
return this;
}
public Builder preferredSubprotocols(
List<String> preferredSubprotocols) {
if (preferredSubprotocols == null ||
preferredSubprotocols.size() == 0) {
this.preferredSubprotocols = Collections.emptyList();
} else {
this.preferredSubprotocols =
Collections.unmodifiableList(preferredSubprotocols);
}
return this;
}
public Builder extensions(
List<Extension> extensions) {
if (extensions == null || extensions.size() == 0) {
this.extensions = Collections.emptyList();
} else {
this.extensions = Collections.unmodifiableList(extensions);
}
return this;
}
public Builder encoders(List<Class<? extends Encoder>> encoders) {
if (encoders == null || encoders.size() == 0) {
this.encoders = Collections.emptyList();
} else {
this.encoders = Collections.unmodifiableList(encoders);
}
return this;
}
public Builder decoders(List<Class<? extends Decoder>> decoders) {
if (decoders == null || decoders.size() == 0) {
this.decoders = Collections.emptyList();
} else {
this.decoders = Collections.unmodifiableList(decoders);
}
return this;
}
}
public class Configurator {
/**
* Provides the client with a mechanism to inspect and/or modify the headers
* that are sent to the server to start the WebSocket handshake.
*
* @param headers The HTTP headers
*/
public void beforeRequest(Map<String, List<String>> headers) {
// NO-OP
}
/**
* Provides the client with a mechanism to inspect the handshake response
* that is returned from the server.
*
* @param handshakeResponse The response
*/
public void afterResponse(HandshakeResponse handshakeResponse) {
// NO-OP
}
}
}
|