javax.websocket.Extension.Parameter Java Examples

The following examples show how to use javax.websocket.Extension.Parameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PerMessageDeflate.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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;
}
 
Example #2
Source File: TestUtil.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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());
}
 
Example #3
Source File: TestPerMessageDeflate.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testSendEmptyMessagePartWithContextTakeover() throws IOException {

    // Set up the extension using defaults
    List<Parameter> parameters = Collections.emptyList();
    List<List<Parameter>> preferences = new ArrayList<>();
    preferences.add(parameters);

    PerMessageDeflate perMessageDeflate = PerMessageDeflate.negotiate(preferences, true);
    perMessageDeflate.setNext(new TesterTransformation());

    ByteBuffer bb1 = ByteBuffer.wrap("A".getBytes(StandardCharsets.UTF_8));
    MessagePart mp1 = new MessagePart(true, 0, Constants.OPCODE_TEXT, bb1, null, null, -1);

    List<MessagePart> uncompressedParts1 = new ArrayList<>();
    uncompressedParts1.add(mp1);
    perMessageDeflate.sendMessagePart(uncompressedParts1);

    ByteBuffer bb2 = ByteBuffer.wrap("".getBytes(StandardCharsets.UTF_8));
    MessagePart mp2 = new MessagePart(true, 0, Constants.OPCODE_TEXT, bb2, null, null, -1);

    List<MessagePart> uncompressedParts2 = new ArrayList<>();
    uncompressedParts2.add(mp2);
    perMessageDeflate.sendMessagePart(uncompressedParts2);
}
 
Example #4
Source File: PerMessageDeflate.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: TestUtil.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void doTestParseExtensionHeaderSimple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<Extension>();
    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());
}
 
Example #6
Source File: PerMessageDeflate.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: TestUtil.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void doTestParseExtensionHeaderSimple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<Extension>();
    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());
}
 
Example #8
Source File: TestUtil.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
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());
}
 
Example #9
Source File: TestUtil.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void doTestParseExtensionHeaderMultiple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<Extension>();
    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());
}
 
Example #10
Source File: TestUtil.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void doTestParseExtensionHeaderMultiple(String header) {
    // Simple test
    List<Extension> result = new ArrayList<Extension>();
    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());
}