use of org.apache.http.entity.mime.MinimalField in project manifoldcf by apache.
the class ModifiedHttpMultipart method doWriteTo.
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);
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);
}
use of org.apache.http.entity.mime.MinimalField in project forest by dromara.
the class HttpclientLogBodyMessage method getBodyString.
@Override
public String getBodyString() {
if (entity == null) {
return null;
}
Header contentTypeHeader = entity.getContentType();
ContentType contentType = new ContentType(contentTypeHeader.getValue());
if (contentType.isMultipart()) {
Class[] paramTypes = new Class[0];
Object[] args = new Object[0];
List<FormBodyPart> parts = null;
try {
Method getMultipartMethod = entity.getClass().getDeclaredMethod("getMultipart", paramTypes);
getMultipartMethod.setAccessible(true);
Object multipart = getMultipartMethod.invoke(entity, args);
if (multipart != null) {
Method getBodyPartsMethod = multipart.getClass().getDeclaredMethod("getBodyParts", paramTypes);
getBodyPartsMethod.setAccessible(true);
parts = (List<FormBodyPart>) getBodyPartsMethod.invoke(multipart, args);
}
} catch (NoSuchMethodException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
Long contentLength = null;
try {
contentLength = entity.getContentLength();
} catch (Throwable th) {
}
if (parts == null) {
String result = "[" + entity.getContentType().getValue();
if (contentLength != null) {
result += "; length=" + contentLength;
}
return result + "]";
} else {
StringBuilder builder = new StringBuilder();
builder.append("[").append(entity.getContentType().getValue());
if (contentLength != null) {
builder.append("; length=").append(contentLength);
}
builder.append("] parts:");
for (FormBodyPart part : parts) {
ContentBody partBody = part.getBody();
MinimalField disposition = part.getHeader().getField("Content-Disposition");
builder.append("\n -- [").append(disposition.getBody());
if (partBody instanceof StringBody) {
Reader reader = ((StringBody) partBody).getReader();
BufferedReader bufferedReader = new BufferedReader(reader);
String value = null;
try {
value = getLogContentFormBufferedReader(bufferedReader);
} catch (IOException e) {
}
builder.append("; content-type=\"").append(((StringBody) partBody).getContentType()).append("\"");
builder.append("; value=\"").append(value).append("\"]");
} else {
Long length = null;
length = partBody.getContentLength();
if (length != null) {
builder.append("; length=").append(length);
}
if (partBody instanceof HttpclientMultipartFileBody) {
builder.append("; content-type=\"").append(((HttpclientMultipartFileBody) partBody).getContentType()).append("\"");
}
builder.append("]");
}
}
return builder.toString();
}
} else if (contentType.isBinary()) {
return "[Binary length=" + entity.getContentLength() + "]";
}
return getLogContentForStringBody(entity);
}
Aggregations