J.Y.S
¿ whats my interest ?
J.Y.S
전체 방문자
오늘
어제
  • 분류 전체보기 (59)
    • 트러블슈팅 기록 (7)
    • Java&Kotlin (5)
    • Server (22)
    • 데이터 엔지니어링 (3)
    • Architecture& Design Patter.. (1)
    • Daily (11)
    • 알고리즘 공부 (9)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
J.Y.S

¿ whats my interest ?

트러블슈팅 기록

[spring/openfeign] Multipart 파일과 함께 json을 페이로드에 담아 다른 서버로 요청보낼 때 400 에러 발생(spring->fast-api)

2022. 10. 24. 02:12

문제 상황

spring-boot 프레임워크를 사용하는 서버(A)에서 다른 서버로 feign client를 통해 파일과 함께 json 형식의 데이터를 페이로드에 담아 요청하려고 할 때, 400 Bad Request Parameter 에러가 발생

  • Content type: multipart/form-data

원인

feign으로 content-type이 multipart/form-data인 요청을 보낼 때 파일이 아닌 사용자 지정 POJO를 담게 되면 에러가 발생하는 이슈가 있었음.

해결

JsonFormWriter를 사용해서 configuration에 빈으로 등록하면 된다!

class feignClientConfiguration {
    @Bean
    fun jsonFormWriter(): JsonFormWriter {
        return JsonFormWriter()
    }
}

참고한 openfeign 이슈: Allow @RequestPart user-defined POJOs #314

 

Allow @RequestPart user-defined POJOs by darrenfoong · Pull Request #314 · spring-cloud/spring-cloud-openfeign

I'm using Spring Cloud OpenFeign, and I have a use case where I need to send multiple files and user-defined POJOs as multipart/form-data, for example: @PostMapping("/items") SomeResponse uploadIte...

github.com

JsonFormWriter 분석:

JsonFormWriter를 사용하면 객체를 string으로 변환해서 요청이 보내지게끔 처리가 된다.
관련 JsonFormWriter의 코드: https://github.com/spring-cloud/spring-cloud-openfeign/pull/314/files#diff-e9d712f747ccab80c570f8c2a2e56fd1d24415435db437257f5cef2537d9a108R43

저작자표시 (새창열림)

'트러블슈팅 기록' 카테고리의 다른 글

[Nginx] Permission denied) while connecting to upstream: SELinux 설정 문제 (Centos, RHEL)  (0) 2023.08.19
클라우드 서버 포트 열기 (iptables, firewall)  (0) 2023.08.14
multipart/form-data로 요청 보낼 때 swagger에서는 안되고 postman, curl로만 되는 문제( feat.n주째 미해결😭)  (1) 2022.12.15
[Python] 'requests' has no attribute 'delete'  (0) 2022.11.08
[트러블슈팅] fast api 에서 ValidationError 발생 시 500 에러가 발생& payload가 맞는데도 validation error 뜸  (0) 2022.10.22
    '트러블슈팅 기록' 카테고리의 다른 글
    • 클라우드 서버 포트 열기 (iptables, firewall)
    • multipart/form-data로 요청 보낼 때 swagger에서는 안되고 postman, curl로만 되는 문제( feat.n주째 미해결😭)
    • [Python] 'requests' has no attribute 'delete'
    • [트러블슈팅] fast api 에서 ValidationError 발생 시 500 에러가 발생& payload가 맞는데도 validation error 뜸
    J.Y.S
    J.Y.S

    티스토리툴바