Search in sources :

Example 1 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class SendPayloadWithContextTest method before.

@Before
public void before() {
    tester = new WicketTester();
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(tester.getApplication());
    webSocketSettings.setSendPayloadExecutor(new WebSocketSettings.SameThreadExecutor() {

        @Override
        public void run(Runnable command) {
            context.set(true);
            super.run(command);
            context.set(false);
        }
    });
}
Also used : WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) WicketTester(org.apache.wicket.util.tester.WicketTester) Before(org.junit.Before)

Example 2 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class WebSocketTesterProcessorTest method configureRequest.

protected void configureRequest(String[] allowedDomains, String[] origins) {
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    WebSocketConnectionOriginFilter connectionFilter = new WebSocketConnectionOriginFilter(Arrays.asList(allowedDomains));
    webSocketSettings.setConnectionFilter(connectionFilter);
    MockHttpServletRequest request = tester.getRequest();
    for (String origin : origins) {
        request.addHeader("Origin", origin);
    }
    request.addParameter("resourceName", TestWebSocketResource.TEXT);
    request.addParameter(WebRequest.PARAM_AJAX_BASE_URL, ".");
}
Also used : WebSocketConnectionOriginFilter(org.apache.wicket.protocol.ws.api.WebSocketConnectionOriginFilter) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings)

Example 3 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class WebSocketTester method broadcast.

/**
 * Broadcasts/pushes a message to specific web socket connection
 *
 * @param application
 *          The application where the web socket connection is registered
 * @param sessionId
 *          The id of the http session with which the web socket connection is registered
 * @param key
 *          The key with which the web socket connection is registered
 * @param message
 *          The message to broadcast/push
 */
public void broadcast(Application application, String sessionId, IKey key, IWebSocketPushMessage message) {
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    WebSocketPushBroadcaster broadcaster = new WebSocketPushBroadcaster(webSocketSettings.getConnectionRegistry());
    ConnectedMessage wsMessage = new ConnectedMessage(application, sessionId, key);
    broadcaster.broadcast(wsMessage, message);
}
Also used : WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) WebSocketPushBroadcaster(org.apache.wicket.protocol.ws.api.WebSocketPushBroadcaster) ConnectedMessage(org.apache.wicket.protocol.ws.api.message.ConnectedMessage)

Example 4 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class JSR356Application method init.

@Override
public void init() {
    super.init();
    scheduledExecutorService = Executors.newScheduledThreadPool(1);
    setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(8080, 8443)));
    mountPage("/behavior", WebSocketBehaviorDemoPage.class);
    mountPage("/resource", WebSocketResourceDemoPage.class);
    getSharedResources().add(ChartWebSocketResource.NAME, new ChartWebSocketResource());
    if (System.getenv("OPENSHIFT_APP_NAME") != null) {
        // OpenShift uses special proxy for WebSocket connections
        // https://blog.openshift.com/paas-websockets/
        final WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(this);
        webSocketSettings.setPort(8000);
        webSocketSettings.setSecurePort(8443);
    }
}
Also used : HttpsMapper(org.apache.wicket.protocol.https.HttpsMapper) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) HttpsConfig(org.apache.wicket.protocol.https.HttpsConfig) ChartWebSocketResource(org.apache.wicket.examples.websocket.charts.ChartWebSocketResource)

Example 5 with WebSocketSettings

use of org.apache.wicket.protocol.ws.WebSocketSettings in project wicket by apache.

the class WebSocketMessageBroadcastHandler method respond.

@Override
public void respond(IRequestCycle requestCycle) {
    final Application application = Application.get();
    final Runnable action = new Runnable() {

        @Override
        public void run() {
            if (pageId != AbstractWebSocketProcessor.NO_PAGE_ID) {
                Page page = (Page) Session.get().getPageManager().getPage(pageId);
                page.send(application, Broadcast.BREADTH, payload);
            } else {
                ResourceReference reference = new SharedResourceReference(resourceName);
                IResource resource = reference.getResource();
                if (resource instanceof WebSocketResource) {
                    WebSocketResource wsResource = (WebSocketResource) resource;
                    wsResource.onPayload(payload);
                } else {
                    throw new IllegalStateException(String.format("Shared resource with name '%s' is not a %s but %s", resourceName, WebSocketResource.class.getSimpleName(), Classes.name(resource.getClass())));
                }
            }
        }
    };
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(application);
    webSocketSettings.getSendPayloadExecutor().run(action);
}
Also used : SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) Page(org.apache.wicket.Page) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings) SharedResourceReference(org.apache.wicket.request.resource.SharedResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Application(org.apache.wicket.Application) IResource(org.apache.wicket.request.resource.IResource)

Aggregations

WebSocketSettings (org.apache.wicket.protocol.ws.WebSocketSettings)9 Application (org.apache.wicket.Application)2 WebSocketPushBroadcaster (org.apache.wicket.protocol.ws.api.WebSocketPushBroadcaster)2 Executor (org.apache.wicket.protocol.ws.concurrent.Executor)2 IApplication (org.apache.openmeetings.IApplication)1 Page (org.apache.wicket.Page)1 ChartWebSocketResource (org.apache.wicket.examples.websocket.charts.ChartWebSocketResource)1 MockHttpServletRequest (org.apache.wicket.protocol.http.mock.MockHttpServletRequest)1 HttpsConfig (org.apache.wicket.protocol.https.HttpsConfig)1 HttpsMapper (org.apache.wicket.protocol.https.HttpsMapper)1 IWebSocketConnection (org.apache.wicket.protocol.ws.api.IWebSocketConnection)1 WebSocketConnectionOriginFilter (org.apache.wicket.protocol.ws.api.WebSocketConnectionOriginFilter)1 ConnectedMessage (org.apache.wicket.protocol.ws.api.message.ConnectedMessage)1 IWebSocketConnectionRegistry (org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry)1 PageIdKey (org.apache.wicket.protocol.ws.api.registry.PageIdKey)1 IResource (org.apache.wicket.request.resource.IResource)1 ResourceReference (org.apache.wicket.request.resource.ResourceReference)1 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)1 PackageTextTemplate (org.apache.wicket.util.template.PackageTextTemplate)1 WicketTester (org.apache.wicket.util.tester.WicketTester)1