I am trying to implement spring boot webservice application as given in spring docs :
https://spring.io/guides/gs/consuming-web-service/
Build was successful, request and response java files was created and , but when executed spring-boot:run , it gives
Caused by: org.springframework.ws.client.WebServiceIOException: I/O error: Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:561)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at hello.WeatherClient.getCityForecastByZip(WeatherClient.java:30)
at hello.Application.main(Application.java:20)
But the URL is accessible via web browser in eclipse. Kindly help me solve this issue
Make sure all your tests declared with same #SpringBootTest annotation parameters.
I had same issue because of different parameters in two tests. Problem gone when I made all annotations same:
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT))
The web Service URL you are trying to call may be not reachable or it gets timeout. Ensure the web Service URL path is correct and is listening. also verify the timeout duration set and the time taken from your request.
PS. Also check if there is some firewall issue at Server side.
For firewall issue, you might need to provide proxy details(proxyHost and proxyPort) In client code.
EDIT:
I am not able to find appropriate blog or something which explains it better. but found one question on stackoverflow which has similar answer : here
Related
There are two microservices (microservice-A & microservice-B), written in Spring boot, are talking to each other through the Feign Client and the services are registered in K8S Native service registry
Whenever a fresh deployment of a microservice-A is happening, the microservice-B that is already running in kubertnetes fails to make HTTP call to the freshly deployed service-A and below is the exception
feign.RetryableException: No route to host (Host unreachable) executing GET http://microserice-a/api/v1/myresources
This issue is getting resolved immediately after restarting the microservice-B.
When we googled for solutions, we got to see this link https://github.com/spring-cloud/spring-cloud-netflix/issues/769 and an user had given the below comment there
I suspect the root cause is that FeignClient keeps an old list of service providers and the Ribbon cannot move correctly to the next node if one node has been destroyed
Not sure if that is correct root cause. Please comment If anyone has faced similar issue and solved it?
I have below architecture in my project
My UI Service(Port 8080) making Feign call to Gateway Service(Port 8085).
My Get call from UI service is " http://localhost:8080/invoice-list?startDate=2018-08-05&endDate=2018-10-05 "
Similar call from Gateway Service "http://localhost:8085/invoice-download-service/invoice-list?startDate=2018-08-05&endDate=2018-10-05"
When i make this GET call from UI service i get below error within minute
is feign.RetryableException: Read timed out executing GET http://localhost:8085/invoice-download-service/invoice-list?startDate=2018-08-05&endDate=2018-10-05] with root cause
java.net.SocketTimeoutException: Read timed out
But when i make direct call from Gateway Server to microservice, i dont get error.
Application.properties file of Gateway service
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=160000000
ribbon.OkToRetryOnAllOperations=true
ribbon.ReadTimeout=5000000
ribbon.ConnectTimeout=5000000
ribbon.MaxAutoRetries=3
ribbon.MaxAutoRetriesNextServer=3
zuul.host.socket-timeout-millis= 5000000
zuul.host.connect-timeout-millis= 5000000
Here i have set readtimeout and connecttimeout property around 8 to 10 min, hence i am not getting error.
Application.properties file of UI service
spring.application.name=external-ui-service
server.port=8080
Here in UI service i dont have timeout property. I tried above properties here but not working.
Obviously this UI service is not using ribbon,zuul etc. This is just an making Feign call to gateway.
So what should i do to increase timeout in UI service?
Added below properties in UI Service's application.propeties file.
feign.client.config.default.connectTimeout: 160000000
feign.client.config.default.readTimeout: 160000000
This issue might also be caused by default laodbalancer implementation of Spring Cloud Gateway in case you make use of Eureka Server and run your microservices undockerized on windows. Services are running on localhost, but Eureka says to the loadbalancer of the gateway to route the request to host.docker.internal.
The links down below give a couple of solutions:
https://localcoder.org/spring-boot-cloud-eurka-windows-10-eurkea-returns-host-docker-internal-for-clien
https://dimitr.im/fix-eureka-localhost
I am developing a REST service which will connect to a CTI server through TCP and the connection will be kept opened until the my REST service is running.
Currently I am reading the server parameters from properties file and creating bean, after the bean is constructed, the server connection will be initiated using #PostConstruct. Is it good to use #PostConstruct for this scenario or should I use context refresh event.
I tested application using both #PostConstruct and context refresh, both are working good how ever I want to follow the best practices.
Note : I searched the forum and got some answers, but not related to my scenario
Technically there is no difference. You have already tested that part. I think #PostConstruct makes more sense mainly because the connection you are creating is specific to this bean. Creating a new ApplicationContextListener wouldn't make much sense as the connection is not at a context level.
There are many REST services running which are Spring boot projects and are proxied via Apache Web Server. Now I am facing below issues:- 1. Randomly I get Response body does not contain any data but HTTP status Code is proper. So, why there is No Body even though the server is setting up the Body. In apache I just do ProxyPass /test http://localhost:7000/test
2. The response headers sometimes have Connection close and sometime keep Alive. Why there is a difference in Request header?Do I need to modify any default settings of ApacheServer? Can this happen due to Load on Apache Server? Can someone please give some pointers as to why this is happening.
I am also facing similar issue. Suddenly my spring boot application is not responding. Day before it was fine. I am developing JSF appliation - using Spring boot and primefaces. I remember, I was updating xhtml page and during deploying below stack-trace was thrown -
java.lang.IllegalStateException: The resources may not be accessed if they are not currently started
at org.apache.catalina.webresources.StandardRoot.validate(StandardRoot.java:245)
at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:212)
at org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:206)
at org.apache.catalina.core.ApplicationContext.getResource(ApplicationContext.java:554)
at org.apache.catalina.core.ApplicationContextFacade.getResource(ApplicationContextFacade.java:199)
at org.springframework.web.context.support.ServletContextResource.exists(ServletContextResource.java:102)
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.addStaticIndexHtmlViewControllers(WebMvcAutoConfiguration.java:276)
Note that I was using Spring boot 1.2.6.RELEASE, so I updated pom.xml to use latest version 1.3.3.RELEASE. Now deploy was successful, but Chrome web browser gets no response and blank page displayed. However, Firefox give below error in the page -
XML Parsing Error: no element found Location: http://127.0.0.1:8080/index.xhtml Line Number 1, Column 1:
Changed from embedded Tomcat to Jetty, but Jetty provides below stack-track during deploying -
javax.servlet.ServletException: Faces Servlet#87ee159b==javax.faces.webapp.FacesServlet,1,false
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:637)
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:396)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedWebAppContext$JettyEmbeddedServletHandler.deferredInitialize(JettyEmbeddedWebAppContext.java:46)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedWebAppContext.deferredInitialize(JettyEmbeddedWebAppContext.java:36)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.handleDeferredInitialize(JettyEmbeddedServletContainer.java:167)
at org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer.start(JettyEmbeddedServletContainer.java:114)
... 10 common frames omitted
Caused by: java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
at javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:555)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:283)
at javax.faces.webapp.FacesServlet.init(FacesServlet.java:358)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:616)
Any light into this is highly appreciated.
I use spring cloud and the FeignRibbonClient to access remote services. The problem is, that this client ignores the retry configuration given by the properties:
example-client.ribbon.MaxAutoRetries=5
example-client.ribbon.MaxAutoRetriesNextServer=5
example-client.ribbon.OkToRetryOnAllOperations=true.
The retryHandlers are created without any configuration. What I want to get is to retry the next server after ConnectException. What I get is a RetryableException caused by a ConnectException.
Does anybody knows how to get the client call to the next server in case of a ConnectException?
Thanx
Lutz