?
Solved

Testing @MultipartForm RestEasy Rest Based Web Service

Posted on 2011-04-26
16
Medium Priority
?
1,161 Views
Last Modified: 2012-05-11
Hello,

Does anyone know how to test the below @MultipartForm RestEasy Webservice? I'm unsure of how to setup the request to the below service, any ideas?


     
  @POST
    	@Path("/upload")
    	@Consumes("multipart/form-data")
    	public Response create(@MultipartForm FileUploadForm form) 
    	{
    	    System.out.println("test");
    		return null;
    	}


    public class FileUploadForm {
        private byte[] filedata;
    
        public FileUploadForm() {}
    
        public byte[] getFileData() {
            return filedata;
        }
    
        @FormParam("filedata")
        @PartType("application/octet-stream")
        public void setFileData(final byte[] filedata) {
            this.filedata = filedata;
        }
    }

Open in new window

0
Comment
Question by:cgray1223
  • 6
  • 6
  • 2
  • +2
16 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35472850
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35472868
0
 

Author Comment

by:cgray1223
ID: 35472928
thanks for the suggestion yan, but unfortunately that didn't help...
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 92

Expert Comment

by:objects
ID: 35472949
you can httpclient or httpunit to throw requests at it
or try rest-client for a higher level test client
http://code.google.com/p/rest-client/

what exactly do you want to test?
0
 

Author Comment

by:cgray1223
ID: 35472965
I'm unsure how to construct the request for the service.  I want to test it, so I can tell the consumer of the service how to setup the call.  Any ideas?  I tried HttpClient but I don't see how to set the FileIploadForm byte[] data.  It would be ideal if the consumer doesn't have to know about the FileUploadForm object and just passess the byte array in the request.  I think that is the idea of the @MultipartForm.  Thanks for the help!
0
 

Author Comment

by:cgray1223
ID: 35472971
I want to test the service a I posted above, passing in a byte array in the request.  I don't think its possible with the google rest client as that only represents string data.
0
 
LVL 92

Expert Comment

by:objects
ID: 35472983
you can't test the method directly using http, the request and what gets pssed to the method are different things. If you want to test it directly then you would use a unit test instead of a http test
0
 

Author Comment

by:cgray1223
ID: 35472993
If I can't test it how can it be consumed by a mobile app?
0
 
LVL 92

Expert Comment

by:objects
ID: 35472998
sorry I don't understand. How can what be consumed?
0
 

Author Comment

by:cgray1223
ID: 35473014
The below post REST web service...

        @POST
          @Path("/upload")
          @Consumes("multipart/form-data")
          public Response create(@MultipartForm FileUploadForm form)
          {
              System.out.println("test");
                return null;
          }
0
 
LVL 92

Expert Comment

by:objects
ID: 35473031
the web service accepts multipart http requests, you need to send it one
theres an example here for sending one with httpclient http://hc.apache.org/httpcomponents-client-ga/httpmime/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java
0
 

Author Comment

by:cgray1223
ID: 35473078
Thanks objects, I did see that example, but I didn't see a way to pass the byte array as a MultipartEntity part...
0
 
LVL 92

Expert Comment

by:objects
ID: 35473088
easiest is to just have the data you want to send in a file
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 35473092
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35473108
0
 

Expert Comment

by:mbdarla
ID: 36937904
Can somebody help me ,
I have a scenario to upload a image from a html file and the server side is Jax-rs service.

thanks,
darla
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question