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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to