Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart7.png 67% of files have more coverage
12   76   4   12
4   41   0.33   1
1     4  
1    
 
  FileUploadRequestHandler       Line # 39 12 0% 4 6 64.7% 0.64705884
 
  (1)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6    *
7    * ARESTC is free software: you can redistribute it and/or modify it under the
8    * terms of the Lesser General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10    * version.
11    *
12    * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY
13    * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14    * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15    *
16    * You should have received a copy of the Lesser General Public License along
17    * with ARESTC. If not, see <http://www.gnu.org/licenses/>.
18    */
19    package net.sf.arestc.testserver;
20   
21    import java.io.FileOutputStream;
22    import java.io.IOException;
23    import java.io.InputStream;
24    import java.io.OutputStream;
25   
26    import org.apache.commons.io.IOUtils;
27    import org.apache.http.HttpEntityEnclosingRequest;
28    import org.apache.http.HttpException;
29    import org.apache.http.HttpRequest;
30    import org.apache.http.HttpResponse;
31    import org.apache.http.HttpStatus;
32    import org.apache.http.protocol.HttpContext;
33    import org.apache.log4j.Logger;
34   
35    // TODO: Auto-generated Javadoc
36    /**
37    * The Class FileUploadRequestHandler.
38    */
 
39    public class FileUploadRequestHandler extends AbstractRequestHandler {
40   
41    /** The Constant LOGGER. */
42    private static final Logger LOGGER = Logger.getLogger(FileUploadRequestHandler.class
43    .getName());
44   
45    /** The Constant URL. */
46    public static final String URL = "/alfresco/service/api/node/workspace/SpacesStore/fe424d83-d697-401c-b29e-ce1a915d7283/content";
47   
48    /* (non-Javadoc)
49    * @see net.sf.arestc.testserver.AbstractRequestHandler#handle(org.apache.http.HttpRequest, org.apache.http.HttpResponse, org.apache.http.protocol.HttpContext)
50    */
 
51  1 toggle @Override
52    public void handle(final HttpRequest request, final HttpResponse response,
53    final HttpContext context) throws HttpException, IOException {
54  1 if ("PUT".equals(request.getRequestLine().getMethod())) {
55  1 if (request instanceof HttpEntityEnclosingRequest) {
56  1 try {
57  1 final InputStream is = ((HttpEntityEnclosingRequest) request)
58    .getEntity().getContent();
59  1 final OutputStream os = new FileOutputStream("response.pdf");
60  1 IOUtils.copy(is, os);
61    } catch (final Exception e) {
62  0 LOGGER.debug(e);
63  0 throw new RuntimeException(e);
64    }
65  1 response.setStatusCode(HttpStatus.SC_OK);
66  1 response.addHeader("Content-Type", "text/plain");
67   
68    } else {
69  0 response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
70    }
71    } else {
72  0 response.setStatusCode(HttpStatus.SC_METHOD_FAILURE);
73    }
74    }
75   
76    }