diff --git a/backend/src/main/java/org/example/backend/global/config/web/WebConfig.java b/backend/src/main/java/org/example/backend/global/config/web/WebConfig.java index ca3d8ab6..80f1d116 100644 --- a/backend/src/main/java/org/example/backend/global/config/web/WebConfig.java +++ b/backend/src/main/java/org/example/backend/global/config/web/WebConfig.java @@ -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> 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"); } } \ No newline at end of file diff --git a/backend/src/main/java/org/example/backend/global/util/OctetStreamReadMsgConverter.java b/backend/src/main/java/org/example/backend/global/util/OctetStreamReadMsgConverter.java new file mode 100644 index 00000000..71265eb7 --- /dev/null +++ b/backend/src/main/java/org/example/backend/global/util/OctetStreamReadMsgConverter.java @@ -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; + } +} \ No newline at end of file