users@jersey.java.net

[Jersey] Re: Test Client for Multipart Jersy Rest Service

From: selvakumar netaji <vvekselva.gm_at_gmail.com>
Date: Fri, 24 Aug 2012 22:46:02 +0530

Hi,

Even after changing the url its not working. I just want to know to write
clients for multipart rest services.

On Thu, Aug 23, 2012 at 10:20 PM, Marek Potociar
<marek.potociar_at_oracle.com>wrote:

> From what I see the @Path value on your resource does not match the URI in
> your client. Might that be the cause of your issue?
>
> Marek
>
> On Aug 23, 2012, at 7:06 AM, selvakumar netaji <vvekselva.gm_at_gmail.com>
> wrote:
>
> Hi,
>
>
> I've created a new multipart part rest service and its working fine with
> the html form. The rest service is
>
> @POST
> @Path("/Upload")
> @Produces(MediaType.TEXT_HTML)
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> public String uploadFile(@FormDataParam("file") InputStream
> inputStream,
> @FormDataParam("file") FormDataContentDisposition
> contentDisposition) {
>
> System.out.println("Method Entry");
> System.out.println(contentDisposition.getFileName());
>
>
> String result = "not Success";
> File file = null;
> if (contentDisposition != null
> && contentDisposition.getFileName() != null
> && contentDisposition.getFileName().trim().length() > 0) {
> try {
> file = new File("xx"
> + contentDisposition.getFileName());
> new File("xxx").mkdirs();
> file.createNewFile();
> OutputStream outputStream = new FileOutputStream(file);
> int read = 0;
> byte[] bytes = new byte[1024];
>
> while ((read = inputStream.read(bytes)) != -1) {
> outputStream.write(bytes, 0, read);
> }
> outputStream.flush();
> outputStream.close();
> result = "success";
>
> } catch (Exception e) {
> System.out.println(e.toString());
> }
> }
> System.out.println("Method Exit");
> return result;
>
> }
>
> but the form the client code I'm not able to access the client
>
>
> FileInputStream finStream = new FileInputStream(new File(
> Error.txt"));
>
> FormDataMultiPart part = new FormDataMultiPart().field("file",
> finStream, MediaType.TEXT_HTML_TYPE);
>
> WebResource resource = Client.create().resource(
> "http://localhost:8080/Multipart/Upload<http://localhost:8080/Multipart/rest>
> ");
> String response = resource.type(MediaType.MULTIPART_FORM_DATA_TYPE)
> .post(String.class, part);
> System.out.println(response);
>
>
>
> Did I've made any mistakes.
>
>
>