-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: on exception log 500 status code instead of 200 status code (#65
- Loading branch information
Showing
38 changed files
with
1,838 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...web/src/main/java/com/getyourguide/openapi/validation/filter/OpenApiValidationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.getyourguide.openapi.validation.filter; | ||
|
||
import com.getyourguide.openapi.validation.api.selector.TrafficSelector; | ||
import com.getyourguide.openapi.validation.core.OpenApiRequestValidator; | ||
import com.getyourguide.openapi.validation.factory.ContentCachingWrapperFactory; | ||
import com.getyourguide.openapi.validation.factory.ServletMetaDataFactory; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
@Slf4j | ||
@AllArgsConstructor | ||
public class OpenApiValidationFilter extends OncePerRequestFilter { | ||
public static final String ATTRIBUTE_SKIP_VALIDATION = "gyg.openapi-validation.skipValidation"; | ||
public static final String ATTRIBUTE_REQUEST_META_DATA = "gyg.openapi-validation.requestMetaData"; | ||
|
||
private final OpenApiRequestValidator validator; | ||
private final TrafficSelector trafficSelector; | ||
private final ServletMetaDataFactory metaDataFactory; | ||
private final ContentCachingWrapperFactory contentCachingWrapperFactory; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
var requestMetaData = metaDataFactory.buildRequestMetaData(request); | ||
request.setAttribute(ATTRIBUTE_REQUEST_META_DATA, requestMetaData); | ||
if (!validator.isReady() || !trafficSelector.shouldRequestBeValidated(requestMetaData)) { | ||
request.setAttribute(ATTRIBUTE_SKIP_VALIDATION, true); | ||
request.setAttribute(ATTRIBUTE_SKIP_VALIDATION, true); | ||
filterChain.doFilter(request, response); | ||
return; | ||
} | ||
|
||
var requestToUse = contentCachingWrapperFactory.buildContentCachingRequestWrapper(request); | ||
var responseToUse = contentCachingWrapperFactory.buildContentCachingResponseWrapper(response); | ||
filterChain.doFilter(requestToUse, responseToUse); | ||
|
||
// in case the response was cached it has to be written to the original response | ||
if (!isAsyncStarted(requestToUse)) { | ||
var cachingResponse = contentCachingWrapperFactory.getCachingResponse(responseToUse); | ||
if (cachingResponse != null) { | ||
cachingResponse.copyBodyToResponse(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean shouldNotFilterAsyncDispatch() { | ||
return false; | ||
} | ||
} |
158 changes: 0 additions & 158 deletions
158
...src/main/java/com/getyourguide/openapi/validation/filter/OpenApiValidationHttpFilter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.