org.eclipse.jetty.websocket.api.WebSocketPolicy Java Examples

The following examples show how to use org.eclipse.jetty.websocket.api.WebSocketPolicy. 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: InstJsrServerExtendsEndpointImpl.java    From dropwizard-websockets with MIT License 6 votes vote down vote up
@Override
public EventDriver create(Object websocket, WebSocketPolicy policy)
{
    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;
    JsrEndpointEventDriver driver = new InstJsrEndpointEventDriver(policy, ei, metrics);
    
    ServerEndpointConfig config = (ServerEndpointConfig)ei.getConfig();
    if (config instanceof PathParamServerEndpointConfig)
    {
        PathParamServerEndpointConfig ppconfig = (PathParamServerEndpointConfig)config;
        driver.setPathParameters(ppconfig.getPathParamMap());
    }

    return driver;
}
 
Example #2
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;
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
Source File: DefaultWebSocketManager.java    From onedev with MIT License 5 votes vote down vote up
@Inject
public DefaultWebSocketManager(Application application, TransactionManager transactionManager, 
		WebSocketPolicy webSocketPolicy, TaskScheduler taskScheduler, ExecutorService executorService) {
	this.application = application;
	this.transactionManager = transactionManager;
	this.webSocketPolicy = webSocketPolicy;
	this.taskScheduler = taskScheduler;
	this.executorService = executorService;
}
 
Example #8
Source File: DefaultWicketFilter.java    From onedev with MIT License 5 votes vote down vote up
@Inject
public DefaultWicketFilter(WebApplication application, WebSocketPolicy webSocketPolicy) {
	super(webSocketPolicy);
	
	this.application = application;
	setFilterPath("");
}
 
Example #9
Source File: WebSocketPolicyProvider.java    From onedev with MIT License 4 votes vote down vote up
@Override
public WebSocketPolicy get() {
	WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
	policy.setIdleTimeout(serverConfig.getSessionTimeout()*1000);
	return policy;
}
 
Example #10
Source File: MockSession.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public WebSocketPolicy getPolicy() {
  return null;
}
 
Example #11
Source File: InstJsrEndpointEventDriver.java    From dropwizard-websockets with MIT License 4 votes vote down vote up
public InstJsrEndpointEventDriver(WebSocketPolicy policy, EndpointInstance ei, MetricRegistry metrics) {
    super(policy, ei);
    this.edm = new EventDriverMetrics(metadata.getEndpointClass(), metrics);
}
 
Example #12
Source File: InstJsrAnnotatedEventDriver.java    From dropwizard-websockets with MIT License 4 votes vote down vote up
public InstJsrAnnotatedEventDriver(WebSocketPolicy policy, EndpointInstance ei, JsrEvents<ServerEndpoint, ServerEndpointConfig> events, MetricRegistry metrics) {
    super(policy, ei, events);
    this.edm = new EventDriverMetrics(metadata.getEndpointClass(), metrics);
}
 
Example #13
Source File: WebSocketConfig.java    From smockin with Apache License 2.0 4 votes vote down vote up
private DefaultHandshakeHandler handshakeHandler() {
    return new DefaultHandshakeHandler(
            new JettyRequestUpgradeStrategy(
                    new WebSocketServerFactory(servletContext,
                            new WebSocketPolicy(WebSocketBehavior.SERVER))));
}
 
