Skip to content
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

Http 500 error when navigating to Swagger UI #465

Closed
sameer-coder opened this issue Sep 18, 2023 · 6 comments
Closed

Http 500 error when navigating to Swagger UI #465

sameer-coder opened this issue Sep 18, 2023 · 6 comments
Assignees
Labels

Comments

@sameer-coder
Copy link

Hello,

We have deployed imposter on AWS lambda using the imposter-awslambda.zip package. We are using the Open API plugin to serve content from a bunch of open API 3.0.1 specs. Everything works great except when we navigate to the Swagger UI, it throws a 500 error. This is only happening with the imposter instance deployed on AWS Lambda. Locally, running with imposter.jar it is working fine.

Any help would be appreciated.

Stack trace

2023-09-15 13:59:48 9d51be98-cc0e-482c-9bdb-a4bb57f854f5 ERROR i.g.i.s.ResourceServiceImpl - Unhandled routing exception for request: GET http://esmdev.lambda-url.us-west-2.on.aws/_spec
java.lang.RuntimeException: Route failed: HttpRoute(path=null, regex=/_spec$, method=GET)
	at io.gatehill.imposter.awslambda.impl.LambdaServer.dispatch(LambdaServer.kt:99) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.HandlerV2.handleRequest(HandlerV2.kt:68) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.HandlerV2.handleRequest(HandlerV2.kt:57) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:205) ~[aws-lambda-java-runtime-0.2.0.jar:?]
	at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:905) ~[aws-lambda-java-runtime-0.2.0.jar:?]
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:261) ~[aws-lambda-java-runtime-0.2.0.jar:?]
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:200) ~[aws-lambda-java-runtime-0.2.0.jar:?]
	at lambdainternal.AWSLambda.main(AWSLambda.java:194) ~[aws-lambda-java-runtime-0.2.0.jar:?]
Caused by: java.lang.RuntimeException: Unhandled exception processing request [3b7a0973-11c3-43e0-9dab-d758e57f860b] GET http://esmdev.lambda-url.us-west-2.on.aws/_spec
	at io.gatehill.imposter.service.ResourceServiceImpl.handleFailure(ResourceServiceImpl.kt:337) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl.access$handleFailure(ResourceServiceImpl.kt:84) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl$handleRoute$1.invoke(ResourceServiceImpl.kt:141) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl$handleRoute$1.invoke(ResourceServiceImpl.kt:137) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.impl.LambdaServer.dispatch(LambdaServer.kt:93) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	... 7 more
Caused by: java.lang.NullPointerException
	at io.gatehill.imposter.http.HttpRoute$parsedPathParams$2.invoke(HttpRoute.kt:67) ~[imposter-http-3.29.0.jar:?]
	at io.gatehill.imposter.http.HttpRoute$parsedPathParams$2.invoke(HttpRoute.kt:64) ~[imposter-http-3.29.0.jar:?]
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.8.22.jar:1.8.22-release-407(1.8.22)]
	at io.gatehill.imposter.http.HttpRoute.getParsedPathParams(HttpRoute.kt:64) ~[imposter-http-3.29.0.jar:?]
	at io.gatehill.imposter.http.HttpRoute.extractPathParams(HttpRoute.kt:115) ~[imposter-http-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.impl.model.LambdaHttpRequestV2$pathParameters$2.invoke(LambdaHttpRequestV2.kt:66) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.impl.model.LambdaHttpRequestV2$pathParameters$2.invoke(LambdaHttpRequestV2.kt:65) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.8.22.jar:1.8.22-release-407(1.8.22)]
	at io.gatehill.imposter.awslambda.impl.model.LambdaHttpRequestV2.getPathParameters(LambdaHttpRequestV2.kt:65) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.impl.model.LambdaHttpRequestV2.getPathParams(LambdaHttpRequestV2.kt:94) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	at io.gatehill.imposter.http.SingletonResourceMatcher.matchRequest(SingletonResourceMatcher.kt:74) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.http.AbstractResourceMatcher.filterResourceConfigs(AbstractResourceMatcher.kt:131) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.http.AbstractResourceMatcher.matchResourceConfig(AbstractResourceMatcher.kt:79) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl.handleResource(ResourceServiceImpl.kt:292) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl.access$handleResource(ResourceServiceImpl.kt:84) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl$handleRoute$1.invoke(ResourceServiceImpl.kt:139) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.service.ResourceServiceImpl$handleRoute$1.invoke(ResourceServiceImpl.kt:137) ~[imposter-engine-3.29.0.jar:?]
	at io.gatehill.imposter.awslambda.impl.LambdaServer.dispatch(LambdaServer.kt:93) ~[imposter-adapter-awslambda-3.29.0.jar:?]
	... 7 more

@outofcoffee
Copy link
Owner

Hi @sameer-coder, thank you for reporting this.

There is improved handling of regex routes in Lambda in v3.31.1. Please could you let us know if this resolves the issue?

@outofcoffee
Copy link
Owner

outofcoffee commented Oct 2, 2023

Hi @sameer-coder, there were some further fixes required to static asset handling in Lambda to get this working.

These are released in v3.31.2.

@sameer-coder
Copy link
Author

Thanks @outofcoffee

I will deploy again and report back on the issue

@sameer-coder
Copy link
Author

sameer-coder commented Oct 3, 2023

Hello,

Thanks for the update. I no longer get a 500 error but now I am facing the same problem mentioned in this open issue

At the moment, Imposter serves the swagger UI at https://domain.com/_spec. But this path is unreachable because of the way routing is setup in API Gateway. The API Gateway only forwards requests to imposter which match a pattern (example- https://domain.com/api/v1)

The endpoints in the OpenAPI spec still work fine because I can specify /api/v1 as the basePath in the imposter config as well as the OpenAPI spec. Imposter handles this perfectly.

Probably we could add an env var to set a basePath for Swagger UI so that the url becomes https://domain.com/<basePath>/_spec

Thanks for the help!

@outofcoffee
Copy link
Owner

outofcoffee commented Nov 12, 2023

Hi @sameer-coder, from v3.32.0 you can set the environment variable IMPOSTER_OPENAPI_SPEC_PATH_PREFIX, to override the default /_spec prefix.

For example:

IMPOSTER_OPENAPI_SPEC_PATH_PREFIX="/api/core-mock/v1/_spec"

...will make the spec UI accessible at http://localhost:8080/api/core-mock/v1/_spec/

@sameer-coder
Copy link
Author

Amazing! Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants