Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6664

NullpointerException in LinkBuilderImpl#getResolvedUri when linkheader url has a matrix parameter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.3
    • 3.1.5, 3.0.8, 3.2.0
    • JAX-RS
    • None
    • Novice

    Description

      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;
      }

      Attachments

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            mikr Michael Krenn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: