-
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: application/octet-stream 변환로직 추가
- Loading branch information
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 17 additions & 2 deletions
19
backend/src/main/java/org/example/backend/global/config/web/WebConfig.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 |
---|---|---|
@@ -1,19 +1,34 @@ | ||
package org.example.backend.global.config.web; | ||
|
||
import org.example.backend.global.util.OctetStreamReadMsgConverter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
private OctetStreamReadMsgConverter octetStreamReadMsgConverter; | ||
|
||
@Autowired | ||
public WebConfig(OctetStreamReadMsgConverter octetStreamReadMsgConverter) { | ||
this.octetStreamReadMsgConverter = octetStreamReadMsgConverter; | ||
} | ||
|
||
@Override | ||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
converters.add(octetStreamReadMsgConverter); | ||
} | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry corsRegistry) { | ||
|
||
corsRegistry.addMapping("/**") | ||
.allowedOrigins("http://localhost:3000", | ||
"http://sejong-bioconvergence-temp.s3-website.ap-northeast-2.amazonaws.com"); | ||
"http://sejong-bioconvergence-temp.s3-website.ap-northeast-2.amazonaws.com"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/org/example/backend/global/util/OctetStreamReadMsgConverter.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,33 @@ | ||
package org.example.backend.global.util; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.lang.reflect.Type; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OctetStreamReadMsgConverter extends AbstractJackson2HttpMessageConverter { | ||
@Autowired | ||
public OctetStreamReadMsgConverter(ObjectMapper objectMapper) { | ||
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); | ||
} | ||
|
||
// 기존 application/octet-stream 타입을 쓰기로 다루는 메시지 컨버터가 이미 존재 (ByteArrayHttpMessageConverter) | ||
// 따라서 해당 컨버터는 쓰기 작업에는 이용하면 안됨 | ||
@Override | ||
public boolean canWrite(Class<?> clazz, MediaType mediaType) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean canWrite(MediaType mediaType) { | ||
return false; | ||
} | ||
} |