| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 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 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 40 |
|
public class DownloadFileHandler extends AbstractRequestHandler { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private static final Logger LOGGER = Logger.getLogger(FileUploadRequestHandler.class |
| 44 |
|
.getName()); |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
public static final String URL = "/alfresco/service/api/node/workspace/SpacesStore/fe424d83-d697-401c-b29e-ce1a915d7283/file"; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@see |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 57 |
1
|
@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 |
|
} |