Skip to content

Commit e2cfdd5

Browse files
committed
v0.0.3
1 parent ad0c284 commit e2cfdd5

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

cls/MTConnect/ExampleProduction/BO/GenericRestOperation.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Class MTConnect.ExampleProduction.BO.GenericRestOperation Extends EnsLib.REST.Operation
22
{
33

4-
Parameter ADAPTER = "MTConnect.OutboundAdapter.GenericRestOutboundAdapter";
4+
Parameter ADAPTER = "MTConnect.ExampleProduction.OutboundAdapter.GenericRestOutboundAdapter";
55

6-
Property Adapter As MTConnect.OutboundAdapter.GenericRestOutboundAdapter;
6+
Property Adapter As MTConnect.ExampleProduction.OutboundAdapter.GenericRestOutboundAdapter;
77

88
Parameter INVOCATION = "Queue";
99

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Class MTConnect.ExampleProduction.OutboundAdapter.GenericRestOutboundAdapter Extends EnsLib.HTTP.OutboundAdapter
2+
{
3+
4+
Parameter INVOCATION = "Queue";
5+
6+
/// defines a Content-Type header, (e.g. application/json)
7+
Property contentType As %String(MAXLEN = 50) [ InitialExpression = "application/json" ];
8+
9+
/// defines a Content-Type Charset header (e.g. utf-8)
10+
Property contentCharset As %String(MAXLEN = 30) [ InitialExpression = "utf-8" ];
11+
12+
/// defines a Accept header (e.g." application/json , text/html")
13+
Property accept As %String(MAXLEN = 100);
14+
15+
/// This key will going to be attached to Authorization Header or url path <br/>
16+
/// <ul>
17+
/// <li>When username exist in credentials, it will be connected to URL</li>
18+
/// <li>When username is not set in credentials, it will be attached as Authorization Headers</li>
19+
/// </ul>
20+
Property apiCredentials As %String(MAXLEN = 100);
21+
22+
/// this key will going to be attached to Authorization Header or url path, depending on what @ApiKeyName
23+
Property apiKey As %String(MAXLEN = 100);
24+
25+
/// defines ApiKey name to be used in URL, if it is empty, then Authorization Header is used
26+
Property apiKeyName As %String;
27+
28+
Property method As %String;
29+
30+
// Parameter SETTINGS = "contentType:GenericRest,contentCharset:GenericRest,apiCredentials:GenericRest:credentialsSelector,accept:GenericRest";
31+
32+
Parameter SETTINGS = "method:GenericRest,contentType:GenericRest,contentCharset:GenericRest,apiCredentials:GenericRest:credentialsSelector,apiKey:GenericRest,apiKeyName:GenericRest,accept:GenericRest,RegistryID:Basic:selector?context={Ens.ServiceRegistry.External.ContextSearch/Services?Protocols_1=REST&Protocols_2=HTTP},HTTPServer:Basic,HTTPPort:Basic,SSLConfig:Connection:sslConfigSelector,SSLCheckServerIdentity:Connection,LocalInterface:Connection:selector?context={Ens.ContextSearch/TCPLocalInterfaces},ProxyServer:Connection,ProxyPort:Connection,ProxyHTTPS:Connection,ProxyHttpTunnel:Connection,URL:Basic,Credentials:Basic:credentialsSelector,UseCookies,ConnectTimeout:Connection,ResponseTimeout:Connection,WriteTimeout:Connection,ProvideMetricsForSAM:Alerting";
33+
34+
/// if pURL is empty, then URL from the Production Settings is being used.
35+
Method SendRequest(pUrl As %String, pBody As %String, Output pHttpResponse As %Net.HttpResponse) As %Status
36+
{
37+
Set tSC = $$$OK
38+
If (pUrl ="") {
39+
Set tUrl = ..URL
40+
} Else {
41+
Set tUrl = pUrl
42+
}
43+
44+
Set tOp=..method
45+
If tOp="" {
46+
Set tOp="GET"
47+
}
48+
49+
Set tApiKeyName=..apiKeyName
50+
Set tApiKey=..apiKey
51+
52+
If (..apiCredentials'="") {
53+
Set tCredentials=##class(Ens.Config.Credentials).%OpenId(..apiCredentials)
54+
Set tApiKeyName=tCredentials.Username
55+
Set tApiKey=tCredentials.Password
56+
}
57+
Set httpRequest = ##class(%Net.HttpRequest).%New()
58+
Set httpRequest.ContentType=..contentType
59+
Set httpRequest.ContentCharset=..contentCharset
60+
If (..apiCredentials'="" && tApiKey'="") {
61+
If (tApiKeyName="") {
62+
If (tApiKey'="") {
63+
Set httpRequest.Authorization=tApiKey
64+
}
65+
} Else {
66+
Set tApiKeyAddon=tApiKeyName_"="_tApiKey
67+
Set tUrl=tUrl_$S($L(tUrl,"?")>1:"&",1:"?")_tApiKeyAddon
68+
}
69+
}
70+
$$$TRACE("tUrl:"_tUrl)
71+
$$$TRACE("tOp:"_tOp)
72+
73+
Set tSC = ..SendFormDataURL(tUrl,.pHttpResponse, tOp, httpRequest,"",pBody)
74+
75+
Return tSC
76+
}
77+
78+
/// Used for the cases when you do GET request without any further requirements
79+
Method GetRequest(pUrl As %String, Output pHttpResponse As %Net.HttpResponse) As %Status
80+
{
81+
Return ..SendRequest("GET", pUrl, , .pHttpResponse)
82+
}
83+
84+
}
85+

0 commit comments

Comments
 (0)