These are chat archives for spring-cloud/spring-cloud

20th
Jul 2015
ccit-spence
@ccit-spence
Jul 20 2015 05:45
How is the x-forwarded-host supposed to work if you have a UI and nothing but a link /somewhere to another ui service? In our case the other UI service is a Spring MVC based UI.
Dave Syer
@dsyer
Jul 20 2015 06:56
Your UI exposes links to another system and they are both behind the same proxy? Not quite sure what you are asking yet.
ccit-spence
@ccit-spence
Jul 20 2015 06:58
sorry, to sum it up. I have 2 spring MVC UI services behind zuul. Links exist within each service that link to each other
eureka is in this as well
not sure how the x-forward works if the call is not something explict like calling an api
Dave Syer
@dsyer
Jul 20 2015 07:01
If the correct headers are there it is still up to the server to use them to construct links
ccit-spence
@ccit-spence
Jul 20 2015 07:02
so in the html the ui must be constructed?
Dave Syer
@dsyer
Jul 20 2015 07:03
How else would it work?
ccit-spence
@ccit-spence
Jul 20 2015 07:05
not sure, right now the ui just has a link /otherservice. I see nothing within the headers. Are you saying that I need a mthod to handle a certain type of outbound link to inject the headers?
with traverson or feign it is easy, just not seeing how to do it for a regular link
Dave Syer
@dsyer
Jul 20 2015 07:08
Is the link in a templated HTML page? Or static?
If it's templated it needs to use the headers to construct the link server side.
If static I guess it has to be done in the browser
Server side you can use Spring's UriTemplateBuilder (from memory). Same as SD Rest would.
Not sure how you would do it in static HTML actually
A "link service" in the backend maybe
ccit-spence
@ccit-spence
Jul 20 2015 07:11
in this case it is a groovy template.
I will play around with the UriTemplateBuilder. Was not sure if this had been a question before
we bascially have spring MVC UI services that are very small often one to 5 pages total
they do call api services. the problem is with the headers for linking between the ui services
Dave Syer
@dsyer
Jul 20 2015 07:13
Do they serve full pages or just partials?
(Out of interest)
ccit-spence
@ccit-spence
Jul 20 2015 07:14
full pages
partials is of some interest, have not been able to figure out a good composition scheme yet
ccit-spence
@ccit-spence
Jul 20 2015 07:23
the end goal is at some point is to display partials. The problem I have run into is getting around the issue of having to refresh the context to get partial changes to appear. The Thymeleaf UriTemplateResolver works to show a partial but it only loads when the app intially loads. Any changes require a restart
Dave Syer
@dsyer
Jul 20 2015 07:34
I would be looking to a browser-based solution. I know I saud that before.
ccit-spence
@ccit-spence
Jul 20 2015 07:43
yeah, I know. in this case I am having to stay away from js as much as possible
for now the main thing is to include the headers for interservice UI request
ccit-spence
@ccit-spence
Jul 20 2015 08:52
I guess I am more confused than I thought. If I enter the url of a ui service as http://zuulproxyurl/ui/somespringmvcui I am sent to the url of the service itself. http://directling:8080/ui/somespringmvcui
Sergei Egorov
@bsideup
Jul 20 2015 08:53

Hello

In perfect world, in case of Zuul, who should retry request: client or zuul? And why?

