You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by fachhoch <fa...@gmail.com> on 2016/04/21 22:07:06 UTC
open connection to async servlet and initiate wicket ajax request,
results ComponentNotFoundException
I am trying to add server push using javascript longpolling and async
servlet,
a self invoking javascript function makes ajax request to this async
servlet , there by keeping the connection open, when this connection is
open and a wicket ajax request is initiated, its sometimes failing with
ComponentNotFoundException?
I assume this is due to wicket ajax channels, how to keep an ajax connection
open and also run other wicket ajax requests concurrently ?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
Yes, Thank you . I will try websocket.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674416.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Apr 25, 2016 at 3:27 PM, fachhoch <fa...@gmail.com> wrote:
> Hi Martin,
> Before adding the new request I find the previous request and call complete
> on that and if user closes browser or logs out , the request times out and
> gets closed. There will be just one request per user at any given time.
>
>
>
> asyncContexts.stream().filter(as->as.getRequest().getParameter("name").equals(name)).collect(Collectors.toList()).forEach(ac->ac.complete());
>
There is no need to collect. You could use Stream#forEach(Consumer)
>
> I tried wicket-atmosphere sometime before faced issues with tomcat and
> wicket version, websocket I saw the wicket example , It shows use container
> specific filter which causes issues with portability.
>
Wicket Native WebSocket also has -javax module which uses JSR-356 and is
tested on Tomcat 7/8/8.5/9, Jetty 9 and WildFly 8/9/10
>
> Async serevlet, long polling javascript is simple, plain.
>
True!
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674413.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
Hi Martin,
Before adding the new request I find the previous request and call complete
on that and if user closes browser or logs out , the request times out and
gets closed. There will be just one request per user at any given time.
asyncContexts.stream().filter(as->as.getRequest().getParameter("name").equals(name)).collect(Collectors.toList()).forEach(ac->ac.complete());
I tried wicket-atmosphere sometime before faced issues with tomcat and
wicket version, websocket I saw the wicket example , It shows use container
specific filter which causes issues with portability.
Async serevlet, long polling javascript is simple, plain.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674413.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
One thing that I don't understand in your code: how the async servlet is
notified to release its resources (async contexts and executor) when the
user navigates to another Wicket page?
Have you considered using Wicket Native WebSocket or Wicket-Atmosphere
instead of this custom solution ?
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Fri, Apr 22, 2016 at 11:11 PM, fachhoch <fa...@gmail.com> wrote:
> I enabled log info org.apache.wicket.protocol.http.RequestLogger, logs show
> different url in case of error.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674379.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
I enabled log info org.apache.wicket.protocol.http.RequestLogger, logs show
different url in case of error.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674379.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
This error happens only when deployed to staging and not in development
box, I cannot run this in debug mode to figure out why only sometimes it
fails, is it possible to debug this through logs?
I tried log debug for org.apache.wicket.request.IRequestHandler but nothing
shows up, is there a way to plugin Custom ListenerInterfaceRequestHandler?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674373.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
MessagePanelPolling function is called through a wicket page, the wicket
page has an active ajax call to the async servlet,
public BasePage(PageParameters pageParameters) {
super(pageParameters);
add(new MessageCheckBehaviour());
}
static class MessageCheckBehaviour extends MyJqueryBehaviour{
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
//response.render(OnLoadHeaderItem.forScript("MessagePanel.longPoll('"+UserContextHolder.getUser().getInfUser().getSysUserId().toString()+"')"));
response.render(JavaScriptHeaderItem.forReference(JS_FILE));
}
static final PackageResourceReference JS_FILE= new
JavaScriptResourceReference(MyJqueryBehaviour.class, "messagePolling.js");
}
Async servlet waits on a blocking queue , a new item in queue causes
thread to checks all registered AsyncContext's and if match found, write
to the aynscontext response.
public class MessageNotificationServlet extends HttpServlet {
static Logger logger= Logger.getLogger(MessageNotificationServlet.class);
private Queue<AsyncContext> asyncContexts = new
ConcurrentLinkedQueue<AsyncContext>();
static BlockingQueue<String> messages = new LinkedBlockingQueue<String>();
ExecutorService executorService;
public static void addMessage(String msg){
try{
messages.add(msg);
}catch(Exception e){
throw new RuntimeException(e);
}
}
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
executorService=Executors.newSingleThreadExecutor();
executorService.submit(new Runnable() {
@Override
public void run() {
while(true){
try{
String message = messages.take();
for(AsyncContext asyncContext :asyncContexts ){
try{
if(asyncContext.getRequest().getParameter("name").trim().equals(message)){
String
paramName=asyncContext.getRequest().getParameter("name").trim();
String
timestamp=asyncContext.getRequest().getParameter("timestamp").trim();
try{
PrintWriter printWriter=asyncContext.getResponse().getWriter();
printWriter.println("new_message");
printWriter.flush();
asyncContext.complete();
}catch(Exception e){
logger.debug(" failed writing to async "+paramName +"
"+timestamp );
logger.error((" async failed "+paramName +" "+timestamp),e);
}
}
}catch (Exception e) {
asyncContexts.remove(asyncContext);
logger.debug(" error with asyncontext ",e);
}
}
}catch(Exception e){
logger.debug(" error in msg check thread ",e);
}
}
}
});
}
@Override
public void destroy() {
super.destroy();
messages.clear();
asyncContexts.clear();
executorService.shutdownNow();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response)
throws ServletException, IOException {
String name=req.getParameter("name");
AsyncContext asyncContext=req.startAsync();
asyncContexts.stream().filter(as->as.getRequest().getParameter("name").equals(name)).collect(Collectors.toList()).forEach(ac->ac.complete());
asyncContext.getRequest().setAttribute("start_time", new Date());
asyncContext.addListener(new AsyncListener() {
@Override
public void onTimeout(AsyncEvent event) throws IOException {
logger.debug(" timeout occuered for "
+event.getAsyncContext().getRequest().getParameter("name") +"
"+event.getAsyncContext().getRequest().getParameter("timestamp")+"
"+event.getAsyncContext().getRequest().getAttribute("start_time"));
event.getAsyncContext().complete();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
logger.debug(" onstart for "
+event.getAsyncContext().getRequest().getParameter("name") +"
"+event.getAsyncContext().getRequest().getParameter("timestamp") +"
"+event.getAsyncContext().getRequest().getAttribute("start_time"));
}
@Override
public void onError(AsyncEvent event) throws IOException {
logger.debug(" error occuered for "
+event.getAsyncContext().getRequest().getParameter("name") +"
"+event.getAsyncContext().getRequest().getParameter("timestamp") +"
"+event.getAsyncContext().getRequest().getAttribute("start_time"));
asyncContexts.remove(event.getAsyncContext());
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
logger.debug(" completed "
+event.getAsyncContext().getRequest().getParameter("name")+"
"+event.getAsyncContext().getRequest().getParameter("timestamp") +"
"+event.getAsyncContext().getRequest().getAttribute("start_time"));
asyncContexts.remove(event.getAsyncContext());
}
});
asyncContext.setTimeout(TimeUnit.MINUTES.toMillis(60));
asyncContexts.add(asyncContext);
}
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674362.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by Martin Grigorov <mg...@apache.org>.
This code doesn't use Wicket.Ajax JavaScript APIs so the Ajax Channels are
not involved at all.
Please show us the Java code of the servlet. How does it use the page ?
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Thu, Apr 21, 2016 at 10:38 PM, fachhoch <fa...@gmail.com> wrote:
> This is the javascript file rendered by wicket page, this opens a
> connection to the async servlet, page has several ajax links, clicking on
> ajaxlinks updates dom, and sometimes wicket throws
> ComponentNotFoundException.
> Initially tried calling MessagePanel.longPoll(data) from wicket page with
> OnDomReadyHeaderItem, no success, then try selfinvoking function assuming
> will work but the same exception.
>
>
> (function MessagePanelPolling (){
> $.ajax({
> url: "/myapp/app/user/userId",
> success: function(data){
> if(data){
> MessagePanel.longPoll(data);
> }
> },
> type: "GET",
> data: {timestamp: new Date().getTime()}
> });
> })();
>
> var MessagePanel ={
> cancelPolling:null,
> newMsg:function(){
> var markup='<div> You have a new message </div>'
> var my_dialog =$(markup).dialog({
> position:'right top'
> ,title:'New Message'
> });
> my_dialog.dialog('widget').zIndex(25000);
> }
> ,longPoll:function(channel){
> $.ajax({
> url: "/myapp/cometmsg",
> success: function(data){
> if(data){
>
> if('new_message'===data.trim()){
>
> MessagePanel.newMsg();
> }
> }
> },
> error: function(err) {
> MessagePanel.cancelPolling='true';
> console.log(" long poll error
> "+err);
> },
> type: "GET",
> data: {name:channel,timestamp: new
> Date().getTime()}
> ,complete:function(){
>
> if(MessagePanel.cancelPolling!='true'){
>
> MessagePanel.longPoll(channel)
> }
> }
> });
> }
> }
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674359.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by fachhoch <fa...@gmail.com>.
This is the javascript file rendered by wicket page, this opens a
connection to the async servlet, page has several ajax links, clicking on
ajaxlinks updates dom, and sometimes wicket throws
ComponentNotFoundException.
Initially tried calling MessagePanel.longPoll(data) from wicket page with
OnDomReadyHeaderItem, no success, then try selfinvoking function assuming
will work but the same exception.
(function MessagePanelPolling (){
$.ajax({
url: "/myapp/app/user/userId",
success: function(data){
if(data){
MessagePanel.longPoll(data);
}
},
type: "GET",
data: {timestamp: new Date().getTime()}
});
})();
var MessagePanel ={
cancelPolling:null,
newMsg:function(){
var markup='<div> You have a new message </div>'
var my_dialog =$(markup).dialog({
position:'right top'
,title:'New Message'
});
my_dialog.dialog('widget').zIndex(25000);
}
,longPoll:function(channel){
$.ajax({
url: "/myapp/cometmsg",
success: function(data){
if(data){
if('new_message'===data.trim()){
MessagePanel.newMsg();
}
}
},
error: function(err) {
MessagePanel.cancelPolling='true';
console.log(" long poll error "+err);
},
type: "GET",
data: {name:channel,timestamp: new Date().getTime()}
,complete:function(){
if(MessagePanel.cancelPolling!='true'){
MessagePanel.longPoll(channel)
}
}
});
}
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357p4674359.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: open connection to async servlet and initiate wicket ajax
request, results ComponentNotFoundException
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Show us some code please.
It is not very clear what you are doing.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Thu, Apr 21, 2016 at 10:07 PM, fachhoch <fa...@gmail.com> wrote:
> I am trying to add server push using javascript longpolling and async
> servlet,
> a self invoking javascript function makes ajax request to this async
> servlet , there by keeping the connection open, when this connection is
> open and a wicket ajax request is initiated, its sometimes failing with
> ComponentNotFoundException?
> I assume this is due to wicket ajax channels, how to keep an ajax
> connection
> open and also run other wicket ajax requests concurrently ?
>
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/open-connection-to-async-servlet-and-initiate-wicket-ajax-request-results-ComponentNotFoundException-tp4674357.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>