Skip to content

Commit 38f1934

Browse files
committed
Upgrade to rome-2.0.0; fix deprecation
* Fix `FeedInboundChannelAdapterParser` to properly populate a `Resource` ctor arg
1 parent ce9f7f4 commit 38f1934

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ext {
9898
r2dbch2Version = '1.0.0.RELEASE'
9999
reactorVersion = '2022.0.3'
100100
resilience4jVersion = '2.0.2'
101-
romeToolsVersion = '1.18.0'
101+
romeToolsVersion = '2.0.0'
102102
rsocketVersion = '1.1.3'
103103
servletApiVersion = '6.0.0'
104104
smackVersion = '4.4.6'

Diff for: spring-integration-feed/src/main/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParser.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import org.springframework.beans.BeanMetadataElement;
2222
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2323
import org.springframework.beans.factory.xml.ParserContext;
24+
import org.springframework.core.io.Resource;
2425
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
2526
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
2627
import org.springframework.integration.feed.inbound.FeedEntryMessageSource;
@@ -50,18 +51,21 @@ protected BeanMetadataElement parseSource(final Element element, final ParserCon
5051
boolean hasResource = StringUtils.hasText(resource);
5152

5253
if (hasUrl == hasResource) {
53-
parserContext.getReaderContext().error(
54-
"Exactly one of the 'url', 'reader' or 'resource' is required.", element);
54+
parserContext.getReaderContext().error("Exactly one of the 'url' or 'resource' is required.", element);
5555
}
5656

5757
if (hasUrl) {
5858
sourceBuilder.addConstructorArgValue(url);
5959
}
60-
else if (hasResource) {
61-
sourceBuilder.addConstructorArgValue(resource);
60+
else {
61+
sourceBuilder.getBeanDefinition()
62+
.getConstructorArgumentValues()
63+
.addIndexedArgumentValue(0, resource, Resource.class.getName());
6264
}
6365

64-
sourceBuilder.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE));
66+
sourceBuilder.getBeanDefinition()
67+
.getConstructorArgumentValues()
68+
.addIndexedArgumentValue(1, element.getAttribute(ID_ATTRIBUTE));
6569

6670
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "metadata-store");
6771
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "feed-input", "syndFeedInput");

Diff for: spring-integration-feed/src/main/java/org/springframework/integration/feed/inbound/FeedEntryMessageSource.java

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,13 @@
1616

1717
package org.springframework.integration.feed.inbound;
1818

19-
import java.io.Reader;
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.net.URISyntaxException;
2022
import java.net.URL;
23+
import java.net.http.HttpClient;
24+
import java.net.http.HttpRequest;
25+
import java.net.http.HttpResponse;
2126
import java.util.Comparator;
2227
import java.util.Date;
2328
import java.util.List;
@@ -26,6 +31,7 @@
2631

2732
import com.rometools.rome.feed.synd.SyndEntry;
2833
import com.rometools.rome.feed.synd.SyndFeed;
34+
import com.rometools.rome.io.FeedException;
2935
import com.rometools.rome.io.SyndFeedInput;
3036
import com.rometools.rome.io.XmlReader;
3137

@@ -220,10 +226,7 @@ private void populateEntryList() {
220226
private SyndFeed getFeed() {
221227
try {
222228
synchronized (this.feedMonitor) {
223-
Reader reader = this.feedUrl != null
224-
? new XmlReader(this.feedUrl)
225-
: new XmlReader(this.feedResource.getInputStream());
226-
SyndFeed feed = this.syndFeedInput.build(reader);
229+
SyndFeed feed = buildSyndFeed();
227230
logger.debug(() -> "Retrieved feed for [" + this + "]");
228231
if (feed == null) {
229232
logger.debug(() -> "No feeds updated for [" + this + "], returning null");
@@ -236,6 +239,29 @@ private SyndFeed getFeed() {
236239
}
237240
}
238241

242+
private SyndFeed buildSyndFeed() throws IOException, URISyntaxException, InterruptedException, FeedException {
243+
InputStream inputStream;
244+
if (this.feedResource != null) {
245+
inputStream = this.feedResource.getInputStream();
246+
}
247+
else {
248+
HttpRequest request =
249+
HttpRequest.newBuilder()
250+
.GET()
251+
.uri(this.feedUrl.toURI())
252+
.build();
253+
254+
inputStream =
255+
HttpClient.newHttpClient()
256+
.send(request, HttpResponse.BodyHandlers.ofInputStream())
257+
.body();
258+
}
259+
260+
try (inputStream) {
261+
return this.syndFeedInput.build(new XmlReader(inputStream));
262+
}
263+
}
264+
239265
@Override
240266
public String toString() {
241267
return "FeedEntryMessageSource{" +

0 commit comments

Comments
 (0)