Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Invalid
-
4.4.5
-
None
-
None
-
Important
Description
Got a java.nio.charset.UnsupportedCharsetException error while the header value consist a charset binary (see below). Since the method in org.apache.http.entity.ContentType.get() is hard coded boolean value true for strict param, the method in org.apache.http.entity.ContentType.create() throw the UnsupportedCharsetException.
Can strict param be pass in from a system property, -Dorg.apache.http.entity.contenttype.strict=false? If not set, then set it to true as default.
Content-Type: image/jpeg; charset=binary; name="image_42Colk06m1oO0xfC"
Caused by: java.nio.charset.UnsupportedCharsetException: binary
at java.nio.charset.Charset.forName(Charset.java:531)
at org.apache.http.entity.ContentType.create(ContentType.java:224)
at org.apache.http.entity.ContentType.create(ContentType.java:214)
at org.apache.http.entity.ContentType.get(ContentType.java:299)
at org.apache.http.entity.ContentType.getOrDefault(ContentType.java:346)
at org.apache.http.nio.protocol.AbstractAsyncResponseConsumer.responseReceived(AbstractAsyncResponseConsumer.java:130)
at org.apache.http.impl.nio.client.MainClientExec.responseReceived(MainClientExec.java:315)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseReceived(DefaultClientExchangeHandlerImpl.java:147)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.responseReceived(HttpAsyncRequestExecutor.java:303)
at org.apache.http.impl.nio.client.InternalRequestExecutor.responseReceived(InternalRequestExecutor.java:108)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:255)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:121)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
public static ContentType get(
final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
if (entity == null)
final Header header = entity.getContentType();
if (header != null) {
final HeaderElement[] elements = header.getElements();
if (elements.length > 0)
}
return null;
}
private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) {
Charset charset = null;
for (final NameValuePair param: params) {
if (param.getName().equalsIgnoreCase("charset")) {
final String s = param.getValue();
if (!TextUtils.isBlank(s)) {
try
catch (final UnsupportedCharsetException ex) {
if (strict)
}
}
break;
}
}
return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null);
}