Hi Lotfi,

I've just had a look at the Restlet FileUpload extension. It is extremely
straightforward code and I don't think the performance difference that you
notice can come from this part. To convince yourself, you could try to do
some direct speed tests on it, bypassing all remaining code (for example
saving the reloading your multipart form from a file).

However, as each request to your Restlet calls the handle(Request, Response)
method, I would strongly recommend to separate your initialization code from
the actual processing code. You can initialize either in the constructor or
in the start() method.

Your handle() method should only contain this logic after the refactoring:

  private void handle(Request request, Response response) {
        List items = upload.parseRequest(request);
 
        //récupérer le xml et l'image
        for (final Iterator it = items.iterator(); it.hasNext(); ) {    
                FileItem fi = (FileItem)it.next();
                if(fi.getFieldName().equals("xml")){
                  xml_text=fi.getString();
                UTEUtils.parserFluXml(xml_text);//parser le flux xml
                }
                else{
                        //sauvegarder l'image
                    ImageUtils.saveImage(fi,imageName);
                }
        }

Of course, you will need to add a "RestletFileUpload upload" member variable
and check for potential multi-threading issues with the parent FileUpload
class, eventually synchronizing some parts of the code.

In the end, this should improve (significantly?) the observed response
times. If not, then the difference might come from the ServerServlet adapter
that let you run you Restlet application from within Tomcat, even though our
tests doesn't show any significant impact.

Best regards,
Jerome  

> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de lotfi elgherbi
> Envoyé : vendredi 11 mai 2007 18:53
> À : [email protected]
> Objet : Re: Problem of upload of file
> 
> Hi Jerome ,
> 
> thank you for reply,
> my servlet container is tomcat 5.2.0 and I use spring also
> 
> public class UTERestlet extends Restlet {
>   private void handle(Request request, Response response) {
>    try{       
>       //recuperer le context de Spring
>       SpringContextspringContext=(SpringContext)PrototypeApplication.
> getProtoContext().getAttributes().get("SpringContext");
>       //récupérer l'interface des services UTE
>        UTEServiceInterface uteService =[UTEServiceInterface)
> springContext.getBean("UTEService");
> 
>       String xml_text="";
>       
>       //upload de l'image
> 
> 
>       DiskFileItemFactory factory = new DiskFileItemFactory();
>         factory.setSizeThreshold(1000240);
> 
>       RestletFileUpload upload = new RestletFileUpload(factory);
>       List items = upload.parseRequest(request);
> 
>       //récupérer le xml et l'image
>       for (final Iterator it = items.iterator(); it.hasNext(); ) {    
>               FileItem fi = (FileItem)it.next();
>               if(fi.getFieldName().equals("xml")){
>                       xml_text=fi.getString();
>                       
> UTEUtils.parserFluXml(xml_text);//parser le flux xml
> 
>               }
>               else{
>                       //sauvegarder l'image
>                    ImageUtils.saveImage(fi,imageName);
>               }
>       }
>                       
>       }catch(Exception e){
>         e.printStackTrace();
>       }
>   }
> }
> 
> 
> This code is very well but it is 5 times as long as the following code
> 
> protected void doPost(HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException, IOException {
>    try {
> 
> 
>       DiskFileItemFactory factory = new DiskFileItemFactory();
>       factory.setSizeThreshold(1000240);
>       ServletFileUpload upload = new ServletFileUpload(factory);
>       List items = upload.parseRequest(request);
>       //récupérer le xml et l'image
>       for (final Iterator it = items.iterator(); it.hasNext(); ) {    
>               FileItem fi = (FileItem)it.next();
>               if(fi.getFieldName().equals("xml")){
>                       xml_text=fi.getString();                
>                       
> UTEUtils.parserFluXml(xml_text);//parser le flux xml
> 
>               }
>               else{
>                       //sauvegarder l'image
>                      ImageUtils.saveImage(fi,imageName);
>               }
>       }
> 
> 
> 
>     }catch(Exception e){
>       e.printStackTrace();
>     }
> }
> 
> 
> thanks,
> 
> lotfi
> 

Reply via email to