스프링에서 외부 API 호출하기
https://jie0025.tistory.com/531
https://doohee94.tistory.com/19
에러메세지
경로 [/ai]의 컨텍스트 내의 서블릿 [appServlet]을(를) 위한 Servlet.service() 호출이, 근본 원인(root cause)과 함께...
https://threeyears.tistory.com/89
위 글 시작부분을 보다가 @inject를 서비스 클래스 마다마다 줘야하나 싶어서 넣어줬더니 해결
https://thalals.tistory.com/266
Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.Object] and content type [application/octet-stream]
하다가 이런 오류가 나왔고 콘텐트 타입 문제인 것 같았다.
위 블로그에서 헤더 바꾸는 코드 본 것 같아서
header.setContentType(new MediaType("application", "json", Charset.forName("UTF-8")));
위에 코드 추가했으나 여전히 같은 오류메세지를 뱉었다.
더 찾아보니
https://circlee7.medium.com/resttemplate-host-header-e30596ab04dd
restTemplate.getInterceptors().add((request, body, execution) -> {
ClientHttpResponse response = execution.execute(request,body);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
return response;
});
이걸로 추가
패스
새로운 에러메세지 hi~
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
https://ayoteralab.tistory.com/entry/Spring-BootError-JSON-parse-error-Unexpected-character
...흠... 나는 request URL만 주면 되는데..
그냥 script단에서 ajax로 통신했던 걸 java로 해보는 중인데 이전에 성공했던 거랑 비교하니 Headers부분이 달랐다.
https://circlee7.medium.com/resttemplate-host-header-e30596ab04dd
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Unexpected character ('<' (code 60))
구글링해보니 결과가 JSON으로 반환되야하는데 <로 시작하는 XML형식으로 넘어와서 생기는 문제라고 했다.
도통 왜 XML로 넘어오는지 모르겠었는데 에러메세지를 xml로 넘겨주더라..
프로그램 로그보고 차이점 비교해보니
&outputFormat=application/json;%20subtype=geojson 넘겨줬는데
&outputFormat=application/json;%2520subtype%3Dgeojson 로 바뀌는 바람에
아래처럼 에러가 떴다.
&outputFormat=application/json; subtype%3Dgeojson로 넘겨주니 괜찮아졌다.
https://bepoz-study-diary.tistory.com/183
java.lang.IllegalArgumentException: protocol = http host = null
..?
String url = http://localhost:8880/orange/wfs?GDX=ai0001.xml
UriComponentsBuilder.newInstance()
.path(url)
이걸로 만들었는데 왜
http:/localhost :8880/orange/wfs?GDX=ai0001.xml?~
가 만들어졌지..?
/하나 어디로 감..?
https://blog.naver.com/PostView.naver?blogId=aservmz&logNo=222322019981