use of javax.servlet.http.Part in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method resolvePartArrayArgument.
@Test
public void resolvePartArrayArgument() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContentType("multipart/form-data");
MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
request.addPart(part1);
request.addPart(part2);
request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
webRequest = new ServletWebRequest(request);
Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
assertTrue(result instanceof Part[]);
Part[] parts = (Part[]) result;
assertEquals(2, parts.length);
assertEquals(parts[0], part1);
assertEquals(parts[1], part2);
}
use of javax.servlet.http.Part in project camel by apache.
the class AttachmentHttpBinding method populateAttachments.
@Override
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
try {
Collection<Part> parts = request.getParts();
for (Part part : parts) {
DataSource ds = new PartDataSource(part);
Attachment attachment = new DefaultAttachment(ds);
for (String headerName : part.getHeaderNames()) {
for (String headerValue : part.getHeaders(headerName)) {
attachment.addHeader(headerName, headerValue);
}
}
message.addAttachmentObject(part.getName(), attachment);
}
} catch (Exception e) {
throw new RuntimeCamelException("Cannot populate attachments", e);
}
}
use of javax.servlet.http.Part in project zxing by zxing.
the class DecodeServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Collection<Part> parts;
try {
parts = request.getParts();
} catch (IllegalStateException ise) {
log.info("File upload was too large or invalid");
errorResponse(request, response, "badimage");
return;
} catch (IOException ioe) {
log.info(ioe.toString());
errorResponse(request, response, "badurl");
return;
}
Part fileUploadPart = null;
for (Part part : parts) {
if (part.getHeader(HttpHeaders.CONTENT_DISPOSITION) != null) {
fileUploadPart = part;
break;
}
}
if (fileUploadPart == null) {
log.info("File upload was not multipart");
errorResponse(request, response, "badimage");
} else {
log.info("Decoding uploaded file " + fileUploadPart.getSubmittedFileName());
try (InputStream is = fileUploadPart.getInputStream()) {
processStream(is, request, response);
}
}
}
use of javax.servlet.http.Part in project wildfly by wildfly.
the class MultipartFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
Part part = req.getPart("file");
byte[] data = new byte[100];
int c;
InputStream inputStream = part.getInputStream();
while ((c = inputStream.read(data)) > 0) {
resp.getOutputStream().write(data, 0, c);
}
}
use of javax.servlet.http.Part in project undertow by undertow-io.
the class HttpServletRequestImpl method loadParts.
private void loadParts() throws IOException, ServletException {
final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (parts == null) {
final List<Part> parts = new ArrayList<>();
String mimeType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
if (mimeType != null && mimeType.startsWith(MultiPartParserDefinition.MULTIPART_FORM_DATA)) {
FormData formData = parseFormData();
if (formData != null) {
for (final String namedPart : formData) {
for (FormData.FormValue part : formData.get(namedPart)) {
parts.add(new PartImpl(namedPart, part, requestContext.getOriginalServletPathMatch().getServletChain().getManagedServlet().getMultipartConfig(), servletContext, this));
}
}
}
} else {
throw UndertowServletMessages.MESSAGES.notAMultiPartRequest();
}
this.parts = parts;
}
}
Aggregations