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
10   78   3   10
2   37   0.3   1
1     3  
1    
 
  DownloadFileHandler       Line # 40 10 0% 3 4 69.2% 0.6923077
 
  (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.File;
22    import java.io.FileInputStream;
23    import java.io.IOException;
24    import java.io.InputStream;
25   
26    import org.apache.http.HttpException;
27    import org.apache.http.HttpRequest;
28    import org.apache.http.HttpResponse;
29    import org.apache.http.HttpStatus;
30    import org.apache.http.entity.InputStreamEntity;
31    import org.apache.http.protocol.HttpContext;
32    import org.apache.log4j.Logger;
33   
34    // TODO: Auto-generated Javadoc
35    /**
36    * The Class DownloadFileHandler.
37    *
38    * @author georgosn
39    */
 
40    public class DownloadFileHandler extends AbstractRequestHandler {
41   
42    /** The Constant LOGGER. */
43    private static final Logger LOGGER = Logger.getLogger(FileUploadRequestHandler.class
44    .getName());
45   
46    /** The Constant URL. */
47    public static final String URL = "/alfresco/service/api/node/workspace/SpacesStore/fe424d83-d697-401c-b29e-ce1a915d7283/file";
48   
49    /*
50    * (non-Javadoc)
51    *
52    * @see
53    * net.sf.arestc.testserver.AbstractRequestHandler#handle(org.apache.http
54    * .HttpRequest, org.apache.http.HttpResponse,
55    * org.apache.http.protocol.HttpContext)
56    */
 
57  1 toggle @Override
58    public void handle(final HttpRequest request, final HttpResponse response,
59    final HttpContext context) throws HttpException, IOException {
60  1 if ("GET".equals(request.getRequestLine().getMethod())) {
61  1 try {
62  1 final File f = new File(this.getClass().getClassLoader()
63    .getResource("stubs/db4o-7.4-tutorial-java-1.pdf")
64    .toURI());
65  1 final InputStream is = new FileInputStream(f);
66  1 response.setEntity(new InputStreamEntity(is, f.length()));
67    } catch (final Exception e) {
68  0 LOGGER.debug(e);
69  0 throw new RuntimeException(e);
70    }
71  1 response.setStatusCode(HttpStatus.SC_OK);
72  1 response.addHeader("Content-Type", "application/binary");
73    } else {
74  0 response.setStatusCode(HttpStatus.SC_METHOD_FAILURE);
75    }
76    }
77   
78    }