Java Code Examples for org.eclipse.jetty.websocket.api.WebSocketPolicy#setMaxBinaryMessageSize()

The following examples show how to use org.eclipse.jetty.websocket.api.WebSocketPolicy#setMaxBinaryMessageSize() . 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: AbstractJettyWebSocketService.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
protected void configurePolicy(final ConfigurationContext context, final WebSocketPolicy policy) {
    final int inputBufferSize = context.getProperty(INPUT_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final int maxTextMessageSize = context.getProperty(MAX_TEXT_MESSAGE_SIZE).asDataSize(DataUnit.B).intValue();
    final int maxBinaryMessageSize = context.getProperty(MAX_BINARY_MESSAGE_SIZE).asDataSize(DataUnit.B).intValue();
    policy.setInputBufferSize(inputBufferSize);
    policy.setMaxTextMessageSize(maxTextMessageSize);
    policy.setMaxBinaryMessageSize(maxBinaryMessageSize);
}
 
Example 2
Source File: JettyWebSocketServer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object createWebSocket(ServletUpgradeRequest servletUpgradeRequest, ServletUpgradeResponse servletUpgradeResponse) {
    final URI requestURI = servletUpgradeRequest.getRequestURI();
    final int port = requestURI.getPort();
    final JettyWebSocketServer service = portToControllerService.get(port);

    if (service == null) {
        throw new RuntimeException("No controller service is bound with port: " + port);
    }

    final String path = requestURI.getPath();
    final WebSocketMessageRouter router;
    try {
        router = service.routers.getRouterOrFail(path);
    } catch (WebSocketConfigurationException e) {
        throw new IllegalStateException("Failed to get router due to: "  + e, e);
    }

    final RoutingWebSocketListener listener = new RoutingWebSocketListener(router) {
        @Override
        public void onWebSocketConnect(Session session) {
            final WebSocketPolicy currentPolicy = session.getPolicy();
            currentPolicy.setInputBufferSize(service.configuredPolicy.getInputBufferSize());
            currentPolicy.setMaxTextMessageSize(service.configuredPolicy.getMaxTextMessageSize());
            currentPolicy.setMaxBinaryMessageSize(service.configuredPolicy.getMaxBinaryMessageSize());
            super.onWebSocketConnect(session);
        }
    };

    return listener;
}
 
Example 3
Source File: InstJsrServerEndpointImpl.java    From dropwizard-websockets with MIT License 5 votes vote down vote up
@Override
public EventDriver create(Object websocket, WebSocketPolicy policy) throws Throwable {
    if (!(websocket instanceof EndpointInstance)) {
        throw new IllegalStateException(String.format("Websocket %s must be an %s", websocket.getClass().getName(), EndpointInstance.class.getName()));
    }

    EndpointInstance ei = (EndpointInstance) websocket;
    AnnotatedServerEndpointMetadata metadata = (AnnotatedServerEndpointMetadata) ei.getMetadata();
    JsrEvents<ServerEndpoint, ServerEndpointConfig> events = new JsrEvents<>(metadata);

    // Handle @OnMessage maxMessageSizes
    int maxBinaryMessage = getMaxMessageSize(policy.getMaxBinaryMessageSize(), metadata.onBinary, metadata.onBinaryStream);
    int maxTextMessage = getMaxMessageSize(policy.getMaxTextMessageSize(), metadata.onText, metadata.onTextStream);

    policy.setMaxBinaryMessageSize(maxBinaryMessage);
    policy.setMaxTextMessageSize(maxTextMessage);

    //////// instrumentation is here
    JsrAnnotatedEventDriver driver = new InstJsrAnnotatedEventDriver(policy, ei, events, metrics);
    ////////
    
    // Handle @PathParam values
    ServerEndpointConfig config = (ServerEndpointConfig) ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig) {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig) config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }

    return driver;
}
 
Example 4
Source File: AbstractJettyWebSocketService.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected void configurePolicy(final ConfigurationContext context, final WebSocketPolicy policy) {
    final int inputBufferSize = context.getProperty(INPUT_BUFFER_SIZE).asDataSize(DataUnit.B).intValue();
    final int maxTextMessageSize = context.getProperty(MAX_TEXT_MESSAGE_SIZE).asDataSize(DataUnit.B).intValue();
    final int maxBinaryMessageSize = context.getProperty(MAX_BINARY_MESSAGE_SIZE).asDataSize(DataUnit.B).intValue();
    policy.setInputBufferSize(inputBufferSize);
    policy.setMaxTextMessageSize(maxTextMessageSize);
    policy.setMaxBinaryMessageSize(maxBinaryMessageSize);
}
 
Example 5
Source File: JettyWebSocketServer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object createWebSocket(ServletUpgradeRequest servletUpgradeRequest, ServletUpgradeResponse servletUpgradeResponse) {
    final URI requestURI = servletUpgradeRequest.getRequestURI();
    final int port = servletUpgradeRequest.getLocalPort();
    final JettyWebSocketServer service = portToControllerService.get(port);

    if (service == null) {
        throw new RuntimeException("No controller service is bound with port: " + port);
    }

    final String path = requestURI.getPath();
    final WebSocketMessageRouter router;
    try {
        router = service.routers.getRouterOrFail(path);
    } catch (WebSocketConfigurationException e) {
        throw new IllegalStateException("Failed to get router due to: "  + e, e);
    }

    final RoutingWebSocketListener listener = new RoutingWebSocketListener(router) {
        @Override
        public void onWebSocketConnect(Session session) {
            final WebSocketPolicy currentPolicy = session.getPolicy();
            currentPolicy.setInputBufferSize(service.configuredPolicy.getInputBufferSize());
            currentPolicy.setMaxTextMessageSize(service.configuredPolicy.getMaxTextMessageSize());
            currentPolicy.setMaxBinaryMessageSize(service.configuredPolicy.getMaxBinaryMessageSize());
            super.onWebSocketConnect(session);
        }
    };

    return listener;
}