[ 
https://issues.apache.org/jira/browse/COCOON3-75?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13088753#comment-13088753
 ] 

Thorsten Scherler edited comment on COCOON3-75 at 8/22/11 3:44 PM:
-------------------------------------------------------------------

In the abstract class we provide the infrastructure to
In POST: Create a progress object and store it in the session context with a 
unique id. 
In GET: retrieve object and get the current progress

In our code we do the following as implementation: 

public class ProcessService extends AbstractAsyncronService {

public RestResponse doGet() throws Exception {
// we use the class name and a request parameter to make id unique
 setId(this.getClass().getCanonicalName()+name);
 Object progress = getProgress();
 return new TextResponse("{\"progress\":"+progress.toString()+" }", 
"application/json");
}

public RestResponse doPost() throws Exception {
// we use the class name and a request parameter to make id unique
 setId(this.getClass().getCanonicalName()+name);
// execute business logic in background
 super.bidExecutor.execute(this);
// Answer the client, reporting we have done 2%
 return new TextResponse("{\"progress\":2"}", "application/json");
}

// long running action that will be done in a seperate thread
public void run() {
// if we reach here we have done 5% progress
 this.updateProgress(5);
//... do business logic and finish progress with 
 this.updateProgress(100);
}

Our client is based on jquery ui progress bar. Where we post the form 
 $.post('rest/ProcessService', {
            name: input
        }, function(data){
            onSuccess(data);
        }, "json");

and in the onSuccess we invoke a loop to get the status like
 window.progressIntervalId = window.setInterval(function(){
        //Getting current operation progress
        $.get('rest/ProcessService', {
            name: input
        }, function(data){
            //Updating progress
            $("#progressbar").progressbar('value', data.progress);
            //If operation is complete
            if (data.progress == 100) {
                //Clear timer
                window.clearInterval(window.progressIntervalId);
            }
        });
    }, 500);

If you see this useful I can add the class and an example to the cocoon-rest 
module. 

      was (Author: thorsten):
    In the abstract class we provide the infrastructure to
In POST: Create a progress object and store it in the session context with a 
unique id. 
In GET: retrieve object and get the current progress

In our code we do the following as implementation: 

public class ProcessService extends AbstractAsyncronService {

public RestResponse doGet() throws Exception {
 Object progress = getProgress();
 return new TextResponse("{\"progress\":"+progress.toString()+" }", 
"application/json");
}

public RestResponse doPost() throws Exception {
 setId(this.getClass().getCanonicalName()+name);
// execute business logic in background
 super.bidExecutor.execute(this);
// Answer the client, reporting we have done 2%
 return new TextResponse("{\"progress\":2"}", "application/json");
}

// long running action that will be done in a seperate thread
public void run() {
// if we reach here we have done 5% progress
 this.updateProgress(5);
//... do business logic and finish progress with 
 this.updateProgress(100);
}

Our client is based on jquery ui progress bar. Where we post the form 
 $.post('rest/ProcessService', {
            name: input
        }, function(data){
            onSuccess(data);
        }, "json");

and in the onSuccess we invoke a loop to get the status like
 window.progressIntervalId = window.setInterval(function(){
        //Getting current operation progress
        $.get('rest/ProcessService', {
            name: input
        }, function(data){
            //Updating progress
            $("#progressbar").progressbar('value', data.progress);
            //If operation is complete
            if (data.progress == 100) {
                //Clear timer
                window.clearInterval(window.progressIntervalId);
            }
        });
    }, 500);

If you see this useful I can add the class and an example to the cocoon-rest 
module. 
  
> REST and asynchronous server side operations
> --------------------------------------------
>
>                 Key: COCOON3-75
>                 URL: https://issues.apache.org/jira/browse/COCOON3-75
>             Project: Cocoon 3
>          Issue Type: New Feature
>          Components: cocoon-rest
>            Reporter: Thorsten Scherler
>            Assignee: Thorsten Scherler
>         Attachments: AbstractAsyncronService.java
>
>
> I am looking into implementing reporting server side operation progress with 
> jQuery UI Progressbar with our REST framework.
> My basic idea as starting point is to use the GET to ask for the
> progress of the processing and POST to invoke the work which reports the
> progress. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to