我想从JMS中检索一些数据,过滤它们并发送到REST服务器。当我解组这些数据时,我得到一个错误:
java.lang.IllegalArgumentException:读取器不能为空
位于com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshalleImpl.unmarshall0(UnmarshallerImpl.java:370)位于com.sun.xml.bind.v2.runtime.ummarshaller.unmarsharlerImpl.unmashall(Unmarhallerimpl.java:356)位于org.apache.acamel.convertor.jaxb.JaxbDataFormat.unmarsshall(JaxbDataFormat.java:300)org.apache.camel.processer.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryError Handler.java:471)位于org.apache.camal.impl.engineer.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutior.java:193(DefaultReactiveExecutor.java:64)位于org.apache.acamel.processer.Pipeline.process(Pipeline.java:184),位于org.apache.cacamel.impl.engineer.CamelInternalProcessor.processe(CamelInternalProcesser.java:399),位于org.apache.cacamel.inmpl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcesserAwaitManager.java:83)(AsyncProcessorSupport.java:41),位于org.apache.acamel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:132),位于org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:736),位于org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessage ListenerContiner.java:674),位于org.springfframework.jms.listener.AbtractPollingMessageListenerCContainer.doReceiveAndExecute(Abstract PollingMessageListerContainr.java:318)(AbstractPollingMessageListenerContainer.java:257)位于org.springframework.jms.listener.DefaultMessageListenerCContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerCainer.java:1237)位于org.spring framework.jms.listener.DDefaultMessageListenerContainer$Async MessageListenerinvoker.executeOngoingLoop(DefaultMessageLister.java:1227)org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1120)位于java.base/java.util.concurrent.ThreadPoolExecutior.runWorker(ThreadPoolExecutior.java:1128)位于java.basi/java.util/concurrent.TthreadPoolExecutitor$Worker.run(ThreadPoolExecutor.java:628)位于java.base/java.lang.Thread.run(Thread.java:829)14:46:44.399[骆驼(camel-1)线程#1-JmsConsumer[MATERIALS_ENRICHED]]调试org.apache.camel.processor。管道-消息交换失败:因此断开管道进行交换:exchange[3917DB1BA45A384-00000000013]异常:java.lang.IllegalArgumentException:reader不能为null
14:46:44.399[Camel(Camel-1)thread#1-JmsConsumer[MATERIALS_ENRICHED]]WARN org.apache.Camel.component.jms。EndpointMessageListener-执行JMS消息侦听器失败。原因:[org.apache.camel.RuntimeCamelException-java.lang.IllegalArgumentException:reader不能为空]
我发现在JaxbDataFormat类的unmarshalhtml" target="_blank">方法中创建了空的读取器:
public Object unmarshal(Exchange exchange, InputStream stream) throws IOException {
try {
XMLStreamReader xmlReader;
if (this.needFiltering(exchange)) {
xmlReader = (XMLStreamReader)this.typeConverter.convertTo(XMLStreamReader.class, exchange, this.createNonXmlFilterReader(exchange, stream));
} else {
xmlReader = (XMLStreamReader)this.typeConverter.convertTo(XMLStreamReader.class, exchange, stream);
}
...
}
}
我怀疑我错过了pom.xml文件中的一些东西:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.release11</groupId>
<artifactId>toRest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId >
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.16.2</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.16.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb-starter</artifactId>
<version>2.25.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>3.15.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.16.4</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-xml-provider</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-undertow</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet-starter</artifactId>
<version>3.0.0-RC3</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson-starter</artifactId>
<version>3.0.0-RC3</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-openapi-java</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-undertow</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-log</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-netty-http</artifactId>
<version>3.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>3.16.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.release11.OutputAdapter
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
这是我的集成代码:
public static void main(String[] args) throws Exception {
PropertiesReader properties = new PropertiesReader("properties.properties");
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://" + properties.getProperty("activemq-host"));
Connection connection = connectionFactory.createConnection();
connection.start();
CamelContext context = new DefaultCamelContext();
context.addComponent("activemq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
JaxbDataFormat xmlDataFormat = new JaxbDataFormat(jaxbContext);
restConfiguration()
.component("undertow")
.host(properties.getProperty("rest-host"))
.port(properties.getProperty("rest-port"))
.bindingMode(RestBindingMode.auto);
from("activemq:topic:MATERIALS_ENRICHED?clientId=420&durableSubscriptionName=foo2")
.unmarshal(xmlDataFormat)
.filter(simple("${body.type} in 'A1,A2,A3'"))
.bean(JsonMapper.class, "process")
.delay(20000)
.process(exchange -> exchange.getIn().setHeader(Exchange.CONTENT_TYPE, constant("application/json")))
.to("rest:post:materials");
}
});
context.start();
}
你能给我一个提示吗?我不知道该尝试什么。请帮帮我。
编辑:在intellij中,这很好,当我在JAR中打包集成时,问题出现了。
好的,我知道了。我正在运行胖罐子,当我创建一个薄罐子然后运行它时,它起作用了。
我正在尝试使用docker compose对用Apache Camel编写的集成进行docker化。应用程序结构如下所示: 当我运行应用程序并尝试将数据插入数据库时,数据应以json形式发送到rest api,并在sftp服务器上以csv形式结束。该应用程序在本地运行良好,但在将数据插入数据库后作为docker网络,JAXB无法在两个输出适配器中解组数据。我想稍后使用自己的映射器将它们映射到适当的
我在XSD / XML到Java的方向上使用JAXB。我的XSD包含派生类型,我必须解组的XML包含xsi:type属性。查看JAXB(默认的Sun实现)生成的代码(用于解组),似乎没有任何方法可以获得这些属性。 是不是因为我总是可以对解组的Java对象执行并找到实际的类? 不过,这不是取决于我提供给某些基类可能会被实例化?(与xsi:type属性的实际值相对应的类的超类)。在这种情况下,可能需要
我正试图使用JAXB api解析下面的XML文档,我想解析PROPERTYDATALIST中包含多个PROPERTYDATA对象的每个项。在文档解组过程中,我得到一个空列表。任何关于如何解决此问题的帮助都将不胜感激。 下面是我编写的用于解组XML文件的类 通过上面的代码,我得到了除上面PropertyCatalist之外的所有元素。下面是输出
我正在尝试使用将XML转换为对象,我的XML如下所示: 所以我创建了3个java类:EntityResource.java,Item.java和PromissionRecipient.java如下图所示: EntityResource.java Item.java PermissionRecipient.java 所有工作和我得到了一个EntityResources对象包含项目,但EntityRe
我正在阅读下面的文件 并将其解析为Book对象 ……。我得到错误: 道:
我正在尝试使用MOXy for JAXB JSON支持来设置一个简单的Jersey JAX-RS应用程序,我想定制解组器。我做了以下工作: 我为编写了一个覆盖,并在解组器上设置了一个事件处理程序。当我传递一个无效的JSON正文时,会执行中的print语句,但不会执行事件处理程序中的print语句。因此,提供程序已正确注册,但未调用事件处理程序。 什么可能导致此问题? 我想要实现的是,当用户在JSO