Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public PartialPageUpdate(final Page page)
headerBuffer = new ResponseBuffer(response);
}

/**
* @return returns true if and only if nothing has being added to partial update.
*/
public boolean isEmpty()
{
return prependJavaScripts.isEmpty() && appendJavaScripts.isEmpty() && domReadyJavaScripts.isEmpty() && markupIdToComponent.isEmpty();
}

/**
* Serializes this object to the response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<li><a href="WebSocketBehaviorDemoPage.html">demo with WebSocketBehavior</a></li>
<li><a href="WebSocketResourceDemoPage.html">demo with WebSocketResource</a></li>
<li><a href="WebSocketMultiTabResourceDemoPage.html">demo with WebSocketResource and multiple tabs</a></li>
<li><a href="WebSocketPushUpdateProgressDemoPage.html">Update a component via server-side initiated notifications</a></li>
</ul>
</wicket:link>
</wicket:extend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/
package org.apache.wicket.examples.websocket;

import org.apache.wicket.Session;
import org.apache.wicket.examples.WicketExampleApplication;
import org.apache.wicket.examples.websocket.charts.ChartWebSocketResource;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.https.HttpsConfig;
import org.apache.wicket.protocol.https.HttpsMapper;
import org.apache.wicket.protocol.ws.WebSocketSettings;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.Response;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -50,6 +53,7 @@ public void init()
setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(8080, 8443)));

mountPage("/behavior", WebSocketBehaviorDemoPage.class);
mountPage("/push", WebSocketPushUpdateProgressDemoPage.class);
mountPage("/resource", WebSocketResourceDemoPage.class);
mountPage("/resource-multi-tab", WebSocketMultiTabResourceDemoPage.class);

Expand All @@ -69,7 +73,13 @@ public void init()
getCspSettings().blocking().disabled();
}

@Override
@Override
public Session newSession(Request request, Response response)
{
return new JSR356Session(request);
}

@Override
protected void onDestroy() {
scheduledExecutorService.shutdownNow();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.wicket.examples.websocket;


import java.util.concurrent.ScheduledExecutorService;

import org.apache.wicket.examples.websocket.progress.ProgressUpdater;
import org.apache.wicket.protocol.http.WebSession;
import org.apache.wicket.request.Request;

public class JSR356Session extends WebSession
{
private ProgressUpdater.ProgressUpdateTask progressUpdateTask;

public JSR356Session(Request request)
{
super(request);
}

public ProgressUpdater.ProgressUpdateTask getProgressUpdateTask()
{
return progressUpdateTask;
}

private synchronized void startTask() {
if (progressUpdateTask != null && progressUpdateTask.isRunning())
{
return;
}

JSR356Application application = JSR356Application.get();
ScheduledExecutorService service = application.getScheduledExecutorService();
progressUpdateTask = ProgressUpdater.start(application, getId(), service);
}

public synchronized void startOrCancelTask() {
if (progressUpdateTask != null && progressUpdateTask.isRunning() && !progressUpdateTask.isCanceled())
{
progressUpdateTask.cancel();
}
else
{
startTask();
}
}

public static JSR356Session get() {
return (JSR356Session)WebSession.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.wicket.examples.websocket.charts.WebSocketChart;
import org.apache.wicket.extensions.ajax.AjaxDownloadBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.protocol.https.RequireHttps;
import org.apache.wicket.protocol.ws.api.WebSocketBehavior;
import org.apache.wicket.protocol.ws.api.WebSocketRequestHandler;
import org.apache.wicket.protocol.ws.api.message.ConnectedMessage;
Expand All @@ -36,7 +35,6 @@
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.util.resource.StringResourceStream;

@RequireHttps
public class WebSocketBehaviorDemoPage extends WicketExamplePage
{
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.examples.websocket.charts.ChartWebSocketResource;
import org.apache.wicket.examples.websocket.charts.WebSocketChart;
import org.apache.wicket.protocol.https.RequireHttps;
import org.apache.wicket.protocol.ws.api.BaseWebSocketBehavior;

import java.util.UUID;

@RequireHttps
public class WebSocketMultiTabResourceDemoPage extends WicketExamplePage
{
public WebSocketMultiTabResourceDemoPage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<div wicket:id="progressPanel"></div>
</wicket:extend>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.examples.websocket;

import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.examples.websocket.progress.ProgressBarTogglePanel;
import org.apache.wicket.examples.websocket.progress.ProgressUpdater;

public class WebSocketPushUpdateProgressDemoPage extends WicketExamplePage implements ProgressUpdater.ITaskProgressListener
{
public WebSocketPushUpdateProgressDemoPage()
{
add(new ProgressBarTogglePanel("progressPanel"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.examples.websocket.charts.ChartWebSocketResource;
import org.apache.wicket.examples.websocket.charts.WebSocketChart;
import org.apache.wicket.protocol.https.RequireHttps;
import org.apache.wicket.protocol.ws.api.BaseWebSocketBehavior;

@RequireHttps
public class WebSocketResourceDemoPage extends WicketExamplePage
{
public WebSocketResourceDemoPage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div><a wicket:id="hideShowProgress"></a></div>
<div><a wicket:id="cancelRestartTask"></a></div>
<div wicket:id="progressBar"></div>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.examples.websocket.progress;

import java.util.concurrent.ScheduledExecutorService;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.event.IEvent;
import org.apache.wicket.examples.websocket.JSR356Application;
import org.apache.wicket.examples.websocket.JSR356Session;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.protocol.ws.api.WebSocketBehavior;
import org.apache.wicket.protocol.ws.api.event.WebSocketPushPayload;
import org.apache.wicket.protocol.ws.api.message.ConnectedMessage;

public class ProgressBarTogglePanel extends Panel
{

private int progress = 0;
private boolean showProgress = true;


public ProgressBarTogglePanel(String id)
{
super(id);

setOutputMarkupId(true);

add(new WebSocketBehavior()
{
});

add(new AjaxLink<Void>("hideShowProgress")
{
@Override
public void onClick(AjaxRequestTarget target)
{
showProgress = !showProgress;
target.add(ProgressBarTogglePanel.this);
}
}.setBody((IModel<String>) () -> showProgress ? "Hide progress" : "Show progress"));

add(new AjaxLink<Void>("cancelRestartTask")
{
@Override
public void onClick(AjaxRequestTarget target)
{
JSR356Session.get().startOrCancelTask();
target.add(ProgressBarTogglePanel.this);
}
}.setBody((IModel<String>) () -> {
ProgressUpdater.ProgressUpdateTask progressUpdateTask = JSR356Session.get().getProgressUpdateTask();
return progressUpdateTask != null && progressUpdateTask.isRunning() && !progressUpdateTask.isCanceled()
? "Cancel task" :
"Restart task";
}));

add(new Label("progressBar", (IModel<String>) () -> {
ProgressUpdater.ProgressUpdateTask progressUpdateTask = JSR356Session.get().getProgressUpdateTask();
return progressUpdateTask != null && progressUpdateTask.isRunning()
? "Background Task is " + progress + "% completed"
: "No task is running";
})
{
@Override
protected void onConfigure()
{
super.onConfigure();
setVisible(showProgress);
}
});
}


@Override
public void onEvent(IEvent<?> event)
{
if (event.getPayload() instanceof WebSocketPushPayload)
{
WebSocketPushPayload wsEvent = (WebSocketPushPayload) event.getPayload();
if (wsEvent.getMessage() instanceof ProgressUpdater.ProgressUpdate)
{
ProgressUpdater.ProgressUpdate progressUpdate = (ProgressUpdater.ProgressUpdate)wsEvent.getMessage();
progress = progressUpdate.getProgress();
wsEvent.getHandler().add(this);
}
else if (wsEvent.getMessage() instanceof ProgressUpdater.TaskCanceled)
{
// task was canceled
wsEvent.getHandler().add(this);
}
}
}
}
Loading