use of jakarta.websocket.Extension in project tomcat by apache.
the class TesterWsClientAutobahn method executeTestCase.
private static void executeTestCase(WebSocketContainer wsc, int testCase) throws Exception {
URI uri = new URI("ws://" + HOST + ":" + PORT + "/runCase?case=" + testCase + "&agent=" + USER_AGENT);
TestCaseClient testCaseClient = new TestCaseClient();
Extension permessageDeflate = new WsExtension("permessage-deflate");
// Advertise support for client_max_window_bits
// Client only supports some values so there will be some failures here
// Note Autobahn returns a 400 response if you provide a value for
// client_max_window_bits
permessageDeflate.getParameters().add(new WsExtensionParameter("client_max_window_bits", null));
List<Extension> extensions = new ArrayList<>(1);
extensions.add(permessageDeflate);
Endpoint ep = new PojoEndpointClient(testCaseClient, null, null);
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
ClientEndpointConfig config = builder.extensions(extensions).build();
wsc.connectToServer(ep, config, uri);
testCaseClient.waitForClose();
}
use of jakarta.websocket.Extension in project tomcat by apache.
the class TestUtil method doTestParseExtensionHeaderMultiple.
private void doTestParseExtensionHeaderMultiple(String header) {
// Simple test
List<Extension> result = new ArrayList<>();
Util.parseExtensionHeader(result, header);
Assert.assertEquals(3, result.size());
Extension ext = result.get(0);
Assert.assertEquals("ext", ext.getName());
List<Parameter> params = ext.getParameters();
Assert.assertEquals(2, params.size());
Parameter paramA = params.get(0);
Assert.assertEquals("a", paramA.getName());
Assert.assertEquals("1", paramA.getValue());
Parameter paramB = params.get(1);
Assert.assertEquals("b", paramB.getName());
Assert.assertEquals("2", paramB.getValue());
Extension ext2 = result.get(1);
Assert.assertEquals("ext2", ext2.getName());
List<Parameter> params2 = ext2.getParameters();
Assert.assertEquals(2, params2.size());
Parameter paramC = params2.get(0);
Assert.assertEquals("c", paramC.getName());
Assert.assertNull(paramC.getValue());
Parameter paramD = params2.get(1);
Assert.assertEquals("d", paramD.getName());
Assert.assertEquals("xyz", paramD.getValue());
Extension ext3 = result.get(2);
Assert.assertEquals("ext3", ext3.getName());
List<Parameter> params3 = ext3.getParameters();
Assert.assertEquals(0, params3.size());
}
use of jakarta.websocket.Extension in project tomcat by apache.
the class TestUtil method doTestParseExtensionHeaderSimple.
private void doTestParseExtensionHeaderSimple(String header) {
// Simple test
List<Extension> result = new ArrayList<>();
Util.parseExtensionHeader(result, header);
Assert.assertEquals(1, result.size());
Extension ext = result.get(0);
Assert.assertEquals("ext", ext.getName());
List<Parameter> params = ext.getParameters();
Assert.assertEquals(2, params.size());
Parameter paramA = params.get(0);
Assert.assertEquals("a", paramA.getName());
Assert.assertEquals("1", paramA.getValue());
Parameter paramB = params.get(1);
Assert.assertEquals("b", paramB.getName());
Assert.assertEquals("2", paramB.getValue());
}
use of jakarta.websocket.Extension in project tomcat by apache.
the class WsWebSocketContainer method generateExtensionHeaders.
private static List<String> generateExtensionHeaders(List<Extension> extensions) {
List<String> result = new ArrayList<>(extensions.size());
for (Extension extension : extensions) {
StringBuilder header = new StringBuilder();
header.append(extension.getName());
for (Extension.Parameter param : extension.getParameters()) {
header.append(';');
header.append(param.getName());
String value = param.getValue();
if (value != null && value.length() > 0) {
header.append('=');
header.append(value);
}
}
result.add(header.toString());
}
return result;
}
use of jakarta.websocket.Extension in project tomcat by apache.
the class PerMessageDeflate method getExtensionResponse.
@Override
public Extension getExtensionResponse() {
Extension result = new WsExtension(NAME);
List<Extension.Parameter> params = result.getParameters();
if (!serverContextTakeover) {
params.add(new WsExtensionParameter(SERVER_NO_CONTEXT_TAKEOVER, null));
}
if (serverMaxWindowBits != -1) {
params.add(new WsExtensionParameter(SERVER_MAX_WINDOW_BITS, Integer.toString(serverMaxWindowBits)));
}
if (!clientContextTakeover) {
params.add(new WsExtensionParameter(CLIENT_NO_CONTEXT_TAKEOVER, null));
}
if (clientMaxWindowBits != -1) {
params.add(new WsExtensionParameter(CLIENT_MAX_WINDOW_BITS, Integer.toString(clientMaxWindowBits)));
}
return result;
}
Aggregations