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:
Solved! Go to 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;
}