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

Sergey Beryozkin commented on CXF-7227:
---------------------------------------

The reason the base URI is set to a new URI is that now, after getting some 
content from a new host, WebClient is pointing to this new host. 

I'm not sure how to cleanly fix this issue at the generic level as it can be 
hard to correctly evaluate the new base URI. The best effort is done when the 
the new URI is part of the same space, but when the host is different,  it is 
just hard to set the base URI to anything but the new URI.

I'd suggest to either disable the autoredirect and react to the redirection 
exception or have a simple 'reset' of the base URI in the form of 
WebClient.to() to protect against the redirects:
{code:java}
WebClient wc = WebClient.create("https://host1/book";);
for (int i  = 1; i <= bookCount; i++) {
    wc.path(Integer.toString(i)).path("info");
    wc.get();
   // now, after the redirect points to https://host2/book/N/info
   // revert back the 2 path segments:
   wc.back(false).back(false); 
}
{code}

This should work well and in the end WebClient will end up pointing to the 
resource where the content actually came form which is expected...

> AbstractClient set wrong base uri when recieves http 301 redirect status
> ------------------------------------------------------------------------
>
>                 Key: CXF-7227
>                 URL: https://issues.apache.org/jira/browse/CXF-7227
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.11
>            Reporter: xseiko
>            Priority: Major
>
> HTTPConduit processes all redirect statuses in redirectRetransmit function 
> like:
> String newURL = extractLocation(Headers.getSetProtocolHeaders(m));
> outMessage.put("transport.retransmit.url", newURL);
> retransmit(newURL);
> And then AbstractClient class use transport.retransmit.url in 
> completeExchange function to set new base uri:
> s = (String)exchange.getOutMessage().get("transport.retransmit.url");
> if (s != null && !state.getBaseURI().toString().equals(s)) {
>     calculateNewRequestURI(URI.create(s), getCurrentURI(), proxy);
>     return;
> }
> So when you send first request https://host1/book/1/info that return 301 
> Location: https://host2/book/1/info this request is redirected to 
> https://host2/book/1/info but AbstractClient set base uri 
> https://host2/book/1/info.
> And when you send second request https://host1/book/2/info it is redirected 
> to https://host2/book/1/info/book/2/info.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to