CXF client: Reading content of sun.net.www.protocol.http.HttpURLConnection$HttpInputStream?

StackOverflow https://stackoverflow.com/questions/19209071

  •  30-06-2022
  •  | 
  •  

Вопрос

I have rest CXF client that have to download multipart body with a file. I have code like this:

WebClient client = WebClient.create(adress);
client.path(path);
Response response = client.get();
InputStream recivedfile = (InputStream) response.getEntity();

Entity class is in fact: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream. Whern I read form that inputsteam I get:

--uuid:e7c56944-f1c2-4cae-8460-4161b5100f60
Content-Type: application/xml
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
Content-Disposition: attachment; filename="file.xsl"    

<my file>
--uuid:e7c56944-f1c2-4cae-8460-4161b5100f60--

I do not need that whole 'Content' properties and UUID number. What is the best way to read that connection with skipping those things?

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

Решение

I see that your using attachment, hence you can directly use the attachment which as getHandler method which returns file stream.

client.type("multipart/mixed").accept("multipart/mixed");
List<Attachment> atts = new LinkedList<Attachment>();
List<Attachment> atts = client.getCollection(atts, Attachment.class);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top