Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error: Request path cannot be empty

I have created an API proxy where I am setting the target endpoint dynamically using the JS Policy. The URL does not contain any path (i.e https://example.com). I can think of hacks to resolve this, but I want to know why am I getting this error. What if the target service has no path in the URL?

Here is a screenshot for your reference:

muq_ash_0-1736510607403.png

 

Solved Solved
0 7 303
1 ACCEPTED SOLUTION

Apigee behaves this way because when you don't specify a path in the TargetConnection, Apigee automatically adds a default path (/).
This is handled in the getTargetPath() method:

 

@Override
@XmlTransient
public String getTargetPath() {
    return this.path == null ? HttpProxyConnection.PATH_SEPARATOR : this.path;
}

 

However, when you set the target.url directly, this automatic behaviour doesn't occur. If the path is missing, Apigee throws an error due to the path validation logic:

private boolean validatePath(HTTPRequest request) {
    if (request != null && request.requestURI != null && !HTTPMethod.CONNECT.equals(request.method)) {
        if (request.requestURI.getURI().isEmpty()) {
            this.requestListener.onException(this, false, new BadRequestException(ErrorCodes.EMPTY_PATH));
            return true;
        } else if (request.requestURI.getURI().startsWith("?")) {
            this.requestListener.onException(this, false, new BadRequestException(ErrorCodes.BAD_PATH));
            return true;
        } else {
            return false;
        }
    }
    return false;
}

View solution in original post

7 REPLIES 7