Announcement Announcement Module
Collapse
No announcement yet.
Got ResourceAccessException when I am using restTemplate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Got ResourceAccessException when I am using restTemplate

    I download the sample code from Ajren's blog, but got error when try to connect flickr while this URL is working by copying to browser directly.Any suggestion? Thanks.

    String photoSearchUrl =
    "http://www.flickr.com/services/rest?method=flickr.photos.search&api+key={api-key}&tags={tag}&per_page=10";
    Source photos = restTemplate.getForObject(photoSearchUrl, Source.class, apiKey, searchTerm);


    Exception in thread "main" org.springframework.web.client.ResourceAccessExcep tion: I/O error: Connection reset; nested exception is java.net.SocketException: Connection reset
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:359)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:307)
    at org.springframework.web.client.RestTemplate.getFor Object(RestTemplate.java:177)
    at com.springsource.samples.resttemplate.FlickrClient .searchPhotos(FlickrClient.java:58)
    at com.springsource.samples.resttemplate.FlickrClient .doIt(FlickrClient.java:50)
    at com.springsource.samples.resttemplate.Driver.main( Driver.java:35)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream. java:168)
    at java.io.BufferedInputStream.fill(BufferedInputStre am.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStr eam.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStre am.java:317)
    at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:687)
    at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:632)
    at sun.net.http://www.http.HttpClient.parseHTTP...lient.java:652)
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:1072)
    at java.net.HttpURLConnection.getResponseCode(HttpURL Connection.java:373)
    at org.springframework.http.client.SimpleClientHttpRe sponse.getStatusCode(SimpleClientHttpResponse.java :47)
    at org.springframework.web.client.DefaultResponseErro rHandler.hasError(DefaultResponseErrorHandler.java :42)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:345)
    ... 5 more

  • #2
    Valid apy key

    Have you got a valid api key to access flickr?

    Comment

    Working...
    X