APEX ORDS 休息 API returns content-type:text/html

APEX ORDS Rest API returns content-type:text/html

我们已经在带有 ORDS 和 Weblogic 应用服务器的应用服务器上安装了 Oracle APEX。我们正在尝试使用它来创建简单的 ReST APIs,以便从我们的数据库 (11gR2) 中获取数据。我开发了一个 HTML 页面,它使用 jqgridjson 数据从 ReST API 转换为表格网格。 jqgrid 对 URI 的 GET 请求遇到了 404 Resource not found 错误。

jqgrid 代码看起来像这样-

 $("#jqGrid").jqGrid({
                url: 'http://nsrmss01:9002/ords/oracle_retail_rest/comm/js',
                mtype: 'GET',
                datatype: 'json'
                styleUI : 'Bootstrap',                
                colModel: [
                    { label: 'Database', name: 'DBNAME', width: 100,editable: true },
                    { label: 'SID', name: 'DBSID', width: 100,editable: true },
                    { label: 'Port', name: 'DBPORT', width: 100,editable: true },
                    { label: 'Last Refreshed', name: 'LASTREFRESHED', width: 150,editable: true ,
                            edittype : 'text',
                            editoptions: {
                            // dataInit is the client-side event that fires upon initializing the toolbar search field for a column
                            // use it to place a third party control to customize the toolbar
                            dataInit: function (element) {
                               $(element).datepicker({
                                                        autoclose: true,
                                                        format: 'dd-M-yyyy',
                                                        orientation : 'bottom'
                                });
                            }
                        }
                      },
                    { label: 'Server Status', name: 'STATUS', width: 150,editable: true ,
                              edittype: "select",
                              editoptions: {
                                    value:"AVAILABLE:Available;UNREACH:Unreachable;DOWN:Down"}
                    }
                ],
                        viewrecords: true,
                height: 250,
                loadonce: true,
                rowNum: 20,
                pager: "#jqGridPager"
            });

该网页有一个简单的 jqgrid table,它应该加载如下所示的 json 内容([=18= 上的 root dbdata 有 3 行]数组)-

{
   "dbdata":    [
            {
         "dbname": "servdbp01",
         "dbsid": "PROD",
         "dbport": 1621,
         "status": "AVAILABLE"
      },
            {
         "dbname": "servdbd06",
         "dbsid": "DEV01",
         "dbport": 1621,
         "lastrefreshed": "2015-01-01T08:00:00Z",
         "status": "AVAILABLE"
      },
            {
         "dbname": "servdbd06",
         "dbsid": "SUP01",
         "dbport": 1621,
         "lastrefreshed": "2015-02-15T08:00:00Z",
         "status": "AVAILABLE"
      }
   ]
}

我也试过 jsonReader : {root: "dbdata"} 作为 jqgrid 中的选项。

浏览器调试显示这个-

我注意到服务发送的响应 header 中的 content-typetext/html 如下所示-

content-type 应该是 application/json 吗?那是问题所在吗?如果是这样,我如何 change/configure ORDS 设置 content-type?我正在使用 APEX UI 创建 ReST API 并测试了 API 通过 APEX 测试和 SoapUI 工作。我已经在这里和其他地方查看过有关此问题的信息,但找不到任何相关信息,因此将不胜感激。

注意:如果我使用 datatype:'jsonstring' 那么错误就会消失,但是我不确定如何将响应转换回字符串。如果我使用 $.getJSON() 获取 JSON 数据,我会得到正确的回复(请参见下面的屏幕截图和代码)。但我只是不确定如何在 JQGrid 中使用它。

$.getJSON('http://nsrmss01:9002/ords/oracle_retail_rest/comm/js', function(data) {
                console.log(data);
         });

404 Resource not found错误的原因可能是参数,将发送到服务器。您应该添加 jqGrid 选项 prmNames 以禁止发送 _searchnd 和其他:

prmNames: { nd: null, search: null, sort: null, order: null, rows: null, page: null }

那么您应该修复 colModel 中使用的 name 属性的值。 JavaScript 区分大小写,您必须使用 name: 'dbname' 而不是 name: 'DBNAME'

最后,我建议您使用 free jqGrid instead of commercial Guriddo jqGrid JS, which you currently used. Free jqGrid can be used under MIT or GPL v2 license completely free of charge. You need just change styleUI : 'Bootstrap' parameter to guiStyle: "bootstrap". See the article 了解更多详情。其他优化可以在您的代码运行后完成。