You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "iris ding (JIRA)" <ji...@apache.org> on 2015/04/15 16:14:58 UTC

[jira] [Commented] (CXF-6352) ContainerResponseContext.getLinks() lose links

    [ https://issues.apache.org/jira/browse/CXF-6352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14496221#comment-14496221 ] 

iris ding commented on CXF-6352:
--------------------------------

Suppose we need to change getLink(), getLinks() and getAllLinks() in org.apache.cxf.jaxrs.impl.ResponseImpl as below:
 @Override
    public Link getLink(String relation) {
        Set<Link> links = getAllLinks();
        for (Link link : links)
        {
            String rel = link.getRel();
            if (rel != null && rel.contains(relation))
            {
                return link;
            }

        }
        return null;

    }

@Override
    public Set<Link> getLinks() {
        return getAllLinks();
    }

   private Set<Link> getAllLinks() {
        List<Object> linkValues = metadata.get(HttpHeaders.LINK);
        if (linkValues == null) {
            return Collections.EMPTY_SET;
        } else {
            Set<Link> links = new LinkedHashSet<Link>();
            for (Object o : linkValues) {
                Link link = o instanceof Link ? (Link) o : Link.valueOf(o.toString());
                if (!link.getUri().isAbsolute()) {
                    URI requestURI = URI.create((String) outMessage.get(Message.REQUEST_URI));
                    link = Link.fromLink(link).baseUri(requestURI).build();
                }
                links.add(link);

            }
            return links;
        }
    }

> ContainerResponseContext.getLinks() lose links
> ----------------------------------------------
>
>                 Key: CXF-6352
>                 URL: https://issues.apache.org/jira/browse/CXF-6352
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.0, 3.0.2, 3.0.3
>            Reporter: iris ding
>             Fix For: 3.0.3
>
>
> in org.apache.cxf.jaxrs.impl.ResponseImpl.getAllLinks() , we put link into a LinkedHashMap and use link.getRel() as key:
> links.put(link.getRel(), link);
> However, link.getRel() may return null, in such case, we will lose links if two links's rel is null.
> See below javadoc for Link:
> getRel()
> Returns the value associated with the link rel param, or null if this param is not specified.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)