-
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.
* [feat] request multi read filter 추가 #165 * [feat] slack message 내용 추가 #165 * [feat] health check api 생성 * [chore] spotless 적용 #165
- Loading branch information
Showing
9 changed files
with
171 additions
and
12 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
30 changes: 30 additions & 0 deletions
30
Api/src/main/java/allchive/server/api/chore/controller/ChoreController.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,30 @@ | ||
package allchive.server.api.chore.controller; | ||
|
||
|
||
import allchive.server.api.archiving.model.dto.request.UpdateArchivingRequest; | ||
import allchive.server.domain.domains.archiving.domain.enums.Category; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/chore") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Tag(name = "etc. [chore]") | ||
public class ChoreController { | ||
@Operation(hidden = true) | ||
@PostMapping(value = "error/{test}") | ||
public void errorExample( | ||
@RequestBody UpdateArchivingRequest updateArchivingRequest, | ||
@RequestParam("category") Category category, | ||
@PathVariable("test") Long test) { | ||
throw new RuntimeException(); | ||
} | ||
|
||
@Operation(hidden = true) | ||
@GetMapping(value = "health") | ||
public void errorExample() {} | ||
} |
61 changes: 61 additions & 0 deletions
61
Api/src/main/java/allchive/server/api/common/filter/MultiReadInputStream.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,61 @@ | ||
package allchive.server.api.common.filter; | ||
|
||
|
||
import com.amazonaws.util.IOUtils; | ||
import java.io.*; | ||
import javax.servlet.ReadListener; | ||
import javax.servlet.ServletInputStream; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
|
||
public class MultiReadInputStream extends HttpServletRequestWrapper { | ||
private ByteArrayOutputStream cachedBytes; | ||
|
||
public MultiReadInputStream(HttpServletRequest request) { | ||
super(request); | ||
} | ||
|
||
@Override | ||
public ServletInputStream getInputStream() throws IOException { | ||
if (cachedBytes == null) cacheInputStream(); | ||
return new CachedServletInputStream(cachedBytes.toByteArray()); | ||
} | ||
|
||
@Override | ||
public BufferedReader getReader() throws IOException { | ||
return new BufferedReader(new InputStreamReader(getInputStream())); | ||
} | ||
|
||
private void cacheInputStream() throws IOException { | ||
cachedBytes = new ByteArrayOutputStream(); | ||
IOUtils.copy(super.getInputStream(), cachedBytes); | ||
} | ||
|
||
private static class CachedServletInputStream extends ServletInputStream { | ||
private final ByteArrayInputStream buffer; | ||
|
||
public CachedServletInputStream(byte[] contents) { | ||
this.buffer = new ByteArrayInputStream(contents); | ||
} | ||
|
||
@Override | ||
public int read() { | ||
return buffer.read(); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return buffer.available() == 0; | ||
} | ||
|
||
@Override | ||
public boolean isReady() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setReadListener(ReadListener listener) { | ||
throw new RuntimeException("Not implemented"); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Api/src/main/java/allchive/server/api/common/filter/MultiReadInputStreamFilter.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,28 @@ | ||
package allchive.server.api.common.filter; | ||
|
||
|
||
import java.io.IOException; | ||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MultiReadInputStreamFilter implements Filter { | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
MultiReadInputStream multiReadRequest = | ||
new MultiReadInputStream((HttpServletRequest) request); | ||
chain.doFilter(multiReadRequest, response); | ||
} | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
Filter.super.init(filterConfig); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
Filter.super.destroy(); | ||
} | ||
} |
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