Getting the request path from messageContext in a Java callout

Hi,

I am trying to get the request path in a java callout from the messageContext, but could not.

Say, the user makes a request to “https://exampleapi.apigee.net/path/to/resource”, I would like to retrieve the full path (“/path/to/resource” in this case).

I went through the available examples and the docs, but could not come up with a solution.

Any ideas?

Thanks

Assign proxy.basepath to a variable(basepath) & pass as a property/variable in java callout.

In java callout you can fetch

messageContext.getVariable("basepath");
getRequiredProperty("basepath", messageContext);

Ref:

https://docs.apigee.com/api-platform/reference/policies/java-callout-policy#Property

Just read the context variable that is appropriate for you. You can do that in Java with

messageContext.getVariable(String variableName)

Some options for the variable to read are: proxy.basepath, request.uri, request.path, proxy.pathsuffix.

Variable reference here, and a specific table for URIs and paths here.

1 Like

There is no need to assign the value or proxy.basepath to a new variable named “basepath” in order to be able to read the variable value from within a Java callout. The Java callout can directly read the context variable named “proxy.basepath”.

This is exactly what I needed. Thanks a lot