春季启动微服务OAuth2TokenRelayFilter 500错误

时间:2019-05-18 12:16:49

标签: java reactjs spring-boot spring-security-oauth2 netflix-zuul

我正在从事微服务架构的春季启动项目。 我有一个微服务(报告),网关和注册表。该微服务在端口8082上运行,该端口已在注册表中注册。

网关在端口8080上运行。在从邮递员向报告微服务发出API请求时,我得到了预期的响应。

我的要求: GET:https://www.simoahava.com/analytics/introducing-gtm-tools/

但是当我从我的React APP发出GET请求时,却遇到了错误。

{  
   "timestamp":"2019-05-02T10:54:48.591+0000",
   "status":500,
   "error":"Internal Server Error",
   "message":"pre:OAuth2TokenRelayFilter"
}

这是XHR的邮递员请求,工作正常。

var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
 if (this.readyState === 4) {
   console.log(this.responseText);
 }
});

xhr.open("GET", "https://<url>/report/v1");
xhr.setRequestHeader("Authorization", "Bearer <jwt token>");

xhr.send(data);

以下是有关来自react的呼叫的摘要。

{
HEADERS : {

    General :{

        Request URL: <url>/report/v1
        Request Method: GET
        Status Code: 500 Internal Server Error
        Remote Address: <IP>:443
        Referrer Policy: no-referrer-when-downgrade 
    }, 

    Response Headers : {

        Access-Control-Allow-Headers: x-requested-with, Accept, Content-Type, Authorization
        Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE,PUT
        Access-Control-Allow-Origin: http://localhost:3000
        Access-Control-Max-Age: 3600
        Cache-Control: no-cache, no-store, max-age=0, must-revalidate
        Connection: keep-alive
        Content-Type: application/json;charset=UTF-8
        Date: Tue, 21 May 2019 05:27:22 GMT
        Expires: 0
        Pragma: no-cache
        Server: nginx/1.14.0 (Ubuntu)
        Transfer-Encoding: chunked
        X-Content-Type-Options: nosniff
        X-XSS-Protection: 1; mode=block
    }

    Request Headers: { 

        Provisional headers are shown
        Authorization: Bearer <jwt_token>
        Origin: http://localhost:3000
        Referer: http://localhost:3000/welcome
        User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36
    }
}, 

PREVIEW : {

    {timestamp: "2019-05-21T05:27:22.186+0000", status: 500, error: "Internal Server Error",…} 
    error: "Internal Server Error"
    message: "pre:OAuth2TokenRelayFilter"
    status: 500
    timestamp: "2019-05-21T05:27:22.186+0000"
},

RESPONSE {

    {"timestamp":"2019-05-21T05:27:22.186+0000","status":500,"error":"Internal Server Error","message":"pre:OAuth2TokenRelayFilter"}
}

}

这就是我从React App拨打电话的方式:

export default class ReportService {
  static call = {
    getReport: 'getReport'
  };
  static callAxios(options) {
    return axios(options)
      .then(res => res.data)
      .catch(err => Promise.reject(err));
  }
  static get(callTo, item) {
    let url = null;
    switch (callTo) {
      case ReportService.call.getReport:
        url = new URL("report/v1");
        break;
    }
url = ReportService.initParams(url, item);
return ReportService.callAxios({ method: 'get', url });
  }
  static initParams(url, item) {
    if (item && item.params) {
      let queryParams = Object.entries(item.params);
      if (queryParams.length > 0) {
        queryParams.forEach(([key, value]) => {
          if (api.params[key]) {
            url.searchParams.append(api.params[key], value);
          }
        });
      }
    }
    return url;
  }
}

我没有弄清楚到底是怎么回事。任何帮助表示赞赏。

0 个答案:

没有答案