Вопрос

I'm sending multipart data with jersey-client and jersey client generates boundary itself.
And my problem is that the consuming server parses incoming TCP stream as raw data, using his own constant value as boundary. Sounds weird, I know :) But I can't do something this server side.
So I need to set boundary myself, but can't find any suitable method for it in FormDataMultiPart. How can I solve it? Is it even possible?

Это было полезно?

Решение

Make your method return Response and set the media type of the response yourself:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(
        @FormDataParam("part") String s,
        @FormDataParam("part") FormDataContentDisposition d) {

    final Map<String, String> parameters = Maps.newHashMap();
    parameters.put("boundary", "myboundary");

    final MediaType mediaType = new MediaType("multipart", "form-data", parameters);

    return Response
            .ok(s + ":" + d.getFileName(), mediaType)
            .build();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top