java - apache httpclient - 如何反序列化响应
问题描述
我正在通过 HttpClient 调用外部 Web 服务,但在转换我得到的响应时遇到了问题。这是一个像这样的mtom响应:
--MIMEBoundaryurn_uuid_5CF5D04EE84169F28B1567408992661 内容类型:application/xop+xml;字符集=UTF-8;type="text/xml" Content-Transfer-Encoding: 二进制 Content-ID: <0.urn:uuid:5CF5D04EE84169F28B1567408992662@apache.org>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns3:executeResponse xmlns:ns2="http://www.myservice.com/bside/plugins/webservices/bigdata/types" xmlns:ns3="http://www.myservice.com/bside/plugins/webservices/bigdata/ws/THCommand/">
<returnCode>WS000000</returnCode>
<returnCodeDescription>Processing completed successfully.</returnCodeDescription>
<systemInfo>
<ns2:userId>111000</ns2:userId> <ns2:rsId>619344</ns2:rsId>
<ns2:sessionId>550211</ns2:sessionId>
</systemInfo>
<responseFile>
<ns2:name>052015_619344_XXXX_YYYY_1567408989171.zip.crypt</ns2:name>
<ns2:content>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:urn:uuid:5CF5D04EE84169F28B1567408992663@apache.org"/>
</ns2:content>
</responseFile>
</ns3:executeResponse>
</soapenv:Body>
</soapenv:Envelope>
--MIMEBoundaryurn_uuid_5CF5D04EE84169F28B1567408992661 内容类型:应用程序/八位字节流内容传输编码:二进制内容ID:
���-��[�-O� �g/Ü?��s�7��82��!x�ګEï¿½ï ¿½|^��.c׋���ء�~��!�CI6�C_��]o��ux�y�lï ¿½ï¿½ï¿½X���Ӯ����C�i��7c���<��*�"-/� ,x��l�/0�J�(�d?�=�>��BXP���O��}ï¿½ï¿½ï¿½ï ¿½`���T��;
我试图在这里和那里遵循建议,我想出了这个测试类https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes/api/src/test/java/org/ apache/cxf/attachment/AttachmentDeserializerTest.java
但不幸的是它不起作用或更好,我忘记做一些很容易的事情。
这是我为它编写的一些代码:
HttpResponse 响应 = client.execute(httpPost); HttpEntity 实体 = response.getEntity();
String ct = response.getLastHeader("Content-Type").toString().replace("Content-Type: ", "");
String responseContent = null;
if (entity != null) {
responseContent = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8.name());
MessageImpl msg = new MessageImpl();
Exchange exchange = new ExchangeImpl();
msg.setExchange(exchange);
InputStream is = new ByteArrayInputStream(responseContent.getBytes());
msg.put(Message.CONTENT_TYPE, ct);
msg.setContent(InputStream.class, is);
AttachmentDeserializer deserializer = new AttachmentDeserializer(msg);
deserializer.initializeAttachments();
InputStream attBody = msg.getContent(InputStream.class);
String attMimeType = msg.getAttachmentMimeType();
Collection<Attachment> atts = msg.getAttachments();
Iterator<Attachment> itr = atts.iterator();
Attachment a = itr.next();
InputStream attIs = a.getDataHandler().getInputStream();
}
不幸的是,集合中没有元素......我的目标是处理元素,但我陷入了这种转换。预先感谢您的支持。
解决方案
推荐阅读
- c - 三向快速排序 C
- .net - Microsoft.CodeDom.Providers.DotNetCompilerPlatform 和 Microsoft.Net.Compilers 有什么区别?
- java - 带有 where 子句的 Group By 的休眠条件
- python - 如何在 Python 中用小数(如货币)制作数字
- hadoop - Hive Query 无法识别表达式规范中 'select' 'max' '(' 附近的输入
- vba - 如何将单元格条目复制到 VBA 中的下一个空行?
- google-apps-script - 谷歌表格复制工作表并重命名
- python - python中的打印功能仅在将数字作为参数而不是变量发送时才有效
- ggplot2 - 有没有办法表明一个组的平均值为零?
- java - 从 Java SE 应用程序连接 EC2 上的 Mysql 数据库