Spring中的Openshift监控,403 Forbidden错误

时间:2018-02-01 08:45:23

标签: java api spring-boot openshift http-status-code-403

我有这样的例外:

点子:

  

用于servlet [dispatcherServlet]的Servlet.service()与path的上下文   []引发异常[请求处理失败;嵌套异常是   org.springframework.web.client.HttpClientErrorException:403   禁止有根本原因

     

org.springframework.web.client.HttpClientErrorException:403 Forbidden

浏览器声明

Fri Feb 02 08:34:11 CET 2018 出现意外错误(type = Internal Server Error,status = 500)。 403禁止

我想从openshift获取pod列表。

我的代码:

    @GetMapping("getPods")
    public List<Pod> podsUpdate(){
        HttpHeaders headres = new HttpHeaders();
        headres.set("Authorization","Bearer <token>");
        RestTemplate template = new RestTemplate();
        JsonObjectPods jsonObjectPods = null;

        TrustManager[] trustAllCerts = new TrustManager[] {
                new X509TrustManager() {
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return new X509Certificate[0];
                    }
                    public void checkClientTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }
                    public void checkServerTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }
                }
        };

// Install the all-trusting trust manager
        try {
            SSLContext sc = SSLContext.getInstance("SSL");
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (GeneralSecurityException e) { }
// Now you can access an https URL without having the certificate in the truststore

            jsonObjectPods = template.getForObject("https://<openshift_address>/api/v1/pods", JsonObjectPods.class, headres);

0 个答案:

没有答案