[
https://issues.apache.org/jira/browse/CXF-5406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13827440#comment-13827440
]
Dale Peakall commented on CXF-5406:
-----------------------------------
Sample code:
{code}
import org.apache.cxf.jaxrs.provider.atom.AtomPojoProvider;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.nio.charset.Charset;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Example that demonstrates problem with AtomPojoProvider when there is no
"type" parameter specified.
*/
public final class NoAtomTypeApp {
/** A sample entry with content. */
private static final String SAMPLE_ENTRY_WITH_CONTENT =
"<?xml version='1.0' encoding='UTF-8'?>\n" +
"<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" +
" <id>84297856</id>\n" +
" <content type=\"application/xml\">\n" +
" <jaxbDataType xmlns=\"\">\n" +
" </jaxbDataType>\n" +
" </content>\n" +
"</entry>";
/**
* A sample JAXB data-type to read data into.
*/
@XmlRootElement
public static class JaxbDataType {
// no data
}
/**
* This class cannot be instantiated.
*/
private NoAtomTypeApp() {
// do nothing
}
/**
* Main entry point.
* @param args the command-line arguments: none expected.
*/
public static void main(String[] args) throws IOException {
AtomPojoProvider atomPojoProvider = new AtomPojoProvider();
try {
atomPojoProvider.readFrom((Class)JaxbDataType.class,
JaxbDataType.class,
new Annotation[0],
MediaType.valueOf("application/atom+xml"),
new MultivaluedHashMap<String, String>(),
new
ByteArrayInputStream(SAMPLE_ENTRY_WITH_CONTENT.getBytes(Charset.forName("UTF-8"))));
} catch (ClassCastException e) {
System.out.println("Urgh - this isn't good!");
}
try {
atomPojoProvider.readFrom((Class)JaxbDataType.class,
JaxbDataType.class,
new Annotation[0],
MediaType.valueOf("application/atom+xml;type=ENTRY"),
new MultivaluedHashMap<String, String>(),
new
ByteArrayInputStream(SAMPLE_ENTRY_WITH_CONTENT.getBytes(Charset.forName("UTF-8"))));
} catch (ClassCastException e) {
System.out.println("Urgh - this also isn't good!");
}
}
}
{code}
> ClassCastException in AtomPojoProvider when an Atom entry is returned with a
> media-type of application/atom+xml (no type parameter)
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: CXF-5406
> URL: https://issues.apache.org/jira/browse/CXF-5406
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 2.7.7
> Reporter: Dale Peakall
>
> According to RFC5023 (section 12) a server SHOULD return a type parameter on
> the media-type when returning an Atom Entry (e.g.
> application/atom+xml;type=entry). However, it is not mandatory that the
> server do this and RFC5023 states:
> {quote}
> If not specified, the type is assumed to be unspecified, requiring
> Atom processors to examine the root element to determine the type of
> Atom document.
> {quote}
> However, AtomPojoProvider simply assumes that when no type parameter is
> present that the content is a feed and throws a ClassCastException when it
> ends up trying to cast the Entry returned by Abdera into a Feed.
> Also AtomPojoProvider's check on the type parameter value is case-senstitive
> where RFC5023 states that:
> {quote}
> Neither the parameter name nor its value are case sensitive.
> {quote}
>
--
This message was sent by Atlassian JIRA
(v6.1#6144)