创建、传递和解析XML文件
import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; ... //create document Document document = DocumentHelper.createDocument(); Element root = document.addElement( "saleItems" ); Element collectTime = root.addElement("collectTime").addText(saleItems.get(0).getCollectTime()); Element collectMethod = root.addElement("collectMethod").addText(saleItems.get(0).getCollectMethod()); Element si=root.addElement("saleItem"); Element commBarcode=si.addElement("commBarcode").addText(saleItem.getCommBarcode()); return document; ... //send xml to jboss server String saleItemsXml = documents.asXML(); ... import org.springframework.jms.core.JmsTemplate; JmsTemplate jt = (JmsTemplate) SpringBeanFactory.getJmsBean("jmsTemplate"); jt.convertAndSend(saleItemsXml); //receive xml from jboss server JmsTemplate jt = (JmsTemplate) SpringBeanFactory.getJmsBean("jmsTemplate"); jt.setReceiveTimeout(1200000); String s = (String) jt.receiveAndConvert(); Document document = DocumentHelper.parseText(s); //parse xml to object EnterpriseRunning enterpriseRunning = new EnterpriseRunning(); enterpriseRunning.setCollectionDate(saleItemsDocument.selectSingleNode("//saleItems/collectTime").getText()); enterpriseRunning.setAllocatedRate(saleItemsDocument.selectSingleNode("//saleItems/percentage").getText()); List list = saleItemsDocument.selectNodes("//saleItems/saleItem"); Iterator it = list.iterator(); while (it.hasNext()) { Node node = (Node) it.next(); enterpriseRunning.setAreaCode(node.selectSingleNode("areaCode").getText()); break; } /** jboss connection config xml in spring **/ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>ConnectionFactory</value> </property> <property name="jndiTemplate"> <ref bean="jndiTemplate" /> </property> </bean> <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>queue/testQueue</value> </property> <property name="jndiTemplate"> <ref bean="jndiTemplate" /> </property> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory"> <ref bean="connectionFactory" /> </property> <property name="defaultDestination"> <ref bean="destination" /> </property> <property name="messageConverter"> <ref bean="xmlMessageConverter" /> </property> </bean> <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"> <property name="environment"> <props> <prop key="java.naming.factory.initial"> org.jnp.interfaces.NamingContextFactory </prop> <prop key="java.naming.provider.url"> jnp://10.0.50.233:1099 </prop> <prop key="java.naming.factory.url.pkgs"> org.jboss.naming:org.jnp.interfaces </prop> </props> </property> </bean> <bean id="xmlMessageConverter" class="com.benteng.wcqx.commons.business.collection.saleitem.jms.XmlMessageConverter"> </bean> </beans>
相关推荐
Yakamoz 2020-05-26
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
XGQ 2020-07-04
Andrewjdw 2020-05-29
行吟阁 2020-05-18
88491874 2020-04-30
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16