-
Notifications
You must be signed in to change notification settings - Fork 560
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
API Gateway Path Mapping Problem #112
Comments
Hey @feinstein, you can use the handler.setStripBasePath("/service/prod"); Alternatively, you can grab the current config and modify it I'll add this to the docs. |
Oh, interesting, I will take a look at this, thanks! |
@sapessi I can't find the My |
Yeah, I can find it in the sample. My handler would change like this: public class StreamLambdaHandler implements RequestStreamHandler {
private final ResourceConfig jerseyApplication = new ResourceConfig()
.packages("com.amazonaws.serverless.sample.jersey")
.register(JacksonFeature.class);
private final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler
= JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
public StreamLambdaHandler() {
// we enable the timer for debugging. This SHOULD NOT be enabled in production.
Timer.enable();
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.stripBasePath("/service/prod");
AwsProxyRequest request = LambdaContainerHandler.getObjectMapper().readValue(inputStream, AwsProxyRequest.class);
AwsProxyResponse resp = handler.proxy(request, context);
LambdaContainerHandler.getObjectMapper().writeValue(outputStream, resp);
System.err.println(LambdaContainerHandler.getObjectMapper().writeValueAsString(Timer.getTimers()));
// just in case it wasn't closed by the mapper
outputStream.close();
}
} |
I am sorry, my bad, it's late in here, I made a typo and auto-complete wasn't working, ops! |
@sapessi now I am getting I will try to see the path being passed logging Are there any caveats on using the |
For routing, I'm looking into the path. |
I see, it makes sense. |
@sapessi where is the code that actually strips the base path? I want to double check it's logic to see the final path, so I cant figure out why both URLs now return 404. |
The path is stripped by the request reader. Here's the call to it and here's the method implementation |
Thanks! I will try to figure out what is going on here.... |
thanks. Ping here if you think there's something wrong |
@sapessi I modified my
So basically I am just logging the Now is the part that I really don't understand what's going on, in my logs I can see that the My Custom Domain Name invocation log looks like this:
And my regular URL logs look like this:
So the path is Now, if I remove the line Custom Domain Name log:
Regular URL:
And now I only get a My Jersey application is configured to work correctly when I don't understand how the regular URL fails and returns 404 in the first case and executes correctly in the second case, when the path is correctly set to |
Weird. I'll create some unit tests tomorrow specifically for jersey
and see what I can figure out. I'll ping you here as soon as I have
something
S
…On 1/30/18, feinstein ***@***.***> wrote:
@sapessi I modified my `StreamLambdaHandler` to include the following code:
```
handler.stripBasePath("/service/prod");
AwsProxyRequest request =
LambdaContainerHandler.getObjectMapper().readValue(inputStream,
AwsProxyRequest.class);
LOGGER.error("Path before: " + request.getPath());
AwsProxyResponse resp = handler.proxy(request, context);
LOGGER.error("Path after: " + request.getPath());
LambdaContainerHandler.getObjectMapper().writeValue(outputStream, resp);
// just in case it wasn't closed by the mapper
outputStream.close();
```
So basically I am just logging the `path` before and after it's stripped
out.
Now is the part that I really don't understand what's going on, in my logs I
can see that the `path` is being stripped out correctly, but I still get a
404!
My Custom Domain Name invocation log looks like this:
```
Path before: /service/prod/test
Initialize Jersey application handler
Path after: /test
```
And my regular URL logs look like this:
```
Path before: /test
Path after: /test
```
So the path is `/test` at end, at both, and I get a `404` on both.
Now, if I comment out the `handler.stripBasePath("/service/prod");`, My logs
are:
Custom Domain Name log:
```
Path before: /service/prod/test
Path after: /service/prod/test
```
Regular URL:
```
Path before: /test
Initialize Jersey application handler
Path after: /test
```
And now I only get a `404` on the Custom Domain Name URL, but the regular
URL works fine!
My Jersey application is configured to work correctly when `path` is
`/test`, as it does for the regular URL. But as soon as I set
`handler.stripBasePath("/service/prod");`, `path` becomes `/test` for all
the URLs and my regular URL stops working. Since there's no base path to be
stripped, `stripBasePath` should be transparent, but apparently there are
side effects and I can't pinpoint where they are since the stripping code
seems to be correct.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#112 (comment)
--
--
Stefano Buliani
@sapessi
http://www.flickr.com/photos/sapessi/
|
@sapessi perfect. If you need anything from me, please let me know. Thank you once again! |
… bug introduced with the fixes for #84. Added unit tests
Hey @feinstein, found the issue and pushed a fix to the |
Fix routing issue with Jersey when stripBasePath is configured (addresses #112)
@sapessi great! let me know when it's out so I can test it. |
@feinstein 0.9.1 is making its way to maven central. Should be there within the hour. |
@sapessi it works perfectly now! I will probably make some sort of configuration file to provide the URL to be stripped out, since there are Thank you for all the help, you are the best! |
Scenario
All the details of this issue can be found on this AWS Forums thread.
Basically, regular URLs and Custom Domain Name URLs From API Gateway, inconsistently map their URL paths to the invoked a Lambda Function.
Here's my invocation logs, from bot a regular API Gateway URL and a Custom Domain Name URL:
Custom Domain Name URL:
Regular URL:
The same Lambda Function, invoked with both URLs will produce different resutls, since the
path
being passed is different, the Lambda Function invoked with:will execute normaly, but the same Lambda Function invoked with:
will return
404
since the path being passed toJersey
by this framework will be an invalid one.Expected behavior
Calling both APIs will invoke the Lambda Function consistently with the same path and both will execute on the same way.
Actual behavior
will execute normaly, but the same Lambda Function invoked with:
will return
404
since the path being passed toJersey
by this framework will be an invalid one.Steps to reproduce
1 - Create a new API Gateway
{proxy+}
method that invokes a Lambda Function running Jersey2 - Create a Custom Domain Name and a basepath mapping for that Lambda Function
3 - Invoke the API using both URLs
From the logs:
Custom Domain Name URL:
Regular URL:
I can see the
pathParameters
are the same on both cases, but thepath
is different.Is this library using the
path
and this is the source of the problem? Could it change to using thepathParameters
instead?The text was updated successfully, but these errors were encountered: