You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nivedan Nadaraj <sh...@gmail.com> on 2010/09/16 11:42:57 UTC

Asynchronous File Uploads

Hi All

Has anyone had a requirement to upload huge files in an asynchronous mode? I
want to be able to upload some files which are on avg 4G plus.
I read some posts that wicket does fine with 50 plus megs. Since these are
huge files, we dont want the user to be blocked. Instead was thinking
kicking off a Job that takes these files and then notifies the user.

If wicket application can be configured to upload these files makes it easy
with just the file upload without a-synching, But if there is an elegant
solution can someone share their experiences?

Many thanks
Niv

Re: Asynchronous File Uploads

Posted by "robert.mcguinness" <ro...@gmail.com>.
not sure if this would work, but create another pagemap for your large form
and submit to that (if you are trying to keep everything in the wicket
world).  keep the default pagemap (null) for your short lived requests.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3086723.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: Asynchronous File Uploads

Posted by exl <er...@uwa.edu.au>.
Thanks for the suggestion.  Since our Wicket application is presently a
singular page, I can kind of imagine how this could work assuming the
'iframe' is embedded in the outermost part of the HTML (thus lies outside of
any potential AJAX refreshes by Wicket).  It will also mean that we must
stick to this singular page (i.e. no page changes as part of the user
workflow), otherwise I can imagine the 'iframe' would be lost/reset.

So I'm guessing this is how it would work:
- have a form that submits to the separate servlet being embedded in the
hidden iframe
- the fields for that hidden iframe form correspond directly to what the
user is expected to input via a Wicket form
- upon hitting the submit button on the Wicket form, it copies all the
contents of the fields (using JS?) from the Wicket form to the hidden iframe
form
- finally we trigger the submit on the hidden iframe form using JS

It sounds like it has potential, but not as clean/quick to implement as I
was originally hoping for.  Would anyone perchance have already tried this
strategy and got it working?

Kind Regards,
Eric.

-----

Eric is learning how to use Wicket and enjoying the experience so far...
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3086678.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: Asynchronous File Uploads

Posted by jcgarciam <jc...@gmail.com>.
Use a hidden Iframe to make your upload using the Servlet  approach that
Jeremy describe.

On Fri, Dec 10, 2010 at 2:12 AM, exl [via Apache Wicket] <
ml-node+3081409-1187169087-65838@n4.nabble.com<ml...@n4.nabble.com>
> wrote:

> Hi again,
>
> This is how I interpreted your last post Jeremy (please see attached code
> fragments: TestingServlet.txt<http://apache-wicket.1842946.n4.nabble.com/file/n3081409/TestingServlet.txt>)
>
>
> The new approach appears to trigger the separate servlet, but the problem
> is that it also redirects the browser to the separate servlet's URL (and
> confirms my suspicion that "the Wicket application loses control" as I
> queried in a previous post).
>
> The requirements I'm trying to achieve are:
> - The Wicket application accepts parameters from the user, potentially
> including a file upload.
> - When the user hits submit, some processing needs to be done in the
> background to update the backend (e.g. decode and import the contents of the
> file).
> - However, the user should be allowed to continue doing other things in the
> Wicket application.
> - The user will be notified via email that the background processing has
> been completed and then they can come back to interact with the newly
> created information.
>
> So am I still approaching this correctly?
>
> Thanks in advanced,
> Eric.
>
> ------------------------------
>  View message @
> http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3081409.html
>
> To start a new topic under Apache Wicket, email
> ml-node+1842946-398011874-65838@n4.nabble.com<ml...@n4.nabble.com>
> To unsubscribe from Apache Wicket, click here<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>.
>
>



-- 
Sincerely,
JC (http://www.linkedin.com/in/jcgarciam)
--Anyone who has never made a mistake has never tried anything new.--

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3081888.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: Asynchronous File Uploads

Posted by exl <er...@uwa.edu.au>.
Hi again,

This is how I interpreted your last post Jeremy (please see attached code
fragments: 
http://apache-wicket.1842946.n4.nabble.com/file/n3081409/TestingServlet.txt
TestingServlet.txt )

The new approach appears to trigger the separate servlet, but the problem is
that it also redirects the browser to the separate servlet's URL (and
confirms my suspicion that "the Wicket application loses control" as I
queried in a previous post).

The requirements I'm trying to achieve are:
- The Wicket application accepts parameters from the user, potentially
including a file upload.
- When the user hits submit, some processing needs to be done in the
background to update the backend (e.g. decode and import the contents of the
file).
- However, the user should be allowed to continue doing other things in the
Wicket application.
- The user will be notified via email that the background processing has
been completed and then they can come back to interact with the newly
created information.

So am I still approaching this correctly?

Thanks in advanced,
Eric.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3081409.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: Asynchronous File Uploads

Posted by Jeremy Thomerson <je...@wickettraining.com>.
If you use Wicket to process a request, it is going to synchronize on
the page map (up through 1.4.x).  This means that any request that is
bound to a page (like a form, which is stateful) will result in
synchronization.  The stateful forms in Wicket submit back to
themselves, which means they will always be synchronizing on the
pagemap that contains the page that contains the form.  No other
requests can happen on that pagemap until that one is complete.

So, you can submit to another servlet.  All you need to do is create a
<form action="http://server:port/url-to-your-servlet"
method="post">... etc ... </form>.  You can use Wicket to create this
form tag in your page, although you probably wouldn't use a Form
component for this, because you won't actually be using the processing
that the form component provides.  You would probably just use a
WebMarkupContainer, override onComponentTag, and do tag.put("action",
yourUrl) to put the URL in the tag.

If you don't think that's what you want, please describe the actual
problem a little more.

On Wed, Dec 8, 2010 at 12:32 AM, exl <er...@uwa.edu.au> wrote:
>
> Thanks for the reply.  Sure - I can understand that if the client submits the
> form directly to the separate servlet, then this would achieve the
> "background processing thread" on the server side.
>
> However, wouldn't this mean that the Wicket application loses control in
> that client browser window, since it has been passed over to the separate
> servlet?
>
> The only way I can see this setup working in the sense that a client to be
> able to continue working somewhere else (perhaps on a different page of the
> Wicket application) whilst uploading, would be to open a new browser window
> on the client and have that new window perform the submit to the separate
> servlet.  Our Wicket application is stateful, but hopefully the opening on a
> new window wouldn't cause problems.
>
> So am I on the right track with the above or am I missing something here?
>
> Also, would it still be possible to use Wicket components with a submit form
> posting to the separate servlet? I'm just thinking if I wanted to use
> Wicket's single file upload (demonstrated here:
> http://wicketstuff.org/wicket/upload/single?0), whether that would still be
> possible.
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3077766.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
>
>



-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Asynchronous File Uploads

Posted by exl <er...@uwa.edu.au>.
Thanks for the reply.  Sure - I can understand that if the client submits the
form directly to the separate servlet, then this would achieve the
"background processing thread" on the server side.

However, wouldn't this mean that the Wicket application loses control in
that client browser window, since it has been passed over to the separate
servlet?

The only way I can see this setup working in the sense that a client to be
able to continue working somewhere else (perhaps on a different page of the
Wicket application) whilst uploading, would be to open a new browser window
on the client and have that new window perform the submit to the separate
servlet.  Our Wicket application is stateful, but hopefully the opening on a
new window wouldn't cause problems.

So am I on the right track with the above or am I missing something here?

Also, would it still be possible to use Wicket components with a submit form
posting to the separate servlet? I'm just thinking if I wanted to use
Wicket's single file upload (demonstrated here:
http://wicketstuff.org/wicket/upload/single?0), whether that would still be
possible.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3077766.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: Asynchronous File Uploads

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Tue, Dec 7, 2010 at 8:53 PM, exl <er...@uwa.edu.au> wrote:

>
> Hi.
>
> Ok, I'm trying to go down the path of what I believe is being suggested
> here.  So this is what I have as the servlet so far:
>
> {code}
> public class HelloServlet extends HttpServlet {
>
>        private static final long serialVersionUID = 1L;
>
>        @Autowired
>        private IOurService serviceInst;
>
>        public void init(ServletConfig config) throws ServletException {
>                super.init(config);
>
> SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
>        }
>
>        public void doGet (HttpServletRequest request, HttpServletResponse
> response)
>                throws ServletException, IOException {
>                // get an PrintWriter from the response object
>                PrintWriter out = response.getWriter();
>                out.println("Used doGet -> doPost<br>");
>                doPost(request, response);
>        }
>
>        public void doPost (HttpServletRequest request, HttpServletResponse
> response)
>                throws ServletException, IOException {
>                // get an PrintWriter from the response object
>                PrintWriter out = response.getWriter();
>                // prepare the response's content type
>                response.setContentType("text/html");
>                // get the IP address of the client
>                String remoteAddress = request.getRemoteAddr();
>                // print to the output stream!
>                out.println("Hello there, web surfer from " + remoteAddress
> + "");
>
>                String firstName = request.getParameter("firstName");
>                out.println("First name was: " + firstName);
>
>                // This will handle pre-processing the large file for import
> into the
> database and thus take a long time...
>                serviceInst.testImport(request);
>        }
> }
> {code}
>
> Then I have a Wicket button to submit to this servlet, but it is blocking
> (i.e. not asynchronous):
>
> {code}
> testForm.add(new Button("Upload", new
> StringResourceModel("page.helloServlet", this, null))
>                {
>                        public void onSubmit()
>                        {
>                                ServletWebRequest servletWebRequest =
> (ServletWebRequest) getRequest();
>                                HttpServletRequest request =
> servletWebRequest.getHttpServletRequest();
>                                WebResponse webResponse = (WebResponse)
> getRequestCycle().getOriginalResponse();
>                                HttpServletResponse response =
> webResponse.getHttpServletResponse();
>                                RequestDispatcher dispatcher =
> ((ServletWebRequest)
>
> getRequest()).getHttpServletRequest().getRequestDispatcher(Constants.HELLOSERVLET);
>                                GenericServletResponseWrapper
> wrappedResponse = new
> GenericServletResponseWrapper(response);
>
>                            try {
>                                        log.info("Forwarding request to
> Hello Servlet");
>                                        dispatcher.forward(request,
> wrappedResponse);
>                                    log.info("response from servlet: " +
> new
> String(wrappedResponse.getData()));
>                            } catch (ServletException e) {
>                                throw new RuntimeException(e);
>                            } catch (IOException e) {
>                                throw new RuntimeException(e);
>                            }
>                                log.info("Returned from forward to Hello
> Servlet");
>                        }
>                });
> {code}
>
> So synchronously I can get the servlet to handle my request, which prevents
> the user from doing other things in the Wicket application until it
> returns.
>
> What is the final step to get it handling asynchronously?
>
> Kind Regards,
> Eric.
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3077633.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
>
>
You are doing this:

browser --> submits to Wicket --> submits to servlet

The whole point of writing a servlet was to take Wicket out of that loop.
 You should be doing this:

browser --> submits to servlet

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Re: Asynchronous File Uploads

Posted by exl <er...@uwa.edu.au>.
Hi.

Ok, I'm trying to go down the path of what I believe is being suggested
here.  So this is what I have as the servlet so far:

{code}
public class HelloServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private IOurService serviceInst;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	   
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
	}

	public void doGet (HttpServletRequest request, HttpServletResponse
response) 
		throws ServletException, IOException {
		// get an PrintWriter from the response object
		PrintWriter out = response.getWriter();
		out.println("Used doGet -> doPost<br>");
		doPost(request, response);
	}

	public void doPost (HttpServletRequest request, HttpServletResponse
response) 
		throws ServletException, IOException {
		// get an PrintWriter from the response object
		PrintWriter out = response.getWriter();
		// prepare the response's content type
		response.setContentType("text/html");
		// get the IP address of the client
		String remoteAddress = request.getRemoteAddr();
		// print to the output stream!
		out.println("Hello there, web surfer from " + remoteAddress + "");
		
		String firstName = request.getParameter("firstName");
		out.println("First name was: " + firstName);

		// This will handle pre-processing the large file for import into the
database and thus take a long time...
		serviceInst.testImport(request);
	}
}
{code}

