List of usage examples for org.apache.http.entity.mime MIME CONTENT_DISPOSITION
String CONTENT_DISPOSITION
To view the source code for org.apache.http.entity.mime MIME CONTENT_DISPOSITION.
Click Source Link
From source file:neembuu.uploader.uploaders.common.FormBodyPartUtils.java
/** * Create an empty form body part.//from w w w.j a va2 s.c o m * @param name the name of the field. * @param body the content of the field. * @return Return the new empty form body part. * @throws UnsupportedEncodingException */ public static FormBodyPart createEmptyFileFormBodyPart(final String name, StringBody body) throws UnsupportedEncodingException { return new FormBodyPart(name, body) { @Override protected void generateContentDisp(final ContentBody body) { StringBuilder buffer = new StringBuilder(); buffer.append("form-data; name=\"").append(name).append("\""); buffer.append("; filename=\"\""); buffer.append("\n"); addField(MIME.CONTENT_DISPOSITION, buffer.toString()); addField(MIME.CONTENT_TYPE, "application/octet-stream"); } }; }
From source file:com.qwazr.crawler.web.driver.HtmlUnitBrowserDriver.java
@Override public String getContentDisposition() { WebResponse response = getWebResponse(); if (response == null) return null; return response.getResponseHeaderValue(MIME.CONTENT_DISPOSITION); }
From source file:com.qwazr.crawler.web.driver.PhantomJSBrowserDriver.java
@Override public String getContentDisposition() { if (endEntry == null) return null; return getHeader(MIME.CONTENT_DISPOSITION); }
From source file:org.apache.manifoldcf.agents.output.solr.ModifiedHttpMultipart.java
private void doWriteTo(final HttpMultipartMode mode, final OutputStream out, boolean writeContent) throws IOException { ByteArrayBuffer boundary = encode(this.charset, getBoundary()); for (FormBodyPart part : this.parts) { writeBytes(TWO_DASHES, out);//w ww .j av a 2 s.c om writeBytes(boundary, out); writeBytes(CR_LF, out); Header header = part.getHeader(); switch (mode) { case STRICT: for (MinimalField field : header) { writeField(field, this.charset, out); } break; case BROWSER_COMPATIBLE: // Only write Content-Disposition // Use content charset MinimalField cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION); writeField(cd, this.charset, out); String filename = part.getBody().getFilename(); if (filename != null) { MinimalField ct = part.getHeader().getField(MIME.CONTENT_TYPE); writeField(ct, this.charset, out); } break; } writeBytes(CR_LF, out); if (writeContent) { part.getBody().writeTo(out); } writeBytes(CR_LF, out); } writeBytes(TWO_DASHES, out); writeBytes(boundary, out); writeBytes(TWO_DASHES, out); writeBytes(CR_LF, out); }
From source file:org.trancecode.xproc.step.RequestParser.java
private FormBodyPart getContentBody(final XdmNode node, final Processor processor) { final String contentTypeAtt = node.getAttributeValue(XProcXmlModel.Attributes.CONTENT_TYPE); final String encoding = node.getAttributeValue(XProcXmlModel.Attributes.ENCODING); final ContentType contentType = Steps.getContentType(contentTypeAtt, node); final String contentString = getContentString(node, contentType, encoding, processor); final StringBody body; try {//from w ww . j av a2 s. c o m body = new StringBody(contentString, contentType.toString(), Steps.getCharset(contentType.getParameter("charset"))); } catch (final UnsupportedEncodingException e) { throw XProcExceptions.xc0020(node); } final String id = node.getAttributeValue(XProcXmlModel.Attributes.ID); final String description = node.getAttributeValue(XProcXmlModel.Attributes.DESCRIPTION); final String disposition = node.getAttributeValue(XProcXmlModel.Attributes.DISPOSITION); final FormBodyPart bodyPart = new FormBodyPart("body", body) { @Override protected void generateContentDisp(final ContentBody body) { if (disposition != null) { addField(MIME.CONTENT_DISPOSITION, disposition); } } @Override protected void generateTransferEncoding(final ContentBody body) { if (encoding != null) { addField(MIME.CONTENT_TRANSFER_ENC, encoding); } } @Override protected void generateContentType(final ContentBody body) { final StringBuilder buffer = new StringBuilder(); buffer.append(body.getMimeType()); if (body.getCharset() != null) { try { final String testCharset = new ContentType(body.getMimeType()).getParameter("charset"); if (testCharset != null) { final Charset charset = Charset.forName(testCharset); if (!StringUtils.equalsIgnoreCase(charset.displayName(), body.getCharset())) { buffer.append("; charset=").append(body.getCharset().toLowerCase()); } } else { buffer.append("; charset=utf-8"); } } catch (final ParseException | IllegalCharsetNameException e) { throw XProcExceptions.xc0020(node); } } addField(MIME.CONTENT_TYPE, buffer.toString()); } }; if (id != null) { bodyPart.addField("Content-ID", id); } if (description != null) { bodyPart.addField("Content-Description", description); } return bodyPart; }
From source file:com.basistech.rosette.api.HttpRosetteAPI.java
private void setupMultipartRequest(final Request request, final ObjectWriter finalWriter, HttpPost post) throws IOException { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMimeSubtype("mixed"); builder.setMode(HttpMultipartMode.STRICT); FormBodyPartBuilder partBuilder = FormBodyPartBuilder.create("request", // Make sure we're not mislead by someone who puts a charset into the mime type. new AbstractContentBody(ContentType.parse(ContentType.APPLICATION_JSON.getMimeType())) { @Override//www . j ava2s .c o m public String getFilename() { return null; } @Override public void writeTo(OutputStream out) throws IOException { finalWriter.writeValue(out, request); } @Override public String getTransferEncoding() { return MIME.ENC_BINARY; } @Override public long getContentLength() { return -1; } }); // Either one of 'name=' or 'Content-ID' would be enough. partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"request\""); partBuilder.setField("Content-ID", "request"); builder.addPart(partBuilder.build()); AbstractContentBody insBody; if (request instanceof DocumentRequest) { DocumentRequest docReq = (DocumentRequest) request; insBody = new InputStreamBody(docReq.getContentBytes(), ContentType.parse(docReq.getContentType())); } else if (request instanceof AdmRequest) { //TODO: smile? AdmRequest admReq = (AdmRequest) request; ObjectWriter writer = mapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET); byte[] json = writer.writeValueAsBytes(admReq.getText()); insBody = new ByteArrayBody(json, ContentType.parse(AdmRequest.ADM_CONTENT_TYPE), null); } else { throw new UnsupportedOperationException("Unsupported request type for multipart processing"); } partBuilder = FormBodyPartBuilder.create("content", insBody); partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"content\""); partBuilder.setField("Content-ID", "content"); builder.addPart(partBuilder.build()); builder.setCharset(StandardCharsets.UTF_8); HttpEntity entity = builder.build(); post.setEntity(entity); }
From source file:com.basistech.rosette.api.RosetteAPI.java
private void setupMultipartRequest(final DocumentRequest request, final ObjectWriter finalWriter, HttpPost post) {/*from w w w. j av a 2 s .c o m*/ MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMimeSubtype("mixed"); builder.setMode(HttpMultipartMode.STRICT); FormBodyPartBuilder partBuilder = FormBodyPartBuilder.create("request", // Make sure we're not mislead by someone who puts a charset into the mime type. new AbstractContentBody(ContentType.parse(ContentType.APPLICATION_JSON.getMimeType())) { @Override public String getFilename() { return null; } @Override public void writeTo(OutputStream out) throws IOException { finalWriter.writeValue(out, request); } @Override public String getTransferEncoding() { return MIME.ENC_BINARY; } @Override public long getContentLength() { return -1; } }); // Either one of 'name=' or 'Content-ID' would be enough. partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"request\""); partBuilder.setField("Content-ID", "request"); builder.addPart(partBuilder.build()); partBuilder = FormBodyPartBuilder.create("content", new InputStreamBody(request.getContentBytes(), ContentType.parse(request.getContentType()))); partBuilder.setField(MIME.CONTENT_DISPOSITION, "inline;name=\"content\""); partBuilder.setField("Content-ID", "content"); builder.addPart(partBuilder.build()); builder.setCharset(StandardCharsets.UTF_8); HttpEntity entity = builder.build(); post.setEntity(entity); }