Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong redirection in containerized environment #38

Open
bfedoronchuk opened this issue Aug 2, 2021 · 4 comments
Open

Wrong redirection in containerized environment #38

bfedoronchuk opened this issue Aug 2, 2021 · 4 comments

Comments

@bfedoronchuk
Copy link

bfedoronchuk commented Aug 2, 2021

Environment Details

  • OS: MacOS
  • Docker version: 20.10.5 Community
  • JDK version: 11
  • MicroProfile implementation: Helidon MP
  • Helidon Version: 2.3.2

Problem Description

Path /openapi-ui redirects to the wrong URI if the MicroProfile app is running inside of Docker container. Extension swaps the host and port to values defined by the container.

I haven't dived deep into the bug, but at least I realized that injected javax.ws.rs.core.UriInfo provides the wrong base URI. As far as I know, Helidon uses Jersey as JAX-RS implementation. So, this problem could be Jersey-specific.

Steps to reproduce

Steps to reproduce:

  1. Setup Helidon MP (Microprofile implementation) example project.
mvn -U archetype:generate -DinteractiveMode=false \
    -DarchetypeGroupId=io.helidon.archetypes \
    -DarchetypeArtifactId=helidon-quickstart-mp \
    -DarchetypeVersion=2.3.2 \
    -DgroupId=io.helidon.examples \
    -DartifactId=openapi-ui-issue \
    -Dpackage=io.helidon.examples.quickstart.mp;
  1. Go to pom.xml and add the dependency.
<dependency>
    <groupId>org.microprofile-ext.openapi-ext</groupId>
    <artifactId>openapi-ui</artifactId>
    <version>1.1.4</version>
</dependency>
  1. Go to the project.
cd openapi-ui-issue;
  1. Build Docker image.
docker build -t openapi-ui-issue . 
  1. Run Docker container.
docker run --rm -p 9090:8080 openapi-ui-issue:latest
  1. Open http://127.0.0.1:9090/openapi-ui in the browser.
    Browser redirects to the wrong path: http://172.17.0.2:8080/openapi-ui/index.html
    Where 172.17.0.2 is the Docker container internal IP and 8080 is the port of the app running inside of the container.

By the way, everything works fine if you specify the full path: http://127.0.0.1:9090/openapi-ui/index.html

@phillip-kruger
Copy link
Member

Hi. Thanks for this. I'll be honest I have no idea how to fix this.

But this is the problem code:

URI fw = uriInfo.getRequestUriBuilder().path(INDEX_HTML).build();

We can maybe introduce a new config where the user can specify the correct base in this case.
Or, we can let the redirect happen on the client, so download a small html on this url that does the redirect.

You are welcome to do a PR ??

@bfedoronchuk
Copy link
Author

Sure, will try.

@rsoika
Copy link

rsoika commented Jan 12, 2022

I currently stumbled over this issue. I thought this feature is already implemented? There is this environment variable MP_OPENAPI_SERVERS which you can set for example in a docker-compose file:

  my-service:
    image: imixs/my-service
    environment:
      # Payara-Micor ENV
      MP_OPENAPI_SERVERS: "http://localhost:8081"

and I have a project in production where I used this and it works.

But now I currently try to build another project and the variable is ignored. So now I have the same problem and I wonder how I have managed to get this working in my other project (based on microprofile 2.2)

See also the openapi documentation here

@rsoika
Copy link

rsoika commented Jan 12, 2022

I figured out that it is an issue from openapi and not from the openapi-ui. If you annotate your rest application with the correct data the information is shown through openapi and also used by openapi-ui

@ApplicationPath("api")
@OpenAPIDefinition(info = @Info(
        title = "Example application", 
        version = "1.0.0", 
        contact = @Contact(
                name = "John", 
                email = "john@foo.com",
                url = "https://www.foo.com")
        ),
        servers = {
            @Server(url = "/",description = "localhost")
        }
)
public class BaseApplication extends Application {

}

Now I wonder how I can overwrite the 'severs' sections in a container based runtime environment....? The environment variable MP_OPENAPI_SERVERS id no longer work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants