Search code examples
spring-bootnetflix-zuulnetflix-eurekaspringfoxkubernetes-ingress

java.lang.NumberFormatException: For input string: "443,80"


I am getting the following exception while hitting my backend Spring boot application which is deployed on a Kubernetes container:

java.lang.NumberFormatException: For input string: "443,80"

All my services are registered with eureka:

#Eureka
spring.application.name=app-name
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka
eureka.instance.preferIpAddress=true
eureka.instance.non-secure-port-enabled=true

And all my requests are routed through ingress/zuul services.

spring.application.name=app-gateway
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=http://app-eureka-dev/eureka

When we try hitting backend services from the Swagger API, I am getting below exception.

java.lang.NumberFormatException: For input string: "443,80"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:580)
    at java.lang.Integer.parseInt(Integer.java:615)
    at springfox.documentation.swagger2.web.HostNameProvider.componentsFrom(HostNameProvider.java:72)
    at springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(Swagger2Controller.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod

I am connecting to the eureka service through the container name, even though I am getting above exception. Is there any other configuration required, as we do ssl offloading in ingress, rest should be plain http or unsecure calls within the container services.


Solution

  • This should have been fixed with Springfox 2.7.0, as can be seen in this GitHub issue and the release notes of this version.

    Before Springfox 2.7.0, the following code was used to determine the port number in HostNameProvider:

    String port = request.getHeader("X-Forwarded-Port");
    
    if (hasText(port)) {
      builder.port(Integer.parseInt(port));
    }
    

    So basically it used the X-Forwarded-Port header to determine the port number. However, in your case it seems like it passes both the HTTP and HTTPS ports (443,80), which is obviously not a valid integer.

    Upgrading your springfox-swagger2 dependency to 2.7.0 (or higher) should do the trick.