Skip to content

Fix incorrect gateway URL port (-1) in Dev Portal when custom tenant URL is used with HTTP-only APIs. #13066

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

Merged

Conversation

Dakshithas
Copy link
Contributor

Scenario

This issue occurs when:

  • A tenant has a custom gateway domain configured (e.g., via registry path /customurl/api-cloud/...)
  • An API is created under that tenant with only HTTP transport enabled

As a result:

  • The Dev Portal shows a incorrect gateway URL like http://example.com:-1/context/version
  • The Try Out page fails to load because the Swagger API call returns incomplete server details (missing gateway URLs)

Fix

  • Fixes the -1 port issue by correctly setting the port.
  • Fixes Swagger server URL generation by determining the correct transport protocol (HTTP or HTTPS) based on the API’s transport level security.

Related Issue: wso2/api-manager#3819

Copy link

coderabbitai bot commented Apr 2, 2025

📝 Walkthrough

Walkthrough

This pull request updates the API management functionality in two components. In the API consumer implementation, the logic for processing custom URLs now checks for both HTTP and HTTPS protocols, defaulting to assign the URL to both when no valid prefix is present. In the API mapping utility, error handling is added to manage malformed custom gateway URLs, with enhancements for extracting the HTTP port and context from the provided URL.

Changes

File(s) Change Summary
components/apimgt/.../APIConsumerImpl.java Updated the getHostWithSchemeMappingForEnvironment method to first check if customUrl is non-null and then verify if it starts with "http://" or "https://". If neither condition is met, the URL is assigned to both HTTP and HTTPS protocols. The method signature remains the same.
components/apimgt/.../APIMappingUtil.java Introduced error handling in the fromAPIRevisionToEndpoints method by creating a URL object from customGatewayUrl and throwing an APIManagementException upon a malformed URL. Enhanced logic for extracting the HTTP port—defaulting to VHost.DEFAULT_HTTP_PORT if necessary—and setting the HTTP context from the URL path.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant APIConsumerImpl
    Client->>APIConsumerImpl: getHostWithSchemeMappingForEnvironment(api, org, env)
    APIConsumerImpl->>APIConsumerImpl: Check if customUrl is not null
    APIConsumerImpl->>APIConsumerImpl: Verify if customUrl starts with "http://" or "https://"
    alt Valid prefix found
        APIConsumerImpl->>APIConsumerImpl: Map customUrl to corresponding protocol
    else No valid prefix
        APIConsumerImpl->>APIConsumerImpl: Map customUrl to both HTTP and HTTPS
    end
    APIConsumerImpl-->>Client: Return protocol mapping
Loading
sequenceDiagram
    participant Client
    participant APIMappingUtil
    Client->>APIMappingUtil: fromAPIRevisionToEndpoints(apiRevision, customGatewayUrl)
    APIMappingUtil->>APIMappingUtil: Attempt to create URL from customGatewayUrl
    alt URL creation error
        APIMappingUtil-->>Client: Throw APIManagementException
    else URL creation successful
        APIMappingUtil->>APIMappingUtil: Extract HTTP port and context from URL
        APIMappingUtil-->>Client: Return endpoints configuration
    end
Loading

Suggested reviewers

  • pubudu538
  • chamilaadhi
  • tgtshanika
  • Arshardh

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.31.1)
components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 851fa71 and 51c52d3.

📒 Files selected for processing (2)
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java (1 hunks)
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/mappings/APIMappingUtil.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/apimgt/org.wso2.carbon.apimgt.rest.api.store.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/store/v1/mappings/APIMappingUtil.java
  • components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-product (4, group4)
  • GitHub Check: build-product (2, group2)
  • GitHub Check: build-product (3, group3)
  • GitHub Check: build-product (1, group1)
  • GitHub Check: build-carbon
  • GitHub Check: run-benchmark-test
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

…n custom tenant URL is used with HTTP-only APIs.
@npamudika npamudika merged commit 985c407 into wso2:master May 15, 2025
12 of 16 checks passed
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

Successfully merging this pull request may close these issues.

3 participants