I have a JAX-RS server implementation, it uses the following Bean Object to pass request data, lets call it DisputeComment having the following parameters
public class DisputeComment {
private String id;
private String dispute;
private String user;
private String admin;
private String comment;
private String date;
}
This is how my HTTP post request is defined in JAX - RS
@POST
@Path("/disputes/{id}/comments")
@Consumes({ "multipart/mixed;type=application/json;charset=UTF-8" /* , MediaType.APPLICATION_XML */})
@Produces({ "multipart/mixed;type=application/json;charset=UTF-8" /* , MediaType.APPLICATION_XML */ })
GetCommentsResponse addComment(
@PathParam("id")
@Pattern(regexp = "[0-9]+", message = "The id must be a valid number")
@NotNull
String disputeId, DisputeCommentRequest request) throws TechnicalWsFault;
This work really well until now.
But now, I want to adapt this HTTP request to be able to pass along a text file. I have tried somethings, but it doesn't seem to work, here is what I tried. I added an extra parameter InputStream and changed the Consumes annotation.
public class DisputeComment {
private String id;
private String dispute;
private String user;
private String admin;
private String comment;
private String date;
private InputStream inputStream;
}
@Consumes({"multipart/mixed;type=application/json;charset=UTF-8"})
Is this supposed to work? I don't even know how to test this? It would be great if someone can tell me what should I change in my code so that it accepts a file and the rest of the json object? And how do I write the client test code. This is my code which is testing the HTTP post without the upload file feature
WebClient wc = getClient();
DisputeCommentRequest disputeCommentRequest = new DisputeCommentRequest();
disputeCommentRequest.setUser(MockData.GMID);
disputeCommentRequest.setComment(MockData.DISPUTE_COMMENT);
Response res = wc.path("disputes/" + MockData.DISPUTE_ID + "/comments").accept("multipart/mixed;type=application/json;charset=UTF-8").type("multipart/mixed;type=application/json;charset=UTF-8").post(disputeCommentRequest);
res.bufferEntity();