File tree Expand file tree Collapse file tree 2 files changed +25
-13
lines changed
aws-serverless-java-container-jersey/src
main/java/com/amazonaws/serverless/proxy/jersey
test/java/com/amazonaws/serverless/proxy/jersey Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Original file line number Diff line number Diff line change @@ -97,22 +97,10 @@ public void destroy() {
9797 @ SuppressFBWarnings ({ "SERVLET_HEADER" , "SERVLET_QUERY_STRING" })
9898 private ContainerRequest servletRequestToContainerRequest (ServletRequest request ) {
9999 Timer .start ("JERSEY_SERVLET_REQUEST_TO_CONTAINER" );
100- URI basePathUri ;
101100 URI requestPathUri ;
102101 String basePath = "/" ;
103102 HttpServletRequest servletRequest = (HttpServletRequest )request ;
104103
105- try {
106- if (servletRequest .getContextPath ().equals ("" )) {
107- basePathUri = URI .create (basePath );
108- } else {
109- basePathUri = new URI (servletRequest .getContextPath ());
110- }
111- } catch (URISyntaxException e ) {
112- log .error ("Could not read base path URI" , e );
113- basePathUri = URI .create (basePath );
114- }
115-
116104 UriBuilder uriBuilder = UriBuilder .fromPath (servletRequest .getPathInfo ());
117105 uriBuilder .replaceQuery (AwsProxyHttpServletRequest .decodeValueIfEncoded (servletRequest .getQueryString ()));
118106
@@ -125,7 +113,7 @@ private ContainerRequest servletRequestToContainerRequest(ServletRequest request
125113 apiGatewayProperties .setProperty (JERSEY_SERVLET_REQUEST_PROPERTY , servletRequest );
126114
127115 ContainerRequest requestContext = new ContainerRequest (
128- basePathUri ,
116+ URI . create ( basePath ), // for routing within Jersey we always assume the base path is "/"
129117 requestPathUri ,
130118 servletRequest .getMethod ().toUpperCase (Locale .ENGLISH ),
131119 (SecurityContext )servletRequest .getAttribute (JAX_SECURITY_CONTEXT_PROPERTY ),
Original file line number Diff line number Diff line change @@ -278,6 +278,30 @@ public void exception_mapException_mapToNotImplemented() {
278278 assertEquals (Response .Status .NOT_IMPLEMENTED .getStatusCode (), response .getStatusCode ());
279279 }
280280
281+ @ Test
282+ public void stripBasePath_route_shouldRouteCorrectly () {
283+ AwsProxyRequest request = new AwsProxyRequestBuilder ("/custompath/echo/status-code" , "GET" )
284+ .json ()
285+ .queryString ("status" , "201" )
286+ .build ();
287+ handler .stripBasePath ("/custompath" );
288+ AwsProxyResponse output = handler .proxy (request , lambdaContext );
289+ assertEquals (201 , output .getStatusCode ());
290+ handler .stripBasePath ("" );
291+ }
292+
293+ @ Test
294+ public void stripBasePath_route_shouldReturn404 () {
295+ AwsProxyRequest request = new AwsProxyRequestBuilder ("/custompath/echo/status-code" , "GET" )
296+ .json ()
297+ .queryString ("status" , "201" )
298+ .build ();
299+ handler .stripBasePath ("/custom" );
300+ AwsProxyResponse output = handler .proxy (request , lambdaContext );
301+ assertEquals (404 , output .getStatusCode ());
302+ handler .stripBasePath ("" );
303+ }
304+
281305 private void validateMapResponseModel (AwsProxyResponse output ) {
282306 validateMapResponseModel (output , CUSTOM_HEADER_KEY , CUSTOM_HEADER_VALUE );
283307 }
You can’t perform that action at this time.
0 commit comments