Hi Andy

Thanks for doing these tests.

Having only a single forward slash in the .path("a/").path("/b") case is what I'd expect from UriBuilder, the users just do not need to worry about doing multiple ifs in their code to make sure no duplicate slashes make it into the final URI, given in most cases no duplicate slashes are expected.

I'm finding it a bit inconsistent that in the initial URI case the duplicate slashes do make it into the final URI, but perhaps CXF should support this case.

UriBuilderImpl.setPathAndMatrix asks JAXRSUtils.getPathSegments() to to prepare a list of segments - it excludes empty path segments. I guess a new JAXRSUtils.getPathSegments() overload may be needed which will accept a property allowing for the empty path segments be optionally included

Thanks, Sergey

On 13/06/17 20:16, Andy McCright wrote:
Hi Sergey,

Looks like both CXF and the RI will remove the duplicate slash in that
case.  Here is the output:

andys-mbp-2:jaxrs20-client-doubleslash andymc$ ./runJersey.sh

http://example.com/api//something

http://example.com/path/a/b

andys-mbp-2:jaxrs20-client-doubleslash andymc$ ./runCxf.sh

http://example.com/api/something

http://example.com/path/a/b


Here is the code I ran (the only difference between runJersey.sh and
runCxf.sh is the class path to the JAXRS implementation jars):


public class DoubleSlash {

public static void main(String[] args) throws Throwable {

WebTarget target = ClientBuilder.newClient().target("
http://example.com/api//something";);

System.out.println(target.getUri());


WebTarget target2 = ClientBuilder.newClient().target("
http://example.com/path/";).path("a/").path("/b");

System.out.println(target2.getUri());

}

}


So it looks like the RI is preserving the double slashes when specified in
the middle of the path in the initial target call, but not preserving them
when multiple individual path methods would end up with double slashes.


Thanks, Andy

On Tue, Jun 13, 2017 at 10:11 AM, Sergey Beryozkin <[email protected]>
wrote:

Hi Andy

The only option I can think of is to use a custom ClientRequestFilter
which will replace a request URI if it matches a certain pattern, etc

Yes, I've never thought about the necessity of having to keep the empty
path segments.

Can you also please do me a favor and check what RI does in
.path("a/").path("/b") case. If it preserves both forward slashes ethen
perhaps CXF UriBuilder will need to be tweaked a bit too

Thanks, Sergey


On 13/06/17 15:07, Andy McCright wrote:

HI Sergey,

Thanks for the response.  I ran the same code using the JAX-RS 2.0 RI
(Jersey 2.25.1) and it preserved the double-slash.  CXF removes it.

I'm not convinced that CXF is in violation of the spec (I suspect there
are
more than a few differences between JAX-RS implementations that still meet
the letter and spirit of the spec), but I'm just wondering if there is an
easy way to allow this customer to get the desired behavior with CXF -
possibly by adding a client property.

Thanks again,

Andy

On Tue, Jun 13, 2017 at 7:49 AM, Sergey Beryozkin <[email protected]>
wrote:

Hi Andy

It is most likely caused by UriBuilder parsing the URI and then dropping
the empty path segments.

As far as I recall UriBuilder.path() must guarantee that if we have say

.path("a/").path("/b") then the builder should ensure no duplicate "//"
appear in the final URI.

However I'm not sure what the expectations are if the "//" was in the
initial URI value, whether it should be preserved or not.

Do you know by any chance what RI does in this case, at the UriBuilder
level ?

Thanks, Sergey


On 05/06/17 15:29, Andy McCright wrote:

Hi All,

One of our customers hit an issue where they cannot preserve an empty
slash
in an outbound request.

For example, they code up:

WebTarget target = ClientBuilder.newClient().target("
http://example.com/api//something";);
System.out.println(target.getUri());

but the resulting URI is:  "http://example.com/api/something"; without
the
extra slash between api and something.

Is there any way to prevent the normalization that removes the extra
slash?

The original customer post is here:
https://developer.ibm.com/answers/questions/378780/how-can-
i-create-a-webtarget-with-double-in-path.html

The customer did not say, but I believe they may be using a WebSphere
Liberty version that ships with CXF 3.1.8.

Thanks in advance,

Andy





--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/


Reply via email to