关于在Bluemix环境中调用Weather rest api的问题

时间:2016-12-27 10:54:59

标签: ibm-cloud

我在Bluemix中调用Weather Company Rest API服务时遇到错误。在本地环境中使用相同的代码,我可以从此调用获得响应。请分享您的建议。

代码:

RestTemplate restTemplate=new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", "application/json");
    HttpEntity entity = new HttpEntity(headers);
    ResponseEntity<WeatherStatusWrapper> jsonString = restTemplate.exchange(srcURL, HttpMethod.GET, entity, WeatherStatusWrapper.class);

错误:

  

12/27/2016 10:06:43 AM ERR App [ERROR] SRVE0777E:应用程序类抛出的异常&#39; org.springframework.web.servlet.FrameworkServlet.processRequest:982&#39;   12/27/2016 10:06:43 AM ERR App org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是org.springframework.web.client.HttpClientErrorException:401 Unauthorized   12/27/2016 10:06:43 AM org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)上的ERR App   12/27/2016 10:06:43 AM org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)上的ERR App   12/27/2016 10:06:43 AM错误应用程序在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)   12/27/2016 10:06:43 AM org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)上的ERR App   12/27/2016 10:06:43 AM ERR App at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)   12/27/2016 10:06:43 AM [内部课程]的ERR App   12/27/2016 10:06:43 AM org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)的ERR App   12/27/2016 10:06:43 AM org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)的ERR App   12/27/2016 10:06:43 AM org.springframework.web.client.RestTemplate.execute的ERR App(RestTemplate.java:557)   12/27/2016 10:06:43 AM org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:289)的ERR App   12/27/2016 10:06:43 AM ERR App at com.techm.bluemix.smarterairport.ServiceImpl.WeatherServiceImpl.trackWeatherForecast(WeatherServiceImpl.java:94)   12/27/2016 10:06:43 AM ERR App at com.techm.bluemix.smarterairport.Controller.WeatherController.trackWeatherForecast(WeatherController.java:47)   12/27/2016 10:06:43 AM ERR App at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   12/27/2016 10:06:43 AM ERR App at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)   12/27/2016 10:06:43 AM ERR App at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)   12/27/2016 10:06:43 AM错误应用程序在java.lang.reflect.Method.invoke(未知来源)   12/27/2016 10:06:43 AM orr.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)上的ERR App   12/27/2016 10:06:43 AM ERR App at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)   12/27/2016 10:06:43 AM ERR App at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)   12/27/2016 10:06:43 AM ERR App at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)   12/27/2016 10:06:43 AM org.springframework.web.servlet.DispatcherServlet.doDispatch的ERR App(DispatcherServlet.java:959)   12/27/2016 10:06:43 AM org.springframework.web.servlet.DispatcherServlet.doService的ERR App(DispatcherServlet.java:893)   12/27/2016 10:06:43 AM org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)上的ERR App

1 个答案:

答案 0 :(得分:0)

投掷401 Unauthorized Error。该请求需要身份验证。用户名和密码可以从CONNECTIONS TAB->获得。在Bluemix应用程序仪表板中查看证书