gpt4 book ai didi

spring - 无法从 Java Spring 中的 RSS Feed 接收数据

转载 作者:行者123 更新时间:2023-12-02 07:01:57 25 4
gpt4 key购买 nike

我想使用以下代码从 Java Spring 中的 RSS 源接收数据:

package org.springframework.integration.samples.feed;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import com.rometools.rome.feed.synd.SyndEntry;

public class Feed {

public static void main(String[] args) {
ConfigurableApplicationContext ac =
new ClassPathXmlApplicationContext("META-INF/spring/integration/FeedInboundChannelAdapterSample-context.xml");
PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
for (int i = 0; i < 10; i++) {
Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
if (message != null){
SyndEntry entry = message.getPayload();
System.out.println(entry.getTitle());
}
else {
break;
}
}
ac.close();
}
}

FeedInboundChannelAdapterSample-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-feed="http://www.springframework.org/schema/integration/feed"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">

<int-feed:inbound-channel-adapter id="feedAdapter"
channel="feedChannel"
auto-startup="true"
url="http://pharmacie.lu/flux_rss.xml">
<int:poller fixed-rate="10000" max-messages-per-poll="100" />
</int-feed:inbound-channel-adapter>

<int:channel id="feedChannel">
<int:queue/>
</int:channel>

包含提要的 URL:http://pharmacie.lu/flux_rss.xml

问题是我收到一条空消息,但我不知道为什么:

    14:32:13.614 INFO  [main][org.springframework.integration.config.IntegrationRegistrar] No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
14:32:13.621 DEBUG [main][org.springframework.integration.config.IntegrationRegistrar] The '#jsonPath' SpEL function cannot be registered: there is no jayway json-path.jar on the classpath.
14:32:13.621 DEBUG [main][org.springframework.integration.config.IntegrationRegistrar] SpEL function '#xpath' isn't registered: there is no spring-integration-xml.jar on the classpath.
14:32:13.739 INFO [main][org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor] No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
14:32:13.743 INFO [main][org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor] No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
14:32:14.075 DEBUG [main][org.springframework.integration.config.GlobalChannelInterceptorProcessor] No global channel interceptors.
14:32:14.078 INFO [main][org.springframework.integration.endpoint.EventDrivenConsumer] Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
14:32:14.078 INFO [main][org.springframework.integration.channel.PublishSubscribeChannel] Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@3b764bce.errorChannel' has 1 subscriber(s).
14:32:14.078 INFO [main][org.springframework.integration.endpoint.EventDrivenConsumer] started _org.springframework.integration.errorLogger
14:32:14.080 INFO [main][org.springframework.integration.endpoint.SourcePollingChannelAdapter] started feedAdapter
14:32:14.085 TRACE [main][org.springframework.integration.channel.QueueChannel] preReceive on channel 'feedChannel'
14:32:14.125 DEBUG [task-scheduler-1][org.springframework.integration.feed.inbound.FeedEntryMessageSource] EVENT: Feed Polled. URL = http://pharmacie.lu/flux_rss.xml
14:32:14.242 DEBUG [task-scheduler-1][org.springframework.integration.feed.inbound.FeedEntryMessageSource] retrieved feed at url 'http://pharmacie.lu/flux_rss.xml'
14:32:14.243 DEBUG [task-scheduler-1][org.springframework.integration.endpoint.SourcePollingChannelAdapter] Received no Message during the poll, returning 'false'
14:32:15.086 TRACE [main][org.springframework.integration.channel.QueueChannel] postReceive on channel 'feedChannel', message is null
14:32:15.091 INFO [main][org.springframework.integration.endpoint.SourcePollingChannelAdapter] stopped feedAdapter
14:32:15.091 INFO [main][org.springframework.integration.endpoint.EventDrivenConsumer] Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
14:32:15.091 INFO [main][org.springframework.integration.channel.PublishSubscribeChannel] Channel 'org.springframework.context.support.ClassPathXmlApplicationContext@3b764bce.errorChannel' has 0 subscriber(s).
14:32:15.092 INFO [main][org.springframework.integration.endpoint.EventDrivenConsumer] stopped _org.springframework.integration.errorLogger

当我使用 url rss.cnn.com/rss/cnn_topstories.rss 时,代码可以正常工作。

(该代码来自 Spring Integration RSS Feed 模块的示例,网址为github:https://github.com/spring-projects/spring-integration-samples/tree/master/basic/feed )

我的问题是为什么上面的代码适用于示例中的网址,但不适用于 pharmacie.lu/flux_rss.xml 网址?

最佳答案

目前,FeedEntryMessageSourcespring-integration预计 feed 的条目有一些最后修改日期,但在 pharmacie.lu 的 feed 中没有,因此所有条目都会被忽略,并且不会返回任何内容。

关于spring - 无法从 Java Spring 中的 RSS Feed 接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069763/

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