gpt4 book ai didi

jaxb - org.apache.camel.InvalidPayloadException : No body available of type error thrown while unMarshalling Jaxb Object

转载 作者:行者123 更新时间:2023-12-02 00:04:41 26 4
gpt4 key购买 nike

我正在通过 Java 将 JAXB 对象发送到 Rabbit MQ。

JAXBContext jaxbContext = JAXBContext.newInstance(MyDTO.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
java.io.StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(deliveryrequest, sw);

ConnectionFactory factory = new ConnectionFactory() ;

//TODO change the hardcoding to the properties file
factory.setHost("rabbitmq.host.net");
factory.setUsername("user");
factory.setPassword("pass");
Channel channel ;
Connection connection;

Map<String, Object> args = new HashMap<String, Object>();
String haPolicyValue = "all";
args.put("x-ha-policy", haPolicyValue);


connection = factory.newConnection();
channel = connection.createChannel();
//TODO change the hardcoding to the properties file
channel.queueDeclare("upload.com.some.queue", true, false, false, args);
//TODO change the hardcoding to the properties file
channel.basicPublish("com.some.exchange", "someroutingKey",
new AMQP.BasicProperties.Builder().contentType("text/plain")
.deliveryMode(2).priority(1).userId("guest").build(),
sw.toString().getBytes());

我在不同的应用程序中使用 Camel 来阅读这篇文章。

    <camel:route id="myRoute">
<camel:from uri="RabbitMQEndpoint" />
<camel:to uri="bean:MyHandler" />
</camel:route>

处理程序正在使用 Camel 端重做的 Jaxb 对象

 @Handler
public void handleRequest(MyDTO dto) throws ParseException {

我收到了我没想到的错误。

Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: byte[] to the required type: com.mycompany.MyDTO with value [B@1b8d3e42
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:181)
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)

感谢解决方案。

最佳答案

你从 rabbit 传来的消息体类型是一个 byte[],你想调用一个 MyDTO 类型的 bean。您的类型不匹配。并且 Camel 找不到可以将消息正文从 byte[] 转换为您的 MyDTO 类型的类型转换器。

Rabbit 的 byte[] 数据是 XML 格式的吗?您是否在 MyDTO 类上有 JAXB 注释,以便您可以使用 JAXB 将其从 xml 编码到 Java?

关于jaxb - org.apache.camel.InvalidPayloadException : No body available of type error thrown while unMarshalling Jaxb Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com