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);
}
});
}
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, ".");
}
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);
}
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);
}
}
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);
}
Aggregations