2017-11-10 1 views
0

을 무시하는 이유는 다음과 같은 그루비 코드가 : 그것은 rootUri처럼 보이는RestTemplate은 rootUri

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "/some/resource": null; nested exception is org.apache.http.client.ClientProtocolException 
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:666) 
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:628) 
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:590) 
    … 
Caused by: org.apache.http.client.ClientProtocolException 
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187) 
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) 
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) 
    at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:89) 
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) 
    … 
Caused by: org.apache.http.ProtocolException: Target host is not specified 
    at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71) 
    at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:125) 
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) 
... 15 more 

이 RestTemplateBuilder에 의해 무시되고있다 :

def test(){ 
    RequestEntity request=RequestEntity.method(HttpMethod.GET,new URI("/some/resource")) 
     .accept("text/plain") 
     .build() 

    def template=new RestTemplateBuilder() 
     .rootUri("http://example.com/api") 
     .build() 
    def response=template.exchange(request,String) 
    assert response.statusCode.value()==200 
} 

그것은 이런 식으로 뭔가를 반환합니다. '/'로 시작하는 모든 요청을 'http://example.com/api'을 (를) 추가하는 방법이 있습니까?

+0

이 가능합니까? – ajc

+0

@ajc 좋은 생각. 내 경우에는 리팩토링 및/또는 기타 창의적인 변경이 필요하지 않습니다. – User1

답변

1

비슷한 문제가있었습니다.

restTemplate.postForEntity("/foo", request, SomeClass.class) 

그래서 기본적으로

restTemplate.postForEntity(URI.create("/foo", request, SomeClass.class) 

을 변경하여 해결, 문자열로 경로를 지정하려고하지 URI있다. 그 후에는 rootUri을 존중해야합니다. 희망이 도움이됩니다.

행동은 여기에서 설명 : 당신이 요청 객체를 구성하기 전에 확인을하는 https://github.com/spring-projects/spring-boot/issues/7891

+0

참조 된 문제는 'TestRestTemplate'에 대해 이야기합니다. 실제 'RestTemplate'동작은 변경되지 않습니다. String을 전달하면 RootUri 핸들러가 호출됩니다. URI를 전달하면 그렇지 않습니다. – Andreas

관련 문제