Wink Multipart REST Service gives 415 Unsupported Media Type

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Wink Multipart REST Service gives 415 Unsupported Media Type

Mihael Schmidt
Hi,

I am trying to get a Multipart REST service running with Wink. I am using Wink 1.4 and Java 7.

    @POST
    @Consumes( MediaTypeUtils.MULTIPART_FORM_DATA )
    public Response upload(BufferedInMultiPart inMultiPart) {
        List<InPart> parts = inMultiPart.getParts();
        ...
    }

But when I call the service I always get 415 Unsupported Media Type.

I test the service with the Wink Client:

public class WinkImagePublisher {

    public static void main(String[] args) throws IOException {

        String serviceUrl = "http://zzz/image";

        File file = new File("/yyy/1727.jpg");
        String fileName = file.getName();

        BufferedOutMultiPart requestEntity = new BufferedOutMultiPart();
        OutPart outPart = new OutPart();
        outPart.setContentType("application/octet-stream; name=" + fileName);
        outPart.setBody(FileUtils.readFileToByteArray(file));
        outPart.addHeader("Content-Transfer-Encoding", "binary");
        outPart.addHeader("Content-Disposition", "form-data; name=\"" + fileName + "\"; filename=\"" + fileName + "\"");
        requestEntity.addPart(outPart);

        String boundary = "simple boundary";
        
        ClientResponse response = new RestClient().resource(serviceUrl)
                        .header("Content-Type", "multipart/form-data; boundary=" + boundary)
                        .post(requestEntity);
        System.out.println(response.getStatusCode());
        System.out.println(response.getMessage());
    }
}


Any idea what I am doing wrong?

Thanx in advance

Mihael

Schulz Gebäudeservice GmbH & Co. KG
Dr.-Max-Ilgner-Straße 17
32339 Espelkamp
Persönlich haftende Gesellschafterin:
Gebäudereinigung Joachim Schulz
Verwaltungsgesellschaft mbH
Telefon: +49 5772 9100 0
Telefax: +49 5772 9100 11
Internet: www.sgbs.de
Geschäftsführer: Joachim und Dirk Schulz, Norbert Kosica
Handelsregister Bad Oeynhausen: HRA 5902, HRB 8591
UST-Id-Nr.: DE 125752702
Reply | Threaded
Open this post in threaded view
|

Re: Wink Multipart REST Service gives 415 Unsupported Media Type

Darin Amos
Because you have the @Consumes annotation, you are saying you will only accept requests with multipart content-type header. You must include the Content-Type header in your request. This allows you to use different methods to service different content-types with the same path.

Cheers


On May 24, 2016, at 3:54 AM, Mihael Schmidt <[hidden email]> wrote:

MULTIPART_FORM_DATA

Reply | Threaded
Open this post in threaded view
|

Re: Wink Multipart REST Service gives 415 Unsupported Media Type

Mihael Schmidt
Hi,

But I explicitly set the Content-Type header:

ClientResponse response = new RestClient().resource(serviceUrl)
                        .header("Content-Type", "multipart/form-data; boundary=" + boundary).post(requestEntity);

... and it does not work.

Mihael


2016-05-24 13:47 GMT+02:00 Darin Amos <[hidden email]>:
Because you have the @Consumes annotation, you are saying you will only accept requests with multipart content-type header. You must include the Content-Type header in your request. This allows you to use different methods to service different content-types with the same path.

Cheers


On May 24, 2016, at 3:54 AM, Mihael Schmidt <[hidden email]> wrote:

MULTIPART_FORM_DATA




--
Mihael Schmidt
Software und System-Entwicklung

Schulz Gebäudeservice GmbH & Co. KG
Dr.-Max-Ilgner-Straße 17
32339 Espelkamp
Persönlich haftende Gesellschafterin:
Gebäudereinigung Joachim Schulz
Verwaltungsgesellschaft mbH
Telefon: +49 5772 9100 0
Telefax: +49 5772 9100 11
Internet: www.sgbs.de
Geschäftsführer: Joachim und Dirk Schulz, Norbert Kosica
Handelsregister Bad Oeynhausen: HRA 5902, HRB 8591
UST-Id-Nr.: DE 125752702