Example #14
Source File: CoreModule.java    From onedev with MIT License 4 votes vote down vote up
private void configureWeb() {
	bind(WicketServlet.class).to(DefaultWicketServlet.class);
	bind(WicketFilter.class).to(DefaultWicketFilter.class);
	bind(WebSocketPolicy.class).toProvider(WebSocketPolicyProvider.class);
	bind(EditSupportRegistry.class).to(DefaultEditSupportRegistry.class);
	bind(WebSocketManager.class).to(DefaultWebSocketManager.class);

	bind(AttachmentUploadServlet.class);
	
	contributeFromPackage(EditSupport.class, EditSupport.class);
	
	bind(WebApplication.class).to(OneWebApplication.class);
	bind(Application.class).to(OneWebApplication.class);
	bind(AvatarManager.class).to(DefaultAvatarManager.class);
	bind(WebSocketManager.class).to(DefaultWebSocketManager.class);
	
	contributeFromPackage(EditSupport.class, EditSupportLocator.class);
	
	contribute(WebApplicationConfigurator.class, new WebApplicationConfigurator() {
		
		@Override
		public void configure(WebApplication application) {
			application.mount(new OnePageMapper("/test", TestPage.class));
		}
		
	});
	
	bind(CommitIndexedBroadcaster.class);
	
	contributeFromPackage(DiffRenderer.class, DiffRenderer.class);
	contributeFromPackage(BlobRendererContribution.class, BlobRendererContribution.class);

	contribute(Extension.class, new EmojiExtension());
	contribute(Extension.class, new SourcePositionTrackExtension());
	
	contributeFromPackage(MarkdownProcessor.class, MarkdownProcessor.class);

	contribute(ResourcePackScopeContribution.class, new ResourcePackScopeContribution() {
		
		@Override
		public Collection<Class<?>> getResourcePackScopes() {
			return Lists.newArrayList(OneWebApplication.class);
		}
		
	});
	contribute(ExpectedExceptionContribution.class, new ExpectedExceptionContribution() {
		
		@SuppressWarnings("unchecked")
		@Override
		public Collection<Class<? extends Exception>> getExpectedExceptionClasses() {
			return Sets.newHashSet(ConstraintViolationException.class, EntityNotFoundException.class, 
					ObjectNotFoundException.class, StaleStateException.class, UnauthorizedException.class, 
					OneException.class, PageExpiredException.class, StalePageException.class);
		}
		
	});

	bind(UrlManager.class).to(DefaultUrlManager.class);
	bind(CodeCommentEventBroadcaster.class);
	bind(PullRequestEventBroadcaster.class);
	bind(IssueEventBroadcaster.class);
	bind(BuildEventBroadcaster.class);
	
	bind(TaskButton.TaskFutureManager.class);
	
	bind(UICustomization.class).toInstance(new UICustomization() {
		
		@Override
		public Class<? extends BasePage> getHomePage() {
			return DashboardPage.class;
		}
		
		@Override
		public List<MainTab> getMainTabs() {
			return Lists.newArrayList(
					new ProjectListTab(), new IssueListTab(), 
					new PullRequestListTab(), new BuildListTab());
		}

	});
}
 
Example #15
Source File: WebSocketFilter.java    From onedev with MIT License 4 votes vote down vote up
public WebSocketFilter(WebSocketPolicy webSocketPolicy) {
	this.webSocketPolicy = webSocketPolicy;
}
 
Example #16
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured {@link WebSocketPolicy}, if any.
 */
@Nullable
public WebSocketPolicy getWebSocketPolicy() {
	return this.webSocketPolicy;
}
 
Example #17
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the configured {@link WebSocketPolicy}, if any.
 */
@Nullable
public WebSocketPolicy getWebSocketPolicy() {
	return this.webSocketPolicy;
}
 
Example #18
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Configure a {@link WebSocketPolicy} to use to initialize
 * {@link WebSocketServerFactory}.
 * @param webSocketPolicy the WebSocket settings
 */
public void setWebSocketPolicy(WebSocketPolicy webSocketPolicy) {
	this.webSocketPolicy = webSocketPolicy;
}
 
Example #19
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * A constructor accepting a {@link WebSocketPolicy} to be used when
 * creating the {@link WebSocketServerFactory} instance.
 * @param policy the policy to use
 * @since 4.3.5
 */
public JettyRequestUpgradeStrategy(WebSocketPolicy policy) {
	Assert.notNull(policy, "WebSocketPolicy must not be null");
	this.policy = policy;
}
 
Example #20
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Default constructor that creates {@link WebSocketServerFactory} through
 * its default constructor thus using a default {@link WebSocketPolicy}.
 */
public JettyRequestUpgradeStrategy() {
	this.policy = WebSocketPolicy.newServerPolicy();
}
 
Example #21
Source File: JettyRequestUpgradeStrategy.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Configure a {@link WebSocketPolicy} to use to initialize
 * {@link WebSocketServerFactory}.
 * @param webSocketPolicy the WebSocket settings
 */
public void setWebSocketPolicy(WebSocketPolicy webSocketPolicy) {
	this.webSocketPolicy = webSocketPolicy;
}
 
Example #22
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * A constructor accepting a {@link WebSocketPolicy} to be used when
 * creating the {@link WebSocketServerFactory} instance.
 * @param policy the policy to use
 * @since 4.3.5
 */
public JettyRequestUpgradeStrategy(WebSocketPolicy policy) {
	Assert.notNull(policy, "WebSocketPolicy must not be null");
	this.policy = policy;
}
 
Example #23
Source File: JettyRequestUpgradeStrategy.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Default constructor that creates {@link WebSocketServerFactory} through
 * its default constructor thus using a default {@link WebSocketPolicy}.
 */
public JettyRequestUpgradeStrategy() {
	this.policy = WebSocketPolicy.newServerPolicy();
}