Hello everyone,

I have a customer that is trying to use
("/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~%1A!$'()*+,;:@",
 "apiKeyQueryParam1Value"
) as a queryParam.  The get fails with a
javax.ws.rs.core.UriBuilderException: URI can not be built.  I have looked
for issues in github and  JIRA and I could not find any that match, so I
thought I would ask here.

I have reproduced the problem with JAX-RS 2.1 CXF Version 3.3.3. I have
tried 2 options to get this to work

Option 1 Not encoded
        Response response = client.target("http://localhost:"; + "8010" +
"/paramconverter/")
                        .path(
"application/resource/queryParamSpecialCharacters")
                        .queryParam(
"/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~%1A!$'()*+,;:@"
, "apiKeyQueryParam1Value")
                        .request(MediaType.APPLICATION_JSON_TYPE)
                        .get();
This fails with:
 00000076 SystemErr                                                    R
javax.ws.rs.core.UriBuilderException: URI can not be built
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuild
(UriBuilderImpl.java:120)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildFromEncoded
(UriBuilderImpl.java:245)
        at org.apache.cxf.jaxrs.client.AbstractClient.getCurrentURI
(AbstractClient.java:319)
        at org.apache.cxf.jaxrs.client.WebClient.fromClient
(WebClient.java:315)
        at org.apache.cxf.jaxrs.client.WebClient.fromClient
(WebClient.java:295)
        at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request
(ClientImpl.java:373)
        at org.apache.cxf.jaxrs.client.spec.ClientImpl$WebTargetImpl.request
(ClientImpl.java:438)
       ...

Caused by: java.net.URISyntaxException: Illegal character in query at index
154:
http://localhost:8010/paramconverter/application/resource/queryParamSpecialCharacters?/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$'()*
 ,;:@=apiKeyQueryParam1Value
        at java.base/java.net.URI$Parser.fail(URI.java:2915)
        at java.base/java.net.URI$Parser.checkChars(URI.java:3086)
        at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3174)
        at java.base/java.net.URI$Parser.parse(URI.java:3116)
        at java.base/java.net.URI.<init>(URI.java:600)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildURIFromEncoded
(UriBuilderImpl.java:202)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildURI
(UriBuilderImpl.java:175)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuild
(UriBuilderImpl.java:118)
        ... 39 more

>From what I can tell from the trace I have set up, buildURIFromEncoded is
using a URI for the queryParam that has been decoded  in error.

[12/8/20, 8:52:07:444 CST] 00000069 id=58888f6b
org.apache.cxf.jaxrs.impl.UriBuilderImpl                     >
buildURIFromEncoded Entry
/paramconverter/application/resource/queryParamSpecialCharacters
/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$'()* 
,;:@=apiKeyQueryParam1Value
null



Option 2 Encoded
        Response response = client.target("http://localhost:"; + "8010" +
"/paramconverter/")
                        .path(
"application/resource/queryParamSpecialCharacters")
                        .queryParam(URLEncoder.encode(
"/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~%1A!$'()*+,;:@"
, "UTF-8"), "apiKeyQueryParam1Value")
                        .request(MediaType.APPLICATION_JSON_TYPE)
                        .get();
URLEncoder.encode =
%2F%3FabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._%7E%251A%21%24%27%28%29*%2B%2C%3B%3A%40


This fails with:
 00000074 SystemErr                                                    R
javax.ws.rs.core.UriBuilderException: URI can not be built
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuild
(UriBuilderImpl.java:120)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildFromEncoded
(UriBuilderImpl.java:245)
        at org.apache.cxf.jaxrs.client.AbstractClient.getCurrentURI
(AbstractClient.java:319)
        at org.apache.cxf.jaxrs.client.WebClient.finalizeMessage
(WebClient.java:1110)
        at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation
(WebClient.java:1084)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:932)
        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:901)
        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:461)
        at org.apache.cxf.jaxrs.client.SyncInvokerImpl.method
(SyncInvokerImpl.java:135)
        at org.apache.cxf.jaxrs.client.SyncInvokerImpl.method
(SyncInvokerImpl.java:130)
        at org.apache.cxf.jaxrs.client.SyncInvokerImpl.get
(SyncInvokerImpl.java:50)
        at org.apache.cxf.jaxrs.client.spec.InvocationBuilderImpl.get
(InvocationBuilderImpl.java:92)
                ...

Caused by: java.net.URISyntaxException: Illegal character in query at index
154:
http://localhost:8010/paramconverter/application/resource/queryParamSpecialCharacters?/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$'()*
 ,;:@=apiKeyQueryParam1Value
        at java.base/java.net.URI$Parser.fail(URI.java:2915)
        at java.base/java.net.URI$Parser.checkChars(URI.java:3086)
        at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3174)
        at java.base/java.net.URI$Parser.parse(URI.java:3116)
        at java.base/java.net.URI.<init>(URI.java:600)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildURIFromEncoded
(UriBuilderImpl.java:202)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.buildURI
(UriBuilderImpl.java:175)
        at org.apache.cxf.jaxrs.impl.UriBuilderImpl.doBuild
(UriBuilderImpl.java:118)
        ... 44 more

>From what I can tell from the trace I have set up, buildURIFromEncoded is
using a URI for the queryParam that has been decoded  a second time in
error.

[12/8/20, 14:40:48:700 CST] 00000070 id=bbcf19e7
org.apache.cxf.jaxrs.impl.UriBuilderImpl                     >
buildURIFromEncoded Entry
/paramconverter/application/resource/queryParamSpecialCharacters
/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~!$'()* 
,;:@=apiKeyQueryParam1Value
null

I have a simple resource class that handles the get:

    @GET
    @Path("queryParamSpecialCharacters")
    public Response queryParamSpecialCharacters(@QueryParam(
"/?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~%1A!$'()*+,;:@"
) final String queryParm1) {
        System.out.println("queryParamSpecialCharacters queryParm1 = " +
queryParm1);
        return Response.ok(queryParm1).build();
    }



My question is:  Should either of the options work or is what the customer
trying to do invalid?

I have opened an Open Liberty Issue that has more details.
https://github.com/OpenLiberty/open-liberty/issues/15234

Thank you for the Help!

Thanks....
John L. Koehler
Dept: WG8A Bld: 050-2
WebSphere Development
Rochester, MN 55901
Phone: 507-513-6221, Tie: 342-6221, Home: 507-281-1874
e-mail address: [email protected]

Reply via email to