Then I have a Wicket button to submit to this servlet, but it is blocking
(i.e. not asynchronous):

{code}
testForm.add(new Button("Upload", new
StringResourceModel("page.helloServlet", this, null))
		{
			public void onSubmit()
			{
				ServletWebRequest servletWebRequest = (ServletWebRequest) getRequest(); 
				HttpServletRequest request = servletWebRequest.getHttpServletRequest(); 
				WebResponse webResponse = (WebResponse)
getRequestCycle().getOriginalResponse(); 
				HttpServletResponse response = webResponse.getHttpServletResponse(); 
				RequestDispatcher dispatcher = ((ServletWebRequest)
getRequest()).getHttpServletRequest().getRequestDispatcher(Constants.HELLOSERVLET); 
				GenericServletResponseWrapper wrappedResponse = new
GenericServletResponseWrapper(response);

			    try {
					log.info("Forwarding request to Hello Servlet");
					dispatcher.forward(request, wrappedResponse);
				    log.info("response from servlet: " + new
String(wrappedResponse.getData()));
			    } catch (ServletException e) {
			    	throw new RuntimeException(e);
			    } catch (IOException e) {
			    	throw new RuntimeException(e);
			    }
				log.info("Returned from forward to Hello Servlet");
			}
		});
{code}

So synchronously I can get the servlet to handle my request, which prevents
the user from doing other things in the Wicket application until it returns.

What is the final step to get it handling asynchronously?

Kind Regards,
Eric.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p3077633.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: Asynchronous File Uploads

Posted by nivs <sh...@gmail.com>.
Thanks for the time. Will give that a shot. Many thanks (will keep it simple)
Niv 
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p2543362.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: Asynchronous File Uploads

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Thu, Sep 16, 2010 at 11:20 PM, nivs <sh...@gmail.com> wrote:

>
> Thanks mate, I will investigate more on this, but can you elaborate it a
> little bit?
>
> I can think of the following
>
> 1. When the application starts up, the servlet will be loaded up.
> 2. In its init(), I would have to create a process that is more like a
> daemon and waits for it to be requested or invoked.
> 3. From the GUI, actor uploads a file - this has to delegate the request to
> the servlet.Which then does the job
>
> Am i on the right track?
> Cheers
>

You're over-complicating things.  He meant just write a regular ol' servlet.
 Servlets already respond to HTTP requests - there's no daemon junk to worry
about.  Write a servlet, put it in your web.xml and make your upload form
submit to it instead of Wicket.

-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: Asynchronous File Uploads

Posted by nivs <sh...@gmail.com>.
Thanks mate, I will investigate more on this, but can you elaborate it a
little bit? 

I can think of the following

1. When the application starts up, the servlet will be loaded up.
2. In its init(), I would have to create a process that is more like a
daemon and waits for it to be requested or invoked.
3. From the GUI, actor uploads a file - this has to delegate the request to
the servlet.Which then does the job

Am i on the right track?
Cheers

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Asynchronous-File-Uploads-tp2541855p2543316.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: Asynchronous File Uploads

Posted by Igor Vaynberg <ig...@gmail.com>.
use a servlet

-igor

On Thu, Sep 16, 2010 at 2:42 AM, Nivedan Nadaraj <sh...@gmail.com> wrote:
> Hi All
>
> Has anyone had a requirement to upload huge files in an asynchronous mode? I
> want to be able to upload some files which are on avg 4G plus.
> I read some posts that wicket does fine with 50 plus megs. Since these are
> huge files, we dont want the user to be blocked. Instead was thinking
> kicking off a Job that takes these files and then notifies the user.
>
> If wicket application can be configured to upload these files makes it easy
> with just the file upload without a-synching, But if there is an elegant
> solution can someone share their experiences?
>
> Many thanks
> Niv
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org