使用在自定义代码中捕获的连接信息
本部分介绍通过集成示例自定义代码中的 captureExternalConnection 实用程序捕获的端点信息的用法。
对于使用 captureExternalConnections 实用程序捕获的连接信息,可在集成示例自定义代码中使用 CustomIntegrationHelper 类进行访问。
以下代码片段呈现如何使用 CustomIntegrationHelper 类来获取连接信息:
public String getPartNumber() throws Exception {
URI apiUrl = customIntegrationHelper.getNamedEndpointURI("get_material_number");
Map<String, String> map = customIntegrationHelper.getSecretsMap();
String bearerToken = map.get("bearer_token");
SSLContext sslContext = customIntegrationHelper.getInitializedSSLContext();
String uniqueNo = performGetRequest(apiUrl, sslContext, bearerToken);
if (log.isDebugEnabled()) {
log.debug("API URL for fetching part number: " + apiUrl);
log.debug("Unique number returned from API Client :" + uniqueNo);
}
return uniqueNo;
}
检查用于捕获信息的 JSON 以及 customization/integrations/main/src/com/acme/ext/APIClient.java 中的自定义代码,以了解如何使用 CustomIntegrationHelper 来访问连接信息。请知悉,对于下表中使用客户端和服务器证书链生成的基本 URL、持有者令牌和 SSL 上下文,它们是使用 CustomIntegrationHelper 的对象实例在自定义代码中检索得到的。
通过 captureExternalConnections 实用程序提交的连接信息
通过 CCD 实用程序提交的自定义代码
"material_api": {
"baseurl": "replace with your base-url",
"url_fragments": {
"get_material_number": "/api/material",
"get_material_data_stream": "/api/materialData/stream"
},
"secrets": {
"client_cert": "replace with path to clientcertchain",
"bearer_token": "Bearer replace with your bearer token"
},
"server_cert": "replace with path to clientcertchain"
}
CustomIntegrationHelper customIntegrationHelper
= new CustomIntegrationHelper("material_api");
public String getPartNumber() throws Exception {
URL apiUr1 = customIntegrationHelper.getNamedEndpointURL("get_material_number");
Map<String, String> map = customIntegrationHelper.getSecretsMap();
String bearerToken = map.get("bearer_token");
SSLContext sslContext = customIntegrationHelper.getInitializedSSLContext();
.
.
.
}
* 
bearer_token 不是保留关键字,因此示例实施中未对持有者令牌身份验证进行特定处理。本质上,它可能是自定义代码在构建相关外部端点的请求时,可以标识并利用的任何其他字符串。
这对您有帮助吗?