[jboss-user] [JBoss jBPM] - Re: problems using jbpm 3.1 with jboss 4.0.0
rishikesh.dagwal
do-not-reply at jboss.com
Tue Sep 23 05:41:20 EDT 2008
Hi All,
I am getting the same problem with HttpClient 3.1 and fileupload 1.0. I have also tried fileupload 1.2.1. But I am getting the same message as
"the request was rejected because no multipart boundary was found"
Servlet is running on Tomcat 4.1 and I have Standalone java application as client.
I am writing some code for understanding
At client side [HttpClient 3.1]
===============================================
final String CONTENT_TYPE = "Content-type";
| final String MULTI_PART_FORM = "multipart/form-data";
|
| File file = new File( "c:\\sample.txt);
| HttpClient httpClient = new HttpClient();
| PostMethod postMethod = new PostMethod( url );
| postMethod.setRequestHeader( CONTENT_TYPE, MULTI_PART_FORM );
| Part[] parts = { new FilePart( file.getName(), file ) };
| postMethod.setRequestEntity( new MultipartRequestEntity( parts,
| postMethod.getParams() ) );
|
| HttpClientParams params = new HttpClientParams();
| httpClient.getHttpConnectionManager().getParams().setConnectionTimeout( 10000 );
| httpClient.setParams( params );
| httpClient.executeMethod( postMethod );
===============================================
At Server Side[Tomcat + fileupload 1.0]
===============================================
File file = new File( "D:\\UploadedFiles\\sample.txt" );
| DiskFileUpload diskFileUpload = new DiskFileUpload();
| List fileItems = diskFileUpload.parseRequest( request );
| diskFileUpload.setSizeMax( -1 ); // No limit on upload.
| Iterator iterator = fileItems.iterator();
| while( iterator.hasNext() ) {
| FileItem fileItem = ( FileItem )iterator.next();
| if( ! fileItem.isFormField() ) {
| fileItem.write( file );
| }
| }
===============================================
At Server Side[Tomcat + fileupload 1.2.1]
===============================================
File file = new File( "D:\\UploadedFiles\\sample.txt" );
| DiskFileItemFactory factory = new DiskFileItemFactory();
| ServletFileUpload servletFileUpload = new ServletFileUpload( factory );
| List fileItems = servletFileUpload.parseRequest( request );
| servletFileUpload.setSizeMax( -1 ); // No limit on upload.
| Iterator iterator = fileItems.iterator();
| while( iterator.hasNext() ) {
| FileItem fileItem = ( FileItem )iterator.next();
| if( ! fileItem.isFormField() ) {
| fileItem.write( file );
| }
| }
===============================================
If I dont use fileupload api and uses inputstrem of request to save file to disk then I get xml file that has additional text. Both code and file contents are shown below.
Code without fileupload API
===============================================
File file = new File( "D:\\UploadedFiles\\sample.txt" );
| InputStream inputStream = request.getInputStream();
| BufferedInputStream bufferedInputStream = new BufferedInputStream( inputStream );
| byte abyte0[] = new byte[ 4096 ];
| int i;
| FileOutputStream fileOutputStream = new FileOutputStream( file );
|
| while ( ( i = bufferedInputStream.read( abyte0, 0, 4096 ) ) != -1 ) {
| fileOutputStream.write( abyte0, 0, i );
| }
|
| bufferedInputStream.close();
| fileOutputStream.close();
===============================================
Original file
===============================================
0001
| BINARY
| FALSE
| 0002
| BINARY
| FALSE
===============================================
File after upload
===============================================
--modMHyNHWzdAQArk5xE5VmXXJAs-dx_A9Au
| Content-Disposition: form-data; name="file.xml"; filename="file.xml"
| Content-Type: application/octet-stream; charset=ISO-8859-1
| Content-Transfer-Encoding: binary
|
| 0001
| BINARY
| FALSE
| 0002
| BINARY
| FALSE
|
| --modMHyNHWzdAQArk5xE5VmXXJAs-dx_A9Au--
===============================================
any idea why this happening?
Thanks in Advance!
Regards,
Rishikesh Dagwal,
Senior Software Engineer,
Geometric Limited, Pune[India]
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178239#4178239
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4178239
More information about the jboss-user
mailing list