ccit-spence
@ccit-spence
Jul 20 2015 08:59
@bsideup Personally I would think the client. Otherwise you could end up with an endless retry. I suppose limts could help that.
I see Zuul as being dumb and just forwarding request
Sergei Egorov
@bsideup
Jul 20 2015 09:02
but if we provide external public API with Zuul then it's not so good to tell every API consumer that he is responsible for retrying API requests all the time we have deployment, restart or something else
Dave Syer
@dsyer
Jul 20 2015 09:03
The proxy in Spring Cloud Zuul uses Hystrix and Ribbon (both of which do retry)
So I think the point is moot (it's just configurable)
ccit-spence
@ccit-spence
Jul 20 2015 09:07
what he said, far smarter than I am
@dsyer I was thinking of me x-forward problem wrong. If I call the ui service through zuul. I am getting the forwarded to the direct link of the service. Do I need to add something to the Spring MVC UI service?
Dave Syer
@dsyer
Jul 20 2015 09:10
That's an implementation detail.
You could, for instance, calculate and add the links to your model in the controller
Or use an interceptor to set up a base path
So you can construct the links in your template
ccit-spence
@ccit-spence
Jul 20 2015 09:11
via ServletUriComponentsBuilder?
Dave Syer
@dsyer
Jul 20 2015 09:11
Yes
The interceptor is cleaner
that way your controllers can remain independent of the servlet APIs
ccit-spence
@ccit-spence
Jul 20 2015 09:13
so out of the box the interaction between zuul and the UI service would result in the UI services URL appearing in the browser if left as default. Correct?
Dave Syer
@dsyer
Jul 20 2015 09:13
It depends on the implementation of your template doesn't it?
Templates often have to wrangle base url paths. E.g. for apps that get deployed with different context roots in different environments.
So there's nothing very unusual here
ccit-spence
@ccit-spence
Jul 20 2015 09:14
for api’s if they are called through zuul the url appears correctly
Dave Syer
@dsyer
Jul 20 2015 09:15
Again, it's implementation dependent.
Spring Data REST has a sensible implementation
ccit-spence
@ccit-spence
Jul 20 2015 09:15
yes that makes sense to get the urls paths correct for the links after the page is loaded
Dave Syer
@dsyer
Jul 20 2015 09:15
If you roll your own links in your API you will have exactly the same problem
ccit-spence
@ccit-spence
Jul 20 2015 09:15
so SDR is providing some magic under the hood. and spring mvc needs a little help
to put it simply
Dave Syer
@dsyer
Jul 20 2015 09:16
I guess you could say that
I'm not sure it's really accurate
Since SDR is only using Spring MVC to do this
So any app or API can choose to do the same
ccit-spence
@ccit-spence
Jul 20 2015 09:17
that is true
so why do my api get proxied correctly and the UI do not?
this is a very basic UI right now with one view
Dave Syer
@dsyer
Jul 20 2015 09:17
Because SDR conciously always tries to give you absolute links, unless you ask it not to
It has no choice but to construct them
ccit-spence
@ccit-spence
Jul 20 2015 09:18
I am talking about the actual url in the browser
I understand that the links within the app need adjustment
Dave Syer
@dsyer
Jul 20 2015 09:19
Well the URL that your browser loads when you click a link is a computed value as well
E.g. if the browser thinks it is relative.
ccit-spence
@ccit-spence
Jul 20 2015 09:20
not a clicked link, I am doing in the browser http://zuulurl/ui/service it returns http://uihost/ui/service
Dave Syer
@dsyer
Jul 20 2015 09:20
I don't really know what these questions are leading to. You sometimes have to compute URIs (or paths) for links.
How do you mean "returns"?
ccit-spence
@ccit-spence
Jul 20 2015 09:22
the url in the browser displays the direct link not http://zuulurl/ui/service
it is acting more like a forward than a proxy
Dave Syer
@dsyer
Jul 20 2015 09:22
That sounds like a redirect
E.g. if your backend sends a 302 and didn't compute the location
Look at the HTTP traffic (F12 in the browser)
ccit-spence
@ccit-spence
Jul 20 2015 09:24
it is sending a 302
Dave Syer
@dsyer
Jul 20 2015 09:27
That's what you need to fix then
Wherever it calculates the location header
You need to compute it
ccit-spence
@ccit-spence
Jul 20 2015 09:28
in this case it would be default spring cloud zuul
I will take a look a little more. I had been trying it from one applciation to another. now I have it down to zuul itself will continue researching
Dave Syer
@dsyer
Jul 20 2015 09:31
The location header is not computed by zuulj
It's up to your app to do that
ccit-spence
@ccit-spence
Jul 20 2015 09:32
as far as deciding what to respond with then needs to happen within the spring mvc app?
Dave Syer
@dsyer
Jul 20 2015 09:33
Yes. The x-forwarded- headers are a contract between the proxy and the backend. It's up to the backend to use them if needed.
ccit-spence
@ccit-spence
Jul 20 2015 09:34
so read the header sent from zuul and respond with the approriate header. which in turn tells the browser what url to display.
Thanks for the help. Sorry for the initial confusion on my part
Dave Syer
@dsyer
Jul 20 2015 09:37
How are you sending the redirect? It's possible there's something in MVC that could be changed to make it less of an effort.
ccit-spence
@ccit-spence
Jul 20 2015 09:39
The only thing in the MVC app other than default config is an addResourceHandler
actually, that is wrong. It does have Spring Mobile. That shouldn’t be doing a redirect though
Dave Syer
@dsyer
Jul 20 2015 11:07
Maybe the redirect comes from the container? is it the home page?
ccit-spence
@ccit-spence
Jul 20 2015 11:09
yes, it is the home page
Dave Syer
@dsyer
Jul 20 2015 11:10
Maybe it wouldn't happen if you added a "/" to the URL then (the container sends a redirect if you load the home page without the trailing "/")
ccit-spence
@ccit-spence
Jul 20 2015 11:10
I will give that a try
right now server.context-path = /ui/service
Dave Syer
@dsyer
Jul 20 2015 11:11
I don't think that's relevant
ccit-spence
@ccit-spence
Jul 20 2015 11:13
zuul.routes.service.path = /ui/service/**
stripPrefix = false
Dave Syer
@dsyer
Jul 20 2015 11:14
I also don't think that's relevant
ccit-spence
@ccit-spence
Jul 20 2015 11:14
thought I would throw it out
ccit-spence
@ccit-spence
Jul 20 2015 11:28
I added it to a test prod environment http://beta.craftcruises.com/
in the top nav bar if you click the cruises link it will show the problem
Dave Syer
@dsyer
Jul 20 2015 11:30
Yeah, well it's easy to see from the browser. The question remains where is the 302 coming from?
If you add the "/" you get through to the backend (as I predicted)
But it's an error. No idea if that is expected or not.
It just wants a login page that it seems you haven't provided
ccit-spence
@ccit-spence
Jul 20 2015 11:33
no there is not one
Dave Syer
@dsyer
Jul 20 2015 11:33
So can't you fix that just be changing your menu bar?
adding the "/"
ccit-spence
@ccit-spence
Jul 20 2015 11:34
this is in the security though
.antMatchers("/ui/yarn").permitAll()
I will need to look at it later today. With a fresh mind. I am still up from yesterday.
Dave Syer
@dsyer
Jul 20 2015 11:42
Get some sleep then
ccit-spence
@ccit-spence
Jul 20 2015 11:42
thanks for the help
Matt Reynolds
@mattreyuk
Jul 20 2015 14:56
thanks @dsyer I'll check that out
Matt Reynolds
@mattreyuk
Jul 20 2015 19:59
@dsyer I got the config client retry working - for some reason I can
't get the retry debug to show up and I was trying to set spring.cloud.config.retry properties instead of spring.config.retry
Dave Syer
@dsyer
Jul 20 2015 20:52
Oops. Actually that looks like a mistake on our part ("spring.config.retry"). Oh well.
We can change it in 1.1 I guess