WSO2 APIM 4.2: Issue using Azure Load Balancer with distributed WSO2 environments

71 views Asked by At

We are testing with two API-Managers 4.2 running on two Virtual Machines.

edit:
Both published using the LB address as hostname
(eg. hostname = "example.site.loadbalancer.com")
And /etc/hosts configured pointing to each respective IP
(eg. x.x.x.x example.site.loadbalancer.com)

The issue here is when trying to access both Publisher/DevPortal using the internal IP for each instance. The APIM redirects to the LB address (eg. https://x.x.x.x:9443/publisher being redirected to https://example.site.loadbalancer.com:9443/publisher/services/auth/login) and we get an invalid "Sign In" page:

APIM 4.2 Login after redirecting from x.x.x.x to example.site.loadbalancer.com

The wso2carbon.log show those messages:

ERROR {org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/authenticationendpoint].[oauth2_login.do]} - Servlet.service() for servlet [oauth2_login.do] threw exception java.lang.IllegalStateException: Cannot forward after response has been committed

ERROR - [default] Servlet.service() for servlet [default] in context with path [/authenticationendpoint] threw exception [An exception occurred processing [plugins/basicauth-extensions.jsp] at line [32]

29:         request.setAttribute("errorMsg", AuthenticationEndpointUtil
30:                 .i18n(resourceBundle, "something.went.wrong.contact.admin"));
31:         IdentityManagementEndpointUtil.addErrorInformation(request, e);
32:         request.getRequestDispatcher("error.jsp").forward(request, response);
33:         return;
34:     }
35:     File typingPatternRecorder = new File(getServletContext().getRealPath("plugins/typing-dna.jsp")); 

Stacktrace:] with root cause java.lang.IllegalStateException: Cannot forward after response has been committed

ERROR - [jsp] Servlet.service() for servlet [jsp] threw exception java.lang.IllegalStateException: Cannot create a session after the response has been committed

ERROR - [localhost] Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/generic-exception-response.jsp] org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.IllegalStateException: Cannot create a session after the response has been committed

  1. Tried changing the deployment.toml configurations and addresses to prevent the redirect. (No success)
  2. Tried publishing the APIM using the internal IP and this solved the Login Page, but I was unable to consume and execute API's using the Load Balancer Endpoint. (No success)
  3. Tried the 4.1.0 version and the latest updates versions for both 4.1.0 and 4.2.0. (No success)
  4. With version 3.2.0 I had success, but we're trying to be up to the latest version.
1

There are 1 answers

0
Pubci On

You can change the hostname of the server as explained here. https://apim.docs.wso2.com/en/latest/install-and-setup/setup/deployment-best-practices/changing-the-hostname/#changing-the-api-m-hostname

[server]
hostname = "{hostname}"

You have few options for the hostname value here.

  1. Use the IP address as the hostname here.
  2. Use a domain name you prefer and this can be your LB hostname as well. If the domain doesn't get resolved, you can add an entry to /etc/hosts until the proper DNS entries are set.