- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将消息(字符串)压缩到 zip 文件中,然后将其设置为 Apache Camel 中交换对象的主体,以便下游服务之一(也使用 Apache Camel)能够使用 exchange.getIn().getBody()
方法提取 zip 文件。
第一部分很好,我可以将 zip 文件设置为 body
,但是当我尝试在队列的另一端(Active MQ)检索该文件时,exchange.getIn().getBody(ZipFile.class)
返回 null
。 事实上,body
本身就是null
。
为什么会这样?
我尝试在正文中发送一个普通的字符串,效果很好。文件(ZipFile)未设置,想知道为什么。
这里是代码片段 -
路线 -
from(some_route)
.bean(SomeClass.class, "zipAndSend")
.to("activemq:queue:" + somequeue)
压缩文件 -
public void zipAndSend(Exchange exchange) throws Exception {
String incomingMessage;
try {
incomingMessage = exchange.getIn().getBody().toString();
File file = ZipUtil.createFile(incomingMessage);
String zipFilePath = file.getPath().replace(".xml", ".zip");
ZipFile zipFile = ZipUtil.zipFile(file.getPath(), zipFilePath);
exchange.getOut().setHeader("Compressed", "Y");
exchange.getOut().setHeader("ZipFilePath", zipFilePath);
exchange.getOut().setBody(zipFile);
//the body is set correctly here, so far so good
} catch (Exception e) {
e.printStackTrace(); //other operations
}
}
public static File createFile(String incomingMessaage) {
String fileName = "C:\\Project\\ZipUnzipTest\\incoming.xml";
File file = new File(fileName);
try {
FileUtils.writeStringToFile(file, incomingMessaage);
} catch (Exception e) {
//log.error("Error in Writing Message into file " + fileName, e);
String errorFile = fileName.replace("work", "error");
}
return file;
}
在其他服务(队列末尾)中,我重写了 process()
方法,如下所示,以便能够从压缩文件内的文件中提取消息(字符串)文件。
public void process(Exchange exchange) throws WorkflowDBException,
Exception {
try {
ZipFile zipFile = exchange.getIn().getBody(ZipFile.class); //NPE as body is null
String zipFilePath = exchange.getIn().getHeader("ZipFilePath").toString();
File inFile = ZipUtil.unzipFile(zipFile, "C:\\Project\\ZipUnzipTest\\Output\\WF", true);
String incomingMessage;
incomingMessage = FileUtils.readFileToString(inFile, "UTF-8");
} catch (Exception e) {e.printStackTrace();}
}
依赖关系 -
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
我希望in
和out
空间中的正文内容相同。唉,事实并非如此。
最佳答案
事实证明,Camel(以及其他框架)可以很好地处理bytes[]
。我将 ZipFile
转换为 字节数组
,并用它来设置 exchange
对象的 body
。
incomingMessage = exchange.getIn().getBody().toString();
File file = ZipUtil.createFile(incomingMessage);
String zipFilePath = file.getPath().replace(".xml", ".zip");
ZipFile zipFile = ZipUtil.zipFile(file.getPath(), zipFilePath);
messageData = FileUtils.readFileToByteArray(new File(zipFilePath));
exchange.getOut().setHeader("Compressed", "Y");
exchange.getOut().setHeader("ZipFilePath", zipFilePath);
exchange.getOut().setBody(messageData);
在阅读时,我使用 ZipInputStream
从 ByteArrayInputStream
获取 Zip Entry
。
byte [] bytes = exchange.getIn().getBody(byte[].class);
ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(bytes));
try {
StringBuilder s = new StringBuilder();
StringBuilder temp = new StringBuilder();
byte[] buffer = new byte[1024];
int read = 0;
ZipEntry entry;
while ((entry = zipStream.getNextEntry())!= null) {
while ((read = zipStream.read(buffer, 0, 1024)) >= 0) {
s.append(new String(buffer, 0, read));
}
temp = temp.append(s);
s.setLength(0);
}
return temp.toString();
} catch (Exception e) {
e.printStackTrace();
}
是的,就是这样。仍然愿意接受其他方法来解决这个问题:)
关于java - Apache Camel - Exchange.getIn().getBody(ZipFile.class) 返回 NULL 但 Exchange.getOut().setBody(zipfile) 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57388695/
有没有办法使用 EWS Managed API 搜索 Exchange 以查找所有文件夹中的所有电子邮件。我正在使用 FindItems API 调用——但这似乎要求将搜索限制在单个文件夹中。
我已经看到这个问题被问了好几次,但到目前为止,答案都非常机械化和令人失望: EWS 与 EAS 有什么区别? 现在,大多数网站都给出以下内容:“一个是移动设备协议(protocol),另一个是 Web
我们将 Exchange 集成到我们的 CRM(日记和电子邮件)中;我们通过 SQL 2008 服务器中的 CRL 函数完成了这项工作,这些函数处理所有身份验证以及与 Exchange 2007 We
我想为交换服务器创建插件。 Exchange 服务器是否为此提供任何 SDK。如果有人知道,请告诉我。 最佳答案 此链接应为您提供可用内容的概览。 https://msdn.microsoft.com
我刚开始使用EWS(Exchange Web服务),并且正在寻找一个简单的示例,该示例演示如何发送带有附件的电子邮件。我搜索了一个示例,但找不到简单明了的示例。我找到了有关如何发送电子邮件但不发送带有
我在一个客户站点工作,并通过网络邮件连接到他们的 Exchange 2000 服务器。我正在运行 Outlook 2007,并通过 HTTP 连接到我的公司 Exchange 2007。 是否有任何方
从 Exchange 2007 开始,安装 Exchange 时不再安装 MAPI。在这些系统上 this install如果您想使用 MAPI,则除 Exchange 外还需要。 我的软件依赖于 E
交换 2010。 我已经阅读了有关 Exchange 中的通知订阅、邮箱事件和 EWS 的信息,据我所知,通知客户端应用程序必须始终与 EWS 保持连接。我对吗? 我的任务看起来很简单 - 当消息到达
我试图弄清楚节流政策如何影响 EWS。 对于 EWS,我们有以下值: EWSMaxSubscription:模拟用户完成的事件订阅数。 EWSMaxConcurrency:单个客户端可能执行的并发连接
我在 Exchange 2010 SP2 服务器上使用 EWS 我似乎找不到任何命令/文档来检索交换服务器中所有用户(邮箱/别名)的完整列表 这个问题已经问了好几次了,但我还没有看到任何答案 谢谢 最
我正在使用 CalendarItemType View 来检索日历项目。我唯一关心的项目是我创建的项目,我知道它们都是每周重复出现的项目。我能够获取每个单独的事件,并从其中任何一个中获取重复出现的主项
我从 Exchange 2007 服务器的地址开始: user@domain.exchangeserver.org 我尝试发送自动发现请求,如 MSDN 中所述. 我尝试使用 TechNet Whit
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 12 年前。 Improve thi
这是我所拥有的... 我有一个跟踪条形码类型标签的程序。我可以在数据库中选择一个项目并为它打印一个标签。我正在添加向我们的 Exchange 服务器 (2007 SP1) 上的特定收件箱发送电子邮件并
我的公司正在开发一个桌面和移动电子邮件客户端的项目,该客户端可以连接到不同的邮件服务器,用户或服务器管理员只需进行最少的配置。我们希望能够支持 Exchange,但经过一些研究后我意识到有许多问题需要
我正在尝试调用 GetUserAvailabilityRequest 来自不遵守夏令时的南非标准时间,但是,TimeZone 元素需要 StandardTime 和 DaylightTime 子元素,
我想在我的交换服务器上收到电子邮件时运行脚本。我真的没有关于如何实现这一点的好方向。我已经用 VB 编写了脚本并在 outlook 上对其进行了测试。我错误地认为您可以像在 Outlook 中一样从
我在使用 Exchange 2010 Web 服务 (EWS) 创建全天事件约会时遇到了麻烦。 根据现有要求,创建全天事件约会对象需要指定开始和结束时间(即 10/20/2011 12:00:00 A
是否有任何公共(public) Exchange 服务器(模拟器)可用于测试/试验我的 Exchange Web 服务实现? 最佳答案 我怀疑没有免费的东西。创建自己的 VM 会容易得多。您将需要具有
我正在尝试使用最新的 Exchange Web 服务 DLL,但是当我搜索我的硬盘时,我看到了许多版本的 Microsoft.Exchange.WebServices.DLL,最新的是版本 14.0.
我是一名优秀的程序员,十分优秀!