I am trying to create a POST request containing multipart-form-data that requires NT Credentials . The authentication request causes the POST be retried, and I get an exception of an exception object.
I tried to wrap a MultipartContent object created using BufferedHttpEntity , but does it throw NullPointerExceptions ?
final GenericUrl sau = new GenericUrl(baseURI.resolve("Record")); final MultipartContent c = new MultipartContent().setMediaType(MULTIPART_FORM_DATA).setBoundary("__END_OF_PART__"); final MultipartContent.Part p0 = new MultipartContent.Part(new HttpHeaders().set("Content-Disposition", format("form-data; name=\"%s\"", "RecordRecordType")), ByteArrayContent.fromString(null, "C_APP_BOX")); final MultipartContent.Part p1 = new MultipartContent.Part(new HttpHeaders().set("Content-Disposition", format("form-data; name=\"%s\"", "RecordTitle")), ByteArrayContent.fromString(null, "JAVA_TEST")); c.addPart(p0); c.addPart(p1);
The documentation for ByteArrayContent says
A specific implementation of AbstractInputStreamContent that generates repeatable input streams based on the contents of a byte array.
Performing all parts repeatedly does not solve the problem. Because this code is System.out.println("c.retrySupported() = " + c.retrySupported()); outputs c.retrySupported() = true .
I found the following documentation:
1.1.4.1. Duplicate objects An entity can be repeatable, that is, its contents can be read more than once. This is only possible with (e.g. ByteArrayEntity or StringEntity)
Now I converted my MultipartContent to ByteArrayContent with the media type multi/part-form , extracting the contents of the string and still get the same error!
But I still get the following exception when I try to call request.execute() .
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
So how can I convince ApacheHttpTransport to create a repeatable Entity?
Jarrod roberson
source share