You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Sergey Beryozkin (JIRA)" <ji...@apache.org> on 2015/11/05 18:19:27 UTC

[jira] [Commented] (CXF-6664) NullpointerException in LinkBuilderImpl#getResolvedUri when linkheader url has a matrix parameter

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

Sergey Beryozkin commented on CXF-6664:
---------------------------------------

Hi, thanks for the patch - I've decided to avoid though splitting all the string, given a "<" ">" token always comes first, so I take of that first and then split to get the parameters, hope you OK with it, thanks for your help

> 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)