在 Flex 中解析多部分 SOAP 响应?
我有一个 Flex 应用程序,需要通过 JasperReports Server Web 服务 API 从 JasperReports Server 获取报告数据。 Flex Builder 3 在生成 Web 服务使用代码方面做得很好,但有一个例外。 如果您请求目录列表或报告参数的统计,JR Server 将在 SOAP 包装器和 Flex< 中返回纯 XML /em> 解析得很好。 但是,如果您请求报告本身,无论是 XML 还是 PDF 格式,它都会以多部分 MIME 消息的形式返回,其中包含一些描述性< em>XML 作为第一部分,报告(即使报告本身是 XML)作为第二部分。 Flex 不知道如何处理多部分消息,只是抱怨无效的XML。
这是响应的示例。 我当前的策略是进行一些字符串解析并单独管理这些位。 但是Flex有任何内置方法来处理这个问题吗? (我一直找不到。)
------=_Part_2_27050467.1235668849951
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <0F082AF1DAF83B3077B1867B4FC8AAA6>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com">
<runReportReturn xsi:type="xsd:string"><?xml version="1.0" encoding="UTF-8"?>\n<operationResult version="2.0.1">\n\t<returnCode><![CDATA[0]]></returnCode>\n</operationResult>\n
</runReportReturn>
</ns1:runReportResponse>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_2_27050467.1235668849951
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <report>
%PDF-1.4\n%âãÏÓ\n1 0 obj <</Filter/FlateDecode/Length 29>>stream\nx+är\ná26S°00S\bIár\rá\näâ
I have a Flex application that needs to grab reporting data from a JasperReports Server, through the JasperReports Server Web Services API. Flex Builder 3 does a nice job of generating the web services consumption code, with one exception. If you ask for a directory list or an accounting of report parameters, JR Server returns plain XML in the SOAP wrapper and Flex parses it just fine. However, if you ask for a report itself, whether in XML or PDF format, it comes back as a multipart MIME message with some descriptive XML as the first part and the report -- even if the report itself is XML -- as the second part. Flex doesn't know what to do with multipart messages and just complains about invalid XML.
Here's a sample of the response. My current strategy is do some string parsing and manage the bits individually. But does Flex have any built-in methods to handle this? (I've been unable to find any.)
------=_Part_2_27050467.1235668849951
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <0F082AF1DAF83B3077B1867B4FC8AAA6>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:runReportResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://axis2.ws.jasperserver.jaspersoft.com">
<runReportReturn xsi:type="xsd:string"><?xml version="1.0" encoding="UTF-8"?>\n<operationResult version="2.0.1">\n\t<returnCode><![CDATA[0]]></returnCode>\n</operationResult>\n
</runReportReturn>
</ns1:runReportResponse>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_2_27050467.1235668849951
Content-Type: application/pdf
Content-Transfer-Encoding: binary
Content-Id: <report>
%PDF-1.4\n%âãÏÓ\n1 0 obj <</Filter/FlateDecode/Length 29>>stream\nx+är\ná26S°00S\bIár\rá\näâ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要说的只是我所相信的:我可能是错的,因为我还没有尝试过。
我认为你没有太多选择。 Flex HTTPService(或您正在使用的任何服务)只能提供这么多(/或这么少)的数据格式。 请参阅此处。 对于任何自定义流,您必须将其作为
对象
检索并通过您自己的解码器传递。 Flex 似乎不对 MIME 消息进行任何解析,而是依赖(这也是浏览器的典型行为方式)服务器来识别正在传输的内容。 如果服务器只发送文本文件,但将内容类型更改为音频/mpeg,我认为您也会遇到同样的问题。 即使 Flex 确实知道如何处理文本。如果您有时间做这个实验(使用 MIME 类型的视频或任何您喜欢的文本文件),请告诉我们。
同时,您可以查看 SerializationFilter 继续为 PDF 添加新的 MIME 类型!
希望 Flex 4 和 HTTP 多服务。
What I am going to say is only what I believe:I may be wrong since I haven't tried this out.
I don't think you have much choice. Flex HTTPService (or whatever you are using) can offer only so many (/or so few) data formats. See here. For any custom stream you will have to retrieve it as an
object
and pass it through your own decoder. It appears that Flex does not do any parsing of the MIME message but depends on (which is also how browsers behave typically) the server to identify the content that is being transmitted. If the server only sends a text file but changes the content type to sayaudio/mpeg
I think you will have the same problem. Even when Flex does know hot to handle text.If you ever can get around to doing this experiment (with text files as MIME type video or whatever fancies you) do let us know.
Meanwhile, you can take a look at SerializationFilter and go on and add a new MIME type for PDF!
Hopefully, life will be a little easy with Flex 4 and the HTTPMultiService.