You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by srinivas thallapalli <sr...@gmail.com> on 2013/03/26 13:53:16 UTC
RESTful file upload problem
Hi,
I have RESTful service for file upload as below
@POST
@Path("/fileupload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void fileUpload(MultipartBody body) {
System.out.println("The API is called....");
try {
System.out.println("start post");
List<Attachment> attachments = body.getAllAttachments();
DataHandler dataHandler = attachments.get(0).getDataHandler();
InputStream inputStream = dataHandler.getInputStream();
OutputStream outputStream = new FileOutputStream(new
File("C:/studentservice/new.pdf"));
IOUtils.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
System.out.println("end post");
} catch (Exception e) {
e.printStackTrace();
}
}
I am trying to upload file from Apache HTTP client library as below
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new
HttpPost("http://localhost:8080/StudentService-RS/studentservice/fileupload");
FileBody fileBody = new FileBody(new File("C:\\test\\test.pdf"));
System.out.println(fileBody.getFilename());
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file1", fileBody);
httpPost.setEntity(reqEntity);
httpClient.execute(httpPost);
But this client does not invoking the service. Am I missing something here?
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 26/03/13 17:52, srinivas thallapalli wrote:
> Hi Sergey,
>
> I found CNF for javax.mail.MessagingException in server logs. Adding
> mail.jar to WEB-INF/lib resolves the issue.
>
> My sincere apologies for my stupid mistake .
>
> Thanks for your valuable time.
>
No worries - thanks for getting to the bottom of it
Sergey
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725288.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by srinivas thallapalli <sr...@gmail.com>.
Hi Sergey,
I found CNF for javax.mail.MessagingException in server logs. Adding
mail.jar to WEB-INF/lib resolves the issue.
My sincere apologies for my stupid mistake .
Thanks for your valuable time.
--
View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725288.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 26/03/13 17:26, srinivas thallapalli wrote:
> Hi Sergey,
>
> The problems are, I have few SOP in my service method, those are not
> printing on console (i,e service is not invoked) and attahcment did not
> saved at destination.
>
I need to know what sort of fault is returned, what the runtime logs, etc.
How does a server response look like, add LoggingOutInterceptor please
Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725270.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by srinivas thallapalli <sr...@gmail.com>.
Hi Sergey,
The problems are, I have few SOP in my service method, those are not
printing on console (i,e service is not invoked) and attahcment did not
saved at destination.
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725270.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by Sergey Beryozkin <sb...@gmail.com>.
The log below looks OK, what is the actual error that you are seeing ?
Sergey
On 26/03/13 16:40, srinivas thallapalli wrote:
> Sergey,
>
> I got the following on server console for inbound message but dont see the
> SOP in service method.
> My file content is "Replayfeatureoutput"
>
>
> INFO: Inbound Message
> ----------------------------
> ID: 1
> Address: http://localhost:8080/StudentService-RS/studentservice/fileupload
> Encoding: ISO-8859-1
> Http-Method: POST
> Content-Type: multipart/form-data;
> boundary=g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04
> Headers: {connection=[Keep-Alive], Content-Length=[248],
> content-type=[multipart
> /form-data; boundary=g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04],
> host=[localhost:8080]
> , user-agent=[Apache-HttpClient/4.2.3 (java 1.5)]}
> Payload: --g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04
> Content-Disposition: form-data; name="file1"; filename="test.txt"
> Content-Type: application/octet-stream
> Content-Transfer-Encoding: binary
>
> Replayfeatureoutput
>
>
> --g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04--
>
> --------------------------------------
>
> Thanks
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725264.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: RESTful file upload problem
Posted by srinivas thallapalli <sr...@gmail.com>.
Sergey,
I got the following on server console for inbound message but dont see the
SOP in service method.
My file content is "Replayfeatureoutput"
INFO: Inbound Message
----------------------------
ID: 1
Address: http://localhost:8080/StudentService-RS/studentservice/fileupload
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: multipart/form-data;
boundary=g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04
Headers: {connection=[Keep-Alive], Content-Length=[248],
content-type=[multipart
/form-data; boundary=g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04],
host=[localhost:8080]
, user-agent=[Apache-HttpClient/4.2.3 (java 1.5)]}
Payload: --g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04
Content-Disposition: form-data; name="file1"; filename="test.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Replayfeatureoutput
--g9xG6oAPSinqyX_6FW0BTqLXanfEEEVXG04--
--------------------------------------
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725264.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 26/03/13 16:23, srinivas thallapalli wrote:
> Hi Sergey,
>
> The path is correct. I think you are suspecting the "studentservice" in the
> clientcode URL, studentservice is service class level path.
>
> If I remove the MultipartBody param in service method and commented the
> entity setting part in client, then
> I am able to invoke the service and seen the SOP "The API is called...." .
>
So what exactly happens ? What is reported in the server console window ?
Can you post a one word text file, and add LoggingInInterceptor to
jaxrs;endpoint and tell what is logged ?
Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725261.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: RESTful file upload problem
Posted by srinivas thallapalli <sr...@gmail.com>.
Hi Sergey,
The path is correct. I think you are suspecting the "studentservice" in the
clientcode URL, studentservice is service class level path.
If I remove the MultipartBody param in service method and commented the
entity setting part in client, then
I am able to invoke the service and seen the SOP "The API is called...." .
Thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256p5725261.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: RESTful file upload problem
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 26/03/13 15:53, srinivas thallapalli wrote:
> Hi,
>
>
> I have RESTful service for file upload as below
>
>
> @POST
> @Path("/fileupload")
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public void fileUpload(MultipartBody body) {
> System.out.println("The API is called....");
>
> try {
> System.out.println("start post");
> List<Attachment> attachments = body.getAllAttachments();
> DataHandler dataHandler = attachments.get(0).getDataHandler();
> InputStream inputStream = dataHandler.getInputStream();
as a side note, you can simply do
InputStream is = attachments.get(0).get(InputStream.class)
> OutputStream outputStream = new FileOutputStream(new
> File("C:/studentservice/new.pdf"));
> IOUtils.copy(inputStream, outputStream);
> inputStream.close();
> outputStream.close();
> System.out.println("end post");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
>
>
> I am trying to upload file from Apache HTTP client library as below
>
>
> HttpClient httpClient = new DefaultHttpClient();
> HttpPost httpPost = new
> HttpPost("http://localhost:8080/StudentService-RS/studentservice/fileupload");
>
> FileBody fileBody = new FileBody(new File("C:\\test\\test.pdf"));
>
> System.out.println(fileBody.getFilename());
> MultipartEntity reqEntity = new MultipartEntity();
> reqEntity.addPart("file1", fileBody);
>
> httpPost.setEntity(reqEntity);
>
> httpClient.execute(httpPost);
>
>
> But this client does not invoking the service. Am I missing something here?
>
I guess the path may not be matching ?
Cheers. Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com