Pivotal Cloud Foundry Support

 View Only

 Zuul not able to route using serviceId when deployed on pcf but works perfectly fine on local system

Rushali Chaurasiya's profile image
Rushali Chaurasiya posted Nov 01, 2018 02:35 PM

I am trying to deploy eureka service registry on pcf. Currently, 2 client applications, 1 UI and a gateway api (consisting of zuul) are successfully running on pcf. The routing mechanism used in zuul for the 2 client applications are url-based. Now, as we are introducing service registry, we have made the following changes in application.properties of the gateway:


eureka.client.serviceUrl.defaultZone=http://service-registry............./eureka (url generated for service registry)






The following setup is working perfectly fine in local system. But when deploying on pcf, the gateway is not able to route the UI request to service 1 throwing the following error:

XMLHttpRequest cannot load http://gateway.apps.dev-pcf.lb1.rbsgrp.net/service1/query. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://service1.apps.dev-pcf.lb1.rbsgrp.net' (this is the link for our UI) is therefore not allowed access. The response had HTTP status code 500.

Need help resolving it. Thanks.

Daniel Mikusa's profile image
Daniel Mikusa

Are you using Spring Cloud Services' Service Registry or did you build your own service registry from scratch using OSS Spring Cloud?

Rushali Chaurasiya's profile image
Rushali Chaurasiya

I have built service registry from scratch. The services are getting registered. Service Registry is working fine.

Attachment  View in library
Capture.PNG 60 KB
Daniel Mikusa's profile image
Daniel Mikusa

>The response had HTTP status code 500.


Where are you seeing the 500 error? What is the associated stack trace? There should be a stack trace with more details about what is failing.


>XMLHttpRequest cannot load http://gateway.apps.dev-pcf.lb1.rbsgrp.net/service1/query. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://service1.apps.dev-pcf.lb1.rbsgrp.net' (this is the link for our UI) is therefore not allowed access.


I'm also confused about this bit. If everything is behind a Zuul proxy, then all the requests from the client/browser should be made under the `http://gateway.app_domain` URL. They would get send to different backend services, but the client would never know about those backend services or URLs. It kind of sounds like something is off here, but I'm not sure I understand enough about how you have things configured to say what. Can you expand more on how this is configured?

Rushali Chaurasiya's profile image
Rushali Chaurasiya

Hi, sorry for responding so late.

I have tried to deploy small demo applications in order to troubleshoot the problem and gain further understanding.

I will also try to share a demo repo of the code that I have deployed (as uptil now all development has taken place in my office network which I am not allowed to share)


I have deployed Eureka server, a zuul service and a client service on PCF. Zuul and client both are getting registered with Eureka. On my local machine, zuul service is able to route to the client service when I send the request. But, when deployed on PCF, it isn't able to.

I have attached the dependencies that I have used. Please let me know if further details are required.

Also, the urls generated for the 3 services on PCF (we have 2 servers) are as follows:

Client: 1) http://client-dev.apps.dev-pcf.lb1.rbsgrp.net (same on both the servers)

2) https://client-dev.edi01-apps.dev-pcf2.lb1.rbsgrp.net (for server 1)


https://client-dev.edi02-apps.dev-pcf2.lb1.rbsgrp.net (for server 2)

3) this one has been generated by me as custom route for both the servers



Similar are the cases with zuul and service-registry as well. But the custom urls generated for them by me on both the servers are:


Zuul: http://zuul.apps.dev-pcg.lb1.rbsgrp.net


Service Registry: http://service-registry.apps.dev-pcf.lb1.rbsgrp.net

Attachment  View in library
print.docx 29 KB
Rushali Chaurasiya's profile image
Rushali Chaurasiya

The error stack trace that I obtained when i am trying to request the URL http://zuul.apps.dev-pcf.lb1.rbsgrp.net/client/hello

is attached.



Attachment  View in library
error.txt 25 KB
Daniel Mikusa's profile image
Daniel Mikusa

I'm not totally sure what is going on here, but instead of a valid hostname or IP, it looks like a guid of some kind (maybe from the registry?) is being passed to Zuul instead. This is triggering a DNS request because the JVM thinks it's a DNS name and that DNS look up is failing.


>Caused by: java.net.UnknownHostException: 0ce43452-5402-4e63-413b-8409: Name or service not known


Look over your config again, make sure Zuul is set to work with the Eureka/Registry. If you need more help than that, I'd suggest opening a ticket with Pivotal Support. We can have someone take a closer look and help debug this issue.

Rushali Chaurasiya's profile image
Rushali Chaurasiya

Yes, this is the definite problem as in the logs I see that zuul gateway is able to recognise the client:

2018-11-19T15:19:47.276+05:30 [APP/PROC/WEB/0] [OUT] 2018-11-19 09:49:47.276 INFO 14 --- [nio-8080-exec-4] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client client initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=client,current list of Servers=[9ae1a084-2755-4e6e-74b4-c805:8080],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone; Instance count:1; Active connections count: 0; Circuit breaker tripped count: 0; Active connections per server: 0.0;]


But it is throwing unknown host error when it is trying to route it:

2018-11-19T15:19:47.587+05:30 [APP/PROC/WEB/0] [OUT] Caused by: java.lang.RuntimeException: java.net.UnknownHostException: 9ae1a084-2755-4e6e-74b4-c805: Name or service not known


Is there any way to resolve this? I mean how can I set the zuul to route the request to the client not through the DNS look up but any other method?

Daniel Mikusa's profile image
Daniel Mikusa

I'm not certain as you've put this app together from scratch and I have no visibility into how you've done that. I would suggest double checking the config that you're using for Zuul & for your service registry.

Rushali Chaurasiya's profile image
Rushali Chaurasiya

When we hit http://c6245f14-aceb-4f0e-45fd-dfb5:8080/actuator, it gives DNS not found error. But, https://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/ displayes the required result as follows: {"_links":{"self":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator","templated":false},"archaius":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/archaius","templated":false},"auditevents":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/auditevents","templated":false},"beans":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/beans","templated":false},"caches-cache":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/caches/{cache}","templated":true},"caches":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/caches","templated":false},"health":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/health","templated":false},"health-component":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/health/{component}","templated":true},"health-component-instance":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/health/{component}/{instance}","templated":true},"conditions":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/conditions","templated":false},"configprops":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/configprops","templated":false},"env":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/env","templated":false},"env-toMatch":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/env/{toMatch}","templated":true},"info":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/info","templated":false},"loggers":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/loggers","templated":false},"loggers-name":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/loggers/{name}","templated":true},"heapdump":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/heapdump","templated":false},"threaddump":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/threaddump","templated":false},"metrics":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/metrics","templated":false},"metrics-requiredMetricName":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/metrics/{requiredMetricName}","templated":true},"scheduledtasks":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/scheduledtasks","templated":false},"httptrace":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/httptrace","templated":false},"mappings":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/mappings","templated":false},"refresh":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/refresh","templated":false},"features":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/features","templated":false},"service-registry":{"href":"http://client.edi01-apps.dev-pcf2.lb1.rbsgrp.net/actuator/service-registry","templated":false}}}


And at last, https://demo-gateway.edi01-apps.dev-pcf2.lb1.rbsgrp.net/client/hello gives the following error:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Nov 22 09:44:12 GMT 2018

There was an unexpected error (type=Internal Server Error, status=500).



Rushali Chaurasiya's profile image
Rushali Chaurasiya

I was able to resolve the issue by adding the following properties in my client application:




This is enabling the client to register to service-registry using the application-uri rather than GUID.

Thanks for the help.

Daniel Mikusa's profile image
Daniel Mikusa

Thanks for posting your solution!