-
Notifications
You must be signed in to change notification settings - Fork 559
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
SpringBootLambdaContainerHandler doesn't set the contextPath #84
Comments
Thanks for the feedback @loki2302 - I believe older versions of the library set the content path from the stage. We removed this because it was causing issues in other places. I'll test again to figure out what was happening, if possible I'll add the stage back in the context path. |
Hey @agibalov, I went back to explore this. The reason why I stayed away from including the stage name in the path is that stages don't necessarily map to servlets. Further, if you configure a custom domain name in API Gateway and point it directly to a stage the base path goes away. One change I'm contemplating is:
With these changes, you will need to set the strip base path and base path properties in the |
I've looked a bit deeper into this. There is no easy way for me to claim that the context path is the stage (see custom domain name issue above). Instead, I'm relying on the @Override
public String getContextPath() {
if (config.isUseStageAsServletContext()) {
String contextPath = cleanUri(request.getRequestContext().getStage());
if (config.getServiceBasePath() != null) {
contextPath += cleanUri(config.getServiceBasePath());
}
return contextPath;
} else {
return "" + (config.getServiceBasePath() != null ? cleanUri(config.getServiceBasePath()) : "");
}
} To get the desired effect, you can initialize the container handler with: SpringLambdaContainerHandler.getContainerConfig().setUseStageAsServletContext(true);
AwsProxyResponse output = handler.proxy(request, lambdaContext); |
Closing this issue as it should be resolved in the latest commit |
@sapessi I've just upgraded to 0.9 and removed all the custom code I had to write to make Spring MVC URL builder functionality work in 0.8. Thanks! |
… bug introduced with the fixes for #84. Added unit tests
… bug introduced with the fixes for #84. Added unit tests
Spring provides a nice mechanism to build URLs by referencing controller classes and their handler methods:
Internally, this mechanism relies on the current
ServletRequest
and namely itsgetContextPath()
method.I see that while my
AwsProxyRequest
has these details:getPath(): /hello
getRequestContext().getPath(): /Dummy/hello
getResource(): /{proxy+}
SpringBootLambdaContainerHandler
creates theServletRequest
object like this:getPathInfo(): /hello
getPathTranslated(): null
getContextPath():
getServletPath(): /hello
getServletContext().getContextPath(): /
As a result, when I build the URL, the API Gateway's "stage" part is lost ("Dummy" is a stage) and instead of
http://apigw/Dummy/hello
, I gethttp://apigw/hello
.We're using
aws-serverless-java-container-spring:0.8
withspring-boot-starter-web:1.5.3.RELEASE
.The text was updated successfully, but these errors were encountered: