Hi Gabriella, 

I've created an example for you to use:

https://github.com/liweinan/try-resteasy/blob/multipart/src/main/java/net/bluedash/resteasy/multipart/MultipartClient.java


I'm using Apache Http Client as client-side codes. I've also found some issues 
about RESTEasy's client API, but I need to do more analysis before make any 
conclusions. 

You can check all the codes: 

git clone git://github.com/liweinan/try-resteasy.git

And then:

git checkout -b multipart remotes/origin/multipart

                                                                                
                                                                          

-- 
Weinan Li
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Monday, January 21, 2013 at 12:23 PM, Gabriella Turek wrote:

> Hello, I need a little help on making requests from a desktop client to a 
> RESTEasy service. The service works great with a web form, but this is not 
> the intended client, I need to implement client in a desktop application. 
> I've followed examples on the web, but I still cannot get my client to work:
> 
> I am using RESTEasy version 2.3.5.Final 
> I can use the service from the a form, but not from a client.
> 
> Relevant code:  
> 
> My form POJO: 
> 
>     public class FileUploadForm { 
>   
>   
>       @FormParam("file")
>       @PartType(MediaType.APPLICATION_OCTET_STREAM)
>       private byte[] data;
>   
>       @FormParam("user")
>       @PartType(MediaType.TEXT_PLAIN)
>       private String user;
>   
>       @FormParam("password")
>       @PartType(MediaType.TEXT_PLAIN)
>       private String password;
>   
>       @FormParam("filename")
>       @PartType(MediaType.TEXT_PLAIN)
>       private String filename;
> 
>       public FileUploadForm() {} 
> 
>       public byte[] getData() { 
>        return data;
>       }
> 
>       public void setData(final byte[] data) { 
>           this.data = data;
>       }
> 
>       public String getUser() { 
>         return user;
>       }
> 
>       public void setUser(String user) { 
>         this.user = user;
>       }
> 
>       public String getPassword() { 
>         return password;
>       }
> 
>       public void setPassword(String password) { 
>         this.password = password;
>       }
> 
>        public String getFilename() { 
>         return filename;
>       }
> 
>       public void setFilename(String filename) { 
>         this.filename = filename;
>       }
> 
>     }  
> 
> My service side method definition: 
> 
>     @POST 
>     @Path("/upload")
>     @Consumes("multipart/form-data")
>     @Produces(MediaType.TEXT_PLAIN)
>     public Response add(@MultipartForm FileUploadForm form);
> 
> My client side interface: 
> 
>     public interface MultipartClient  
>     {
>       @PUT
>       @Path("/upload")
>       @Consumes("multipart/form-data")
>       @Produces(MediaType.TEXT_PLAIN)
>       public Response add(@MultipartForm FileUploadForm form);
>     }
> 
> My test code: 
>      
>     MultipartClient client = ProxyFactory.create(MultipartClient.class, 
> BASEURL + URL_ROOT);
>     FileUploadForm upload = new FileUploadForm();
>     upload.setUser("bob");
>     upload.setPassword("xyzzxy");
>     upload.setFilename("file.zip");
>     String fileToUpload = "file.zip"
>     FileInputStream fis = new FileInputStream(fileToUpload);    
>     byte[] fileData = IOUtils.toByteArray(fis);
>     upload.setData(fileData);
>     Response response = client.add(upload);
>     System.out.println("Response status: "  + response.getStatus());
>     System.out.println("Response message: "  + response.getEntity());
>     assertTrue(HttpResponseCodes.SC_OK == response.getStatus());
> 
> 
> I get a response code 405 from the server. I am at my wits' end. 
>  
> 
> 
> 
> 
> 
> -- 
> Please consider the environment before printing this email.
> NIWA is the trading name of the National Institute of Water & Atmospheric 
> Research Ltd. 
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. SALE $99.99 this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122412
> 
> _______________________________________________
> Resteasy-users mailing list
> Resteasy-users@lists.sourceforge.net 
> (mailto:Resteasy-users@lists.sourceforge.net)
> https://lists.sourceforge.net/lists/listinfo/resteasy-users
> 
> 


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to