Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve "type" parameter in media type for Atom Feed/Entry message conversion #1885

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -90,7 +90,7 @@ protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage)
Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType != null) {
contentType = new MediaType(contentType.getType(), contentType.getSubtype(), charset);
contentType = new MediaType(contentType, charset);
outputMessage.getHeaders().setContentType(contentType);
}

Expand Down
Expand Up @@ -24,7 +24,9 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.rometools.rome.feed.atom.Entry;
import com.rometools.rome.feed.atom.Feed;
Expand All @@ -39,6 +41,8 @@
import org.springframework.http.MockHttpInputMessage;
import org.springframework.http.MockHttpOutputMessage;

import static java.util.Collections.singletonMap;

/**
* @author Arjen Poutsma
*/
Expand Down Expand Up @@ -130,4 +134,18 @@ public void writeOtherCharset() throws IOException, SAXException {
outputMessage.getHeaders().getContentType());
}

@Test
public void writeOtherContentTypeParameters() throws IOException {
Feed feed = new Feed("atom_1.0");

MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(feed, new MediaType("application", "atom+xml", singletonMap("type", "feed")), outputMessage);

Map<String, String> expectedParameters = new HashMap<>();
expectedParameters.put("charset", "UTF-8");
expectedParameters.put("type", "feed");
assertEquals("Invalid content-type", new MediaType("application", "atom+xml", expectedParameters),
outputMessage.getHeaders().getContentType());
}

}
Expand Up @@ -23,7 +23,9 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.rometools.rome.feed.rss.Channel;
import com.rometools.rome.feed.rss.Item;
Expand All @@ -36,6 +38,8 @@
import org.springframework.http.MockHttpInputMessage;
import org.springframework.http.MockHttpOutputMessage;

import static java.util.Collections.singletonMap;

/**
* @author Arjen Poutsma
*/
Expand Down Expand Up @@ -133,6 +137,23 @@ public void writeOtherCharset() throws IOException, SAXException {
outputMessage.getHeaders().getContentType());
}

@Test
public void writeOtherContentTypeParameters() throws IOException {
Channel channel = new Channel("rss_2.0");
channel.setTitle("title");
channel.setLink("http://example.com");
channel.setDescription("description");

MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(channel, new MediaType("application", "rss+xml", singletonMap("x", "y")), outputMessage);

Map<String, String> expectedParameters = new HashMap<>();
expectedParameters.put("charset", "UTF-8");
expectedParameters.put("x", "y");
assertEquals("Invalid content-type", new MediaType("application", "rss+xml", expectedParameters),
outputMessage.getHeaders().getContentType());
}

private static CompareMatcher isSimilarTo(final String content) {
return CompareMatcher.isSimilarTo(content)
.ignoreWhitespace();
Expand Down