问题描述
我正在尝试开发一个ule流,该queue流从JMS队列中获取字符串形式的xml并将其转换为POJO.我正在使用JAXB批注定义xml与类属性之间的映射.下面是在JMS队列上作为字符串接收的示例xml.
I am trying to develop a mule flow which takes a xml in the form of a string from a JMS queue and converts it into a POJO. I am using JAXB annotations to define the mappings between the xml and the class attributes. Below is the sample xml that is received on the JMS queue as a string.
<FCUBS_NOTIFICATION xmlns="http://fcubs.ofss.com/notify/NOTIF_UP_TRANSACTION">
<FCUBS_NOTIF_HEADER>
<MSGID>9132820000357947</MSGID>
</FCUBS_NOTIF_HEADER>
</FCUBS_NOTIFICATION>
我的POJO类如下:
package com.bean;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name="FCUBS_NOTIFICATION")
public class Notification {
private String MSGID;
public String getMSGID() {
return MSGID;
}
@XmlElement(name="MSGID")
public void setMSGID(String mSGID) {
MSGID = mSGID;
}
}
我在com.bean软件包中有一个jaxb.index文件,该文件仅包含一个bean
I have a jaxb.index file in the com.bean package consisting of only one bean
Notification
我的m子流配置文件如下:
My mule flow config file is as below:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd">
<spring:beans>
<spring:bean name="myJaxb" class="javax.xml.bind.JAXBContext" factory-method="newInstance">
<!-- colon-separated (:) list of package names where JAXB classes exist -->
<spring:constructor-arg value="com.bean"/>
</spring:bean>
</spring:beans>
<jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/>
<flow name="JMS-exampleFlow1" doc:name="JMS-exampleFlow1">
<jms:inbound-endpoint queue="NotificationQueue" connector-ref="Active_MQ" doc:name="JMS"/>
<logger message="Payload after picking message from queue is #[message.payload]" level="INFO" doc:name="Logger"/>
<mulexml:xml-to-object-transformer returnClass="com.bean.Notification" doc:name="XML to Object"/>
<logger level="INFO" doc:name="Logger" message="Payload after xml to object transformation is #[message.payload]"/>
</flow>
</mule>
我正在使用Mule Studio进行开发,以下是我得到的错误-
I am using Mule Studio for development and below is the error I get -
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'jms-example' +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO 2013-11-27 16:19:44,225 [[jms-example].JMS-exampleFlow1.stage1.02] org.mule.api.processor.LoggerMessageProcessor: Payload after picking message from queue is <FCUBS_NOTIFICATION xmlns="http://fcubs.ofss.com/notify/NOTIF_UP_TRANSACTION"><FCUBS_NOTIF_HEADER><MSGID>9132820000357947</MSGID></FCUBS_NOTIF_HEADER></FCUBS_NOTIFICATION>
ERROR 2013-11-27 16:19:44,227 [[jms-example].JMS-exampleFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException). Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException)
com.thoughtworks.xstream.mapper.DefaultMapper:56 (null)
2. FCUBS_NOTIFICATION (com.thoughtworks.xstream.mapper.CannotResolveClassException). Message payload is of type: String (org.mule.api.transformer.TransformerMessagingException)
org.mule.transformer.AbstractTransformer:139 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.mapper.CannotResolveClassException: FCUBS_NOTIFICATION
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
这里有什么我想念的吗?
Is there anything I am missing here ?
谢谢.
推荐答案
xml-to-object-transformer中的序列化/反序列化是通过XStream完成的,因此此时JAXB无关紧要.
The serialization/deserialization in the xml-to-object-transformer is done through XStream, so JAXB won't matter at that point.
您需要一个别名:
<mulexml:xml-to-object-transformer returnClass="com.bean.Notification" doc:name="XML to Object">
<mulexml:alias name="FCUBS_NOTIFICATION" class="com.bean.Notification"/>
</mulexml:xml-to-object-transformer>
这篇关于尝试将xml字符串转换为java对象时出现CannotResolveClassException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!