Spring-boot Application Throwing Error on Actuator Port - java

In my Java application, I have kept the server port at: 8090
And the property management.port=9080
Now, in my browser, when I open a random link (http://localhost:9080) on the actuator port, my application throws the following error:
No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'dispatcherServlet'
23/11/2018:18:47:54.350 [http-nio-9080-exec-1] E o.a.c.c.C.[.[.[.[dispatcherServlet] --- Servlet.service() for servlet [dispatcherServlet] threw exception
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.LinkedHashMap
Whereas, when I put management.port=8090 (same as the server port), this error is not thrown when I open a random link.
Is there a way to add a default request handler on the actuator port when it is different from the server port in a spring boot application?

In a standalone application, the Actuator HTTP port defaults to the same as the main HTTP port. To make the application listen on a different port, set the external property: management.server.port. To listen on a completely different network address (such as when you have an internal network for management and an external one for user applications), you can also set management.server.address to a valid IP address to which the server is able to bind.

Related

Spring Cloud Gateway Invalid IPv4 address

I have the following setup:
Spring Cloud Gateway on Port 8080
Routing /user to Spring Rest API (Called User) on Port 9000
Routing /character to Spring Rest API (Called Character) on Port 9001
Spring Cloud Config Server on Port 8090
The Gateway and the two Rest API applications are connected to the Cloud Config to pull the configs. The applications themselves start up correctly and can be used via their respective ports. I tested this by calling /swagger-ui.html which works fine.
When calling /actuator/gateway/routes I get a list of the routes of the gateway, which seem fine.
For all four applications I set up:
server:
address: 0.0.0.0
port: 8080 # ports are adjusted for each service
forward-headers-strategy: framework
When I did not use the Spring Cloud Config Server the Gateway was running fine. Now I'm receiving the following error whenever calling either /user/swagger-ui.html or /character/swagger-ui.html
java.lang.IllegalArgumentException: Invalid IPv4 address: 0:0:0:0:0:0:0:1:60979
at org.springframework.web.util.UriComponentsBuilder.parseForwardedFor(UriComponentsBuilder.java:363) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.web.filter.ForwardedHeaderFilter$ForwardedHeaderExtractingRequest.<init>(ForwardedHeaderFilter.java:246) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.web.filter.ForwardedHeaderFilter.doFilterInternal(ForwardedHeaderFilter.java:149) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.8.jar:5.3.8]
Tried changing forward-headers-strategy to native which did not help either. I dug into the UriComponentBuilder and set some breakpoints to investigate the variables in their and I suspect request.headers["forwarded"] is the reason it fails:
It tries to resolve the "for" inside the variable which is not a IPv4 address and thus fails. Forcing ipv4 with "server.address" seemed to work before using Spring Cloud Config, does not now, however. Has anyone come across the same issue and knows what am I supposed to do to get rid off this exception?
So all in all the routing itself seems to work, as it routes to the correct application. The application itself (User in this case) throws the error, not the Gateway.
The issue is resolved with
Spring gateway version 3.0.4
which you can get from
org.springframework.cloud:spring-cloud-dependencies:2020.0.4

Camel SpringBoot rest servlet connection refused (camel 2.22.0)

I'm having troubles getting any of the simplest springboot servlet rest api examples to work on my machine. I'm just trying to create the simplest possible test api to practice the framework. I have the following code in my Routes RouteBuilder class:
#Component
public class Routes extends RouteBuilder {
#Override
public void configure() {
restConfiguration()//Bind the api servlet to the localhost port 8080
.component("servlet").host("localhost").port(8080)
.bindingMode(RestBindingMode.auto);
rest("/api")//Log any get requests
.get()
.route().to("log:DEBUG?showBody=true&showHeaders=true");
}
}
However, when I try to invoke this code with curl, I get the following error:
curl -X GET http://localhost:8080/api
curl: (7) Failed to connect to localhost port 8080: Connection refused
I'm using camel 2.22.0 and SpringBoot 2.0.4.RELEASE. I'm running this on Ubuntu 20.04 LTS.
EDIT:
I did the changes suggested, but I still get the same Connection refused by curl. My code now looks like this:
restConfiguration()//Bind the api servlet to the localhost port 8080
.component("servlet").host("localhost").port(8080)//Use camel default context path
.bindingMode(RestBindingMode.auto);
rest("/api")//Log any get requests
.get()
.route().to("log:DEBUG?showBody=true&showHeaders=true");
curl -X GET http://localhost:8080/camel/api -> Connection refused
I also now have the following in my application.yml:
server:
port: 8080 #Specify port for camel servlet
max-http-header-size: 32768 # Maximum size in bytes of the HTTP message header.
By default, Camel uses the context path /camel/*.
So, your curl command should look like this:
curl -X GET http://localhost:8080/camel/api
You can control the context path in the following ways.
With restConfiguration
restConfiguration()//Bind the api servlet to the localhost port 8080
.component("servlet").host("localhost").port(8080)
.contextPath("/test/*")
.bindingMode(RestBindingMode.auto);
With application.properties
camel.component.servlet.mapping.context-path=/test/*
For me, only the latter works.
Something worth mentioning here.
You are using the servlet component in your rest definition. In this case, Camel ignores the port configuration and uses the underlying servlet component. As you are using spring-boot, the tomcat port is being used, which by default happens to be 8080.
If for some reason, you change the tomcat port, your rest service port will change.
For example, if you change the server port in the application.properties.
server.port=8180
Your rest service uses that port, ignoring the definition in the restConfiguration.
curl -X GET http://localhost:8180/camel/api
Rest DSL docs

Error launching simple Eureka-Service server

I am following Josh Long's presentation at https://www.youtube.com/watch?v=5q8B6lYhFvE&feature=youtu.be . I am following his examples. At about 34 minutes in he demos setting up the Eureka service.
This service uses the config-service. My config service is running and exposes the information the eureka service needs. I have checked my bootstrap.properties and they look correct according to his presentation. However the eureka service does not complete and does not seem to be accessing the config service. My other service does reach the config service and works fine.
The eureka service should come up at http://localhost:8761/ but does not. It is at 8080.
eureka service bootstrap.properties:
spring.application.name= eureka-service
spring.cloud.config.uri= http://localhost:8888
First error:
2016-10-13 18:43:00.088 ERROR 7464 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
Second error
2016-10-13 18:43:00.097 ERROR 7464 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_EUREKA-SERVICE/RB-64-PC.Home:eureka-service - was unable to refresh its cache! status = Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Found the problem. I had accidently added the "config server" dependency into the project when I created it. I am using the site "http://start.spring.io/" as per the video. Adding the config server dependencies kept the initialization from accessing the actual config server running on another port.

Communication between spring boot dockerized apps

I new using spring boot and docker and I faced a problem running the docker containers.
On debug mode, there is no problem on applications boot, but when I run them as a container, there is something wrong.
For example, I have my server config with all the yml files, also eureka properties.
The config server boot perfectly, but not the eureka server, it must look for it`s configuration to the config server becouse of these:
uri: ${vcap.services.config-service.credentials.uri:http://127.0.0.1:8888}
In the eureka`s log I can found:
Could not locate PropertySource: I/O error on GET request for
"http://127.0.0.1:8888/server-eureka/default":Connection refused;
nested exception is java.net.ConnectException: Connection refused
So I see that eureka cant connect to the config server for a reason I cant understund.
Maybe I miss something in my docker file.
If you are not using docker linked containers you'll have to use only the public ip addresses. Docker will assign every running container an own ip address which is per default not accessible. Only when you start to expose ports there will be an entry to iptables that is linking the hosts public ip address and given port to the internal used port and (dynamically assigned) ip address of the docker container. This is also why 127.0.0.1 does not work cause it would look into the containers local context but tgere the service is not running.

Could not access HTTP invoker remote service

i'm working in a kofax application connected with oracle database.
i found an error as
ERROR markview.viewer.MvViewer
org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [ias9:opmn:ormi://uhmvtst.uhhs.com:6003:markview_tst4/mvas/remote/EnterpriseService]; nested exception is java.net.MalformedURLException: unknown protocol: ias9
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
i'm getting as connection failed to open. could any one help me to solve this issue.
The Spring HTTP invoker is for HTTP. It's not going to work with that URL you gave it (ias9:opmn:ormi://uhmvtst.uhhs.com:6003:markview_tst4/mvas/remote/EnterpriseService)

Categories

Resources