I have a RESTEasy Client (3.6.2.Final) implemented with a proxy interface where I want to call a WS to upload a file. The call works fine if I define a fix Content-Type, but fails if I want to set one by myself.
Interface:
@POST
@Path("api/files/upload/")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes()
FileUploadResponse uploadFile(byte[] file);
When instanciating the proxy, I provide a Basic Authentication:
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://..."));
target.register(new BasicAuthentication("username", "password"));
ApiInterface api = target.proxy(ApiInterface.class);
Like this the call works, but the Content-Type in the header is the generic * / *
If I add a HeaderParam like this, the call fails with HTTP 400 (Bad Request):
@POST
@Path("api/files/upload/")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes()
FileUploadResponse uploadFile(byte[] file, @HeaderParam("Content-Type") String contentType);
I've checked the HTTP call and Content-Type appears twice there: once as * / * and another as "application/pdf" (the one I provide when calling uploadFile).
I thought I could remove the @Consumes(), as I'm setting the header myself, but then I get another error:
java.lang.RuntimeException: RESTEASY004590: You must define a @Consumes type on your client method or interface, or supply a default
The Content-Type will be different in each call I make depending on the document I send. Isn't there a way in RESTEasy to define it as a parameter?