cgray1223
asked on
Testing @MultipartForm RestEasy Rest Based Web Service
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?
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;
}
}
ASKER
thanks for the suggestion yan, but unfortunately that didn't help...
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?
or try rest-client for a higher level test client
http://code.google.com/p/rest-client/
what exactly do you want to test?
ASKER
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!
ASKER
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.
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
ASKER
If I can't test it how can it be consumed by a mobile app?
sorry I don't understand. How can what be consumed?
ASKER
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;
}
@POST
@Path("/upload")
@Consumes("multipart/form-
public Response create(@MultipartForm FileUploadForm form)
{
System.out.println("test")
return null;
}
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
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
ASKER
Thanks objects, I did see that example, but I didn't see a way to pass the byte array as a MultipartEntity part...
easiest is to just have the data you want to send in a file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
I have a scenario to upload a image from a html file and the server side is Jax-rs service.
thanks,
darla
Perhaps this could help:
http://developer.yahoo.com/search/rest.html