| 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.IOException; |
| 22 |
|
import java.io.InputStream; |
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
import org.apache.commons.fileupload.FileItem; |
| 27 |
|
import org.apache.commons.fileupload.FileItemFactory; |
| 28 |
|
import org.apache.commons.fileupload.FileUploadException; |
| 29 |
|
import org.apache.commons.fileupload.RequestContext; |
| 30 |
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
| 31 |
|
import org.apache.commons.fileupload.servlet.ServletFileUpload; |
| 32 |
|
import org.apache.http.HttpEntityEnclosingRequest; |
| 33 |
|
import org.apache.http.HttpException; |
| 34 |
|
import org.apache.http.HttpRequest; |
| 35 |
|
import org.apache.http.HttpResponse; |
| 36 |
|
import org.apache.http.HttpStatus; |
| 37 |
|
import org.apache.http.entity.BasicHttpEntity; |
| 38 |
|
import org.apache.http.protocol.HttpContext; |
| 39 |
|
import org.apache.log4j.Logger; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 45 |
|
public class MULTIPOSTHandler extends AbstractRequestHandler { |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 6 |
Complexity Density: 1.2 |
|
| 50 |
|
private static class RequestWrapper implements RequestContext { |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
private final HttpEntityEnclosingRequest request; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@param |
| 59 |
|
|
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
1
|
public RequestWrapper(final HttpRequest req) {... |
| 62 |
1
|
request = (HttpEntityEnclosingRequest) req; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@see |
| 69 |
|
|
| 70 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 71 |
1
|
public String getCharacterEncoding() {... |
| 72 |
1
|
return request.getEntity().getContentEncoding() == null ? "ISO-8859-1" |
| 73 |
|
: request.getEntity().getContentEncoding().getValue(); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
@see |
| 80 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
1
|
public int getContentLength() {... |
| 82 |
1
|
return (int) request.getEntity().getContentLength(); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
@see |
| 89 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
1
|
public String getContentType() {... |
| 91 |
1
|
return request.getEntity().getContentType().getValue(); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@see |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
1
|
public InputStream getInputStream() throws IOException {... |
| 100 |
1
|
return ((BasicHttpEntity) request.getEntity()).getContent(); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
private static final Logger LOGGER = Logger.getLogger(MULTIPOSTHandler.class |
| 107 |
|
.getName()); |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
private final FileItemFactory factory; |
| 111 |
|
|
| 112 |
|
|
| 113 |
|
private final ServletFileUpload upload; |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
private static final String RESPONSE_FILE_NAME = "stubs/returned_cmis_create.xml"; |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
public static final String URL = "/alfresco/service/api/node/workspace/SpacesStore/fe424d83-d697-401c-b29e-ce1a915d7283/filemulti"; |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 124 |
1
|
public MULTIPOSTHandler() {... |
| 125 |
1
|
factory = new DiskFileItemFactory(); |
| 126 |
1
|
upload = new ServletFileUpload(factory); |
| 127 |
|
|
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
@see |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 138 |
1
|
@Override... |
| 139 |
|
public void handle(final HttpRequest request, final HttpResponse response, |
| 140 |
|
final HttpContext context) throws HttpException, IOException { |
| 141 |
1
|
if ("POST".equals(request.getRequestLine().getMethod())) { |
| 142 |
|
|
| 143 |
1
|
response.setStatusCode(HttpStatus.SC_CREATED); |
| 144 |
1
|
response.addHeader("Content-Type", "application/xml"); |
| 145 |
1
|
List<FileItem> items = new ArrayList<FileItem>(); |
| 146 |
1
|
try { |
| 147 |
1
|
items = upload.parseRequest(new RequestWrapper(request)); |
| 148 |
|
} catch (final FileUploadException e) { |
| 149 |
0
|
LOGGER.error(e); |
| 150 |
0
|
response.setStatusCode(HttpStatus.SC_BAD_REQUEST); |
| 151 |
|
} |
| 152 |
1
|
LOGGER.debug(items.size()); |
| 153 |
1
|
addFileAsBody(response, RESPONSE_FILE_NAME); |
| 154 |
|
} else { |
| 155 |
0
|
response.setStatusCode(HttpStatus.SC_METHOD_FAILURE); |
| 156 |
|
} |
| 157 |
|
} |
| 158 |
|
} |