On Tue, 2010-05-25 at 16:57 +0200, MOSSE Franck wrote: > Hi, > > I am facing an issue while I am trying to send a Multipart Entity with the > http client nio api. I received the UnsupportedOperationException exception. > > I am using the following libraries: httpcore-nio-4.0.1; httpmime-4.0.1 and > apache-mime4j-0.6. > > The multipart message is built with the following code sample: > > BasicHttpEntityEnclosingRequest httppost = new > BasicHttpEntityEnclosingRequest( "POST", "http://localhost:8080 "); > > // Get stream from file > FileInputStream fileStream = new FileInputStream( new File( args[0])); > InputStreamBody streamBody = new InputStreamBody( fileStream, > "image/png", args[0]); > > // Add a string > StringBody comment = new StringBody( "A binary file of some kind", > Charset.forName("UTF-8")); > > MultipartEntity reqEntity = new MultipartEntity(); > reqEntity.addPart("comment", comment); > reqEntity.addPart("bin", streamBody); > > httppost.setEntity( reqEntity); > > > The http request is sent using the http client nio api. > > It seems that somewhere the multipart entity is encapsulated in a > NHttpEntityWrapper class that calls the getContent() method of the entity at > its construction. > The problem is that the MultipartEntity throws the > UnsupportedOperationException and no code is provided at the moment for this > method. > > Can you tell me if it is planned to support this functionality in the future ? > Do you known any kind of workaround to solve this problem ? > > Thank you for your help. > Franck. >
Franck You are trying to use HttpCore NIO transport which is based on the non-blocking I/O model with a content library based on the classic (blocking) I/O model. These things just do not mix well. HttpMime API is inherently blocking. It simply cannot be used in a fully asynchronous mode. You basically have two options: (1) buffer content in memory or (2) use a thread pool executor. Both options are described here: http://hc.apache.org/httpcomponents-core-4.0.1/tutorial/html/nio.html#d0e2081 The question you should be asking yourself whether the use of NIO in your particular case makes any sense or not. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
