Java Code Examples for javax.websocket.Extension#getParameters()

The following examples show how to use javax.websocket.Extension#getParameters() . 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 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 3
Source File: UpgradeUtil.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private static void append(StringBuilder sb, Extension extension) {
    if (extension == null || extension.getName() == null || extension.getName().length() == 0) {
        return;
    }

    sb.append(extension.getName());

    for (Extension.Parameter p : extension.getParameters()) {
        sb.append(';');
        sb.append(p.getName());
        if (p.getValue() != null) {
            sb.append('=');
            sb.append(p.getValue());
        }
    }
}
 
Example 4
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 5
Source File: WsWebSocketContainer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private static List<String> generateExtensionHeaders(List<Extension> extensions) {
    List<String> result = new ArrayList<String>(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;
}
 
Example 6
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 7
Source File: UpgradeUtil.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private static void append(StringBuilder sb, Extension extension) {
    if (extension == null || extension.getName() == null || extension.getName().length() == 0) {
        return;
    }

    sb.append(extension.getName());

    for (Extension.Parameter p : extension.getParameters()) {
        sb.append(';');
        sb.append(p.getName());
        if (p.getValue() != null) {
            sb.append('=');
            sb.append(p.getValue());
        }
    }
}
 
Example 8
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 9
Source File: WsWebSocketContainer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private static List<String> generateExtensionHeaders(List<Extension> extensions) {
    List<String> result = new ArrayList<String>(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;
}
 
Example 10
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 11
Source File: UpgradeUtil.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static void append(StringBuilder sb, Extension extension) {
    if (extension == null || extension.getName() == null || extension.getName().length() == 0) {
        return;
    }

    sb.append(extension.getName());

    for (Extension.Parameter p : extension.getParameters()) {
        sb.append(';');
        sb.append(p.getName());
        if (p.getValue() != null) {
            sb.append('=');
            sb.append(p.getValue());
        }
    }
}
 
Example 12
Source File: WsWebSocketContainer.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
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;
}
 
Example 13
Source File: StandardToWebSocketExtensionAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static Map<String, String> initParameters(Extension extension) {
	List<Extension.Parameter> parameters = extension.getParameters();
	Map<String, String> result = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
	for (Extension.Parameter parameter : parameters) {
		result.put(parameter.getName(), parameter.getValue());
	}
	return result;
}
 
Example 14
Source File: ServerWebSocketContainer.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static List<WebSocketExtensionData> toExtensionList(final List<Extension> extensions) {
    List<WebSocketExtensionData> ret = new ArrayList<>();
    for (Extension e : extensions) {
        final Map<String, String> parameters = new HashMap<>();
        for (Extension.Parameter p : e.getParameters()) {
            parameters.put(p.getName(), p.getValue());
        }
        ret.add(new WebSocketExtensionData(e.getName(), parameters));
    }
    return ret;
}
 
Example 15
Source File: StandardToWebSocketExtensionAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static Map<String, String> initParameters(Extension extension) {
	List<Extension.Parameter> parameters = extension.getParameters();
	Map<String, String> result = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
	for (Extension.Parameter parameter : parameters) {
		result.put(parameter.getName(), parameter.getValue());
	}
	return result;
}
 
Example 16
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 17
Source File: StandardToWebSocketExtensionAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private static Map<String, String> initParameters(Extension extension) {
	List<Extension.Parameter> parameters = extension.getParameters();
	Map<String, String> result = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH);
	for (Extension.Parameter parameter : parameters) {
		result.put(parameter.getName(), parameter.getValue());
	}
	return result;
}
 
Example 18
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 19
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());
}