Michael Krenn created CXF-6664:
----------------------------------

             Summary: NullpointerException in LinkBuilderImpl#getResolvedUri 
when linkheader url has a matrix parameter
                 Key: CXF-6664
                 URL: https://issues.apache.org/jira/browse/CXF-6664
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.0.3
            Reporter: Michael Krenn


The method LinkBuilderImpl#link(String) has a bug when in url between "<" and 
">" a matrix parameter (begins with ";") is occuring.

Then the tokenizer splits the url at ";" and no "UriBuilder.fromUri" is called.
when accessing "ub" in getResolvedUri, a NullPointerException is thrown.

Example:
* LinkHeader Entry:

<http://localhost:8080/something/subresource;type=null?index=0&max=null>;rel="all";title="Read
 all resources";type="application/json";verb="GET"

* StackTrace:

java.lang.NullPointerException
        at 
org.apache.cxf.jaxrs.impl.LinkBuilderImpl.getResolvedUri(LinkBuilderImpl.java:58)
        at 
org.apache.cxf.jaxrs.impl.LinkBuilderImpl.build(LinkBuilderImpl.java:46)
        at javax.ws.rs.core.Link.valueOf(Link.java:174)
        at 
org.apache.cxf.jaxrs.impl.ResponseImpl.getAllLinks(ResponseImpl.java:362)
        at org.apache.cxf.jaxrs.impl.ResponseImpl.getLink(ResponseImpl.java:305)


Following Patch of "LinkBuilderImpl#link(String)" supports this case:

    @Override
    public Builder link(String link) {
        String[] tokens = StringUtils.split(link, ";");
        String potentialUrlPart = null;

        for (String token : tokens) {

            if (potentialUrlPart != null) {
                token = potentialUrlPart + token;
                            potentialUrlPart = null;
            }

            String theToken = token.trim();

            if (theToken.startsWith("<") && theToken.endsWith(">")) {
                ub = UriBuilder.fromUri(theToken.substring(1, theToken.length() 
- 1));
            } else {
                int i = theToken.indexOf('=');
                if (i != -1) {
                    String name = theToken.substring(0, i);
                    String value = stripQuotes(theToken.substring(i + 1));
                    params.put(name, value);
                } else {
                    potentialUrlPart = token;
                }
            }
        }
        return this;
    }



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

Reply via email to