Skip to content

How let ControllerLinkBuilder see original request URI? #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewtswu opened this issue Jan 20, 2014 · 8 comments
Closed

How let ControllerLinkBuilder see original request URI? #143

andrewtswu opened this issue Jan 20, 2014 · 8 comments
Assignees

Comments

@andrewtswu
Copy link

andrewtswu commented Jan 20, 2014

Hi,

Our tomcat server can only see internal URIs due to the way we setup our servers. If a client, for example, wants to get a list of events, the external URI is

http://api.mydomain.com/events

However, internally, tomcat sees

http://api.mydomain.com/servlet/events

which causes all self links to have similar pattern. For example

http://api.mydomain.com/servlet/events
http://api.mydomain.com/servlet/events/:id

Is there an easy way to customize ControllerLinkBuilder to re-write the URIs?

@collinpeters
Copy link

+1

@aleksz
Copy link

aleksz commented Apr 14, 2014

+1, but same goes to other link builders. In my scenario app is sitting behind the proxy. X-Forwarded-Host and X-Forwarded-Ssl do the trick, but I also need to change the path.

@dmartinpro
Copy link

As a workaround, you can rely on mod_substitute (
http://httpd.apache.org/docs/2.2/mod/mod_substitute.html).

On Mon, Apr 14, 2014 at 9:36 AM, Aleksandr Zhuikov <[email protected]

wrote:

+1, but same goes to other link builders. In my scenario app is sitting
behind the proxy. X-Forwarded-Host and X-Forwarded-Ssl do the trick, but I
also need to change the path.

Reply to this email directly or view it on GitHubhttps://github.com//issues/143#issuecomment-40339896
.

@aleksz
Copy link

aleksz commented Apr 14, 2014

Does it work for POST method returning status 201 and body? We are actually using it at the moment and it works for GET requests returning 200, but not for POST.

nickgrealy added a commit to nickgrealy/spring-hateoas that referenced this issue Oct 26, 2015
Added use of X-Forwarded-Path in ControllerLinkBuilder for issue spring-projects#143.
Fixed JacksonSerializationTest for Windows & Linux OS's.
@nickgrealy
Copy link

Just wondering, would handling an X-Forwarded-Path header solve this issue? i.e.
nickgrealy@d069038

You could then automatically inject the headers as part of your application filters... e.g.
https://gist.github.com/nickgrealy/b4a582c8e1c411c5396d#file-application-java-L18-L24

I haven't committed to this project before, so let me know if I can go ahead and submit a pull request (do you want the HeaderOverrideFilter.java from the example included too?).

@aleksz - re: not working for POST - that sounds like a separate issue to this

nickgrealy added a commit to nickgrealy/spring-hateoas that referenced this issue Oct 26, 2015
…ng-projects#143.

Fixed JacksonSerializationTest for Windows & Linux OS's.
nickgrealy added a commit to nickgrealy/spring-hateoas that referenced this issue Oct 26, 2015
commit 898cd20
Author: Nick Grealy <[email protected]>
Date:   Mon Oct 26 13:15:36 2015 +1100

    Added @author

commit d069038
Author: Nick Grealy <[email protected]>
Date:   Mon Oct 26 12:06:54 2015 +1100

    Added use of X-Forwarded-Path in ControllerLinkBuilder

    Added use of X-Forwarded-Path in ControllerLinkBuilder for issue spring-projects#143.
    Fixed JacksonSerializationTest for Windows & Linux OS's.
nickgrealy added a commit to nickgrealy/spring-hateoas that referenced this issue Oct 26, 2015
commit 898cd20
Author: Nick Grealy <[email protected]>
Date:   Mon Oct 26 13:15:36 2015 +1100

    Added @author

commit d069038
Author: Nick Grealy <[email protected]>
Date:   Mon Oct 26 12:06:54 2015 +1100

    Added use of X-Forwarded-Path in ControllerLinkBuilder

    Added use of X-Forwarded-Path in ControllerLinkBuilder for issue spring-projects#143.
    Fixed JacksonSerializationTest for Windows & Linux OS's.
nickgrealy added a commit to nickgrealy/spring-hateoas that referenced this issue Oct 26, 2015
Added ForwardedHeaderRequestWrapper utility class - spring-projects#143
@odrotbohm
Copy link
Member

ControllerLinkBuilder already supports well-defined proxy server headers, so it's basically up to you making sure your proxy server sets those appropriately.

@odrotbohm odrotbohm changed the title Customize ControllerLinkBuilder How let ControllerLinkBuilder see original request URI? Jan 13, 2016
@odrotbohm odrotbohm self-assigned this Jan 13, 2016
@otrosien
Copy link

otrosien commented Dec 7, 2016

Should be obsolete now. Current master is delegating this to UriComponentsBuilder, which is also base-path aware. (use X-Forwarded-Prefix header. see also https://jira.spring.io/browse/SPR-12500)

gregturn added a commit that referenced this issue May 25, 2017
If forming a link outside a Spring web request, fallback to relative links.

Original pull-request: #410
Related issues: #330, #143, #516
gregturn added a commit that referenced this issue May 25, 2017
If forming a link outside a Spring web request, fallback to relative links.

Original pull-request: #410
Related issues: #330, #143, #516
gregturn added a commit that referenced this issue May 25, 2017
If forming a link outside a Spring web request, fallback to relative links.

Original pull-request: #410
Related issues: #330, #143, #516
@gregturn gregturn self-assigned this May 25, 2017
gregturn added a commit that referenced this issue May 25, 2017
If forming a link outside a Spring web request, fallback to relative links.

Original pull-request: #410
Related issues: #330, #143, #516
odrotbohm pushed a commit that referenced this issue Jul 27, 2017
If forming a link outside a Spring web request, fallback to relative links.

Original pull-request: #410.
Related issues: #330, #143, #516.
odrotbohm added a commit that referenced this issue Jul 27, 2017
Original pull-request: #410.
Related issues: #330, #143, #516.
@gregturn
Copy link
Contributor

Closed since we observe standard headers as well as support relative links as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants