我正在为TFS构建一个集线器扩展,它将扩展到HP Fortify REST api并返回一个项目列表。 TFS服务器和Fortify服务器都在同一个域中进行本地运行。
Fortify有一种独特的配置,其中IIS 8.5是Tomcat 8的前端。
我要做的第一件事就是从TFS扩展中调用,以便从Fortify获取令牌。完全披露,我是一个javascript新手,所以这可能不是很棒:
string connectionString = "Data Source=myDataSource;Initial Catalog=MyInitialCatalog;Persist Security Info=True;User ID=myID;Password=myPassword";
string sql = "SELECT * FROM JournalItems";
sDs = new DataSet();
sDs.Tables.Add("JournalItems");
using(var connection = new SqlConnection(connectionString))
{
using(var sCommand = new SqlCommand(sql, connection))
{
using(var sAdapter = new SqlDataAdapter(sCommand))
{
sAdapter.Fill(sDs, "JournalItems");
}
}
}
journalItemsDataGridView.DataSource = sDs.Tables["JournalItems"];
journalItemsDataGridView.ReadOnly = true;
saveData.Enabled = false;
journalItemsDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
当上述脚本执行时,我收到此错误:
$.ajax({
type: "POST",
url: "https://fortifyserver/ssc/api/v1/auth/obtain_token",
data: JSON.stringify({ name: "Teambuild" }),
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
xhr.setRequestHeader("Content-type", "text/plain");
xhr.setRequestHeader("Content-Encoding", "gzip");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Authorization", "Basic ********************");
},
dataType: "json",
success: function (data) {
alert("Data Loaded: " + data);
}
});
我很确定这与CORS有关,所以我的问题是应该调整哪一块Fortify配置? IIS或Tomcat还是两者兼而有之?
答案 0 :(得分:0)
我想出了另一种方法。我根据Sriram Balasubramaniam的这一系列blog posts的指导,为HP Fortify Rest API创建了一个自定义服务端点。
我还使用了jsonpath online evaluator帮助找出自定义扩展中每个数据源的正确结果语法。以下是端点数据源的示例:
"dataSources": [
{
"name": "GetAllProjects",
"endpointUrl": "$(endpoint.url)api/v1/projects",
"resultSelector": "jsonpath:$.data.[*]"
}
]
这是一个使用端点的ajax调用示例:
var queryUri = baseUri + '/_apis/distributedtask/serviceendpointproxy?endpointId=' + $connectionDropdown.val() + '&api-version=3.0-preview.1';
var projectQueryContent = '{"dataSourceDetails": {"dataSourceName":"GetAllProjects"}}';
$.ajax({
type: "POST",
url: queryUri,
data: projectQueryContent,
contentType: 'application/json',
dataType: 'json',
headers: { 'Authorization': basicAuthHeader }
})
.done(function (data) {
$(data.result).each(function (i, e) {
var el = JSON.parse(e);
//console.log('Project Name: ' + el.name);
$projectDropdown.append($('<option value="' + el.id + '">' + el.name + '</option>'));
});
});
现在我有一个带有集线器和自定义端点的VSTS / TFS扩展。