Skip to content

Commit 2417973

Browse files
Release 2.2.0 (#6)
# Release 2.2.0 ## New features - Basic authentication setup - New function 'sendRequest' - Check if persistent data to load provides all relevant parameters. Otherwise add default values ## Improvements - 'sendInternalRequest' returns now the HTTP response - FlowConfig handling - Minor docu improvements ## Bugfix - Wrong instance handling within FlowConfig - FlowConfig priority was not instance specific - Legacy bindings of ValueDisplay elements and FileUpload feature within UI did not work if deployed with VS Code AppSpace SDK - UI differs if deployed via Appstudio or VS Code AppSpace SDK - Fullscreen icon of iFrame was visible
1 parent c869946 commit 2417973

16 files changed

Lines changed: 1048 additions & 386 deletions

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## Release 2.2.0
5+
6+
### New features
7+
- Basic authentication setup
8+
- New function 'sendRequest'
9+
- Check if persistent data to load provides all relevant parameters. Otherwise add default values
10+
11+
### Improvements
12+
- 'sendInternalRequest' returns now the HTTP response
13+
- FlowConfig handling
14+
- Minor docu improvements
15+
16+
### Bugfix
17+
- Wrong instance handling within FlowConfig
18+
- FlowConfig priority was not instance specific
19+
- Legacy bindings of ValueDisplay elements and FileUpload feature within UI did not work if deployed with VS Code AppSpace SDK
20+
- UI differs if deployed via Appstudio or VS Code AppSpace SDK
21+
- Fullscreen icon of iFrame was visible
22+
423
## Release 2.1.0
524

625
### New features

CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@
104104

105105
.myCustomButton_CSK_Module_MultiHTTPClient {
106106
border-radius: 30px;
107-
padding-right: 0px;
107+
padding: 11px;
108108
}

CSK_Module_MultiHTTPClient/pages/pages/CSK_Module_MultiHTTPClient/CSK_Module_MultiHTTPClient.html

Lines changed: 168 additions & 53 deletions
Large diffs are not rendered by default.

CSK_Module_MultiHTTPClient/pages/src/converter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ export function convertToList(value) {
55
export function changeStyle(theme) {
66
const style: HTMLStyleElement = document.createElement('style');
77
style.id ='blub'
8+
9+
const toggleSW = document.querySelectorAll("davinci-toggle-switch")
10+
toggleSW.forEach((userItem) => {
11+
const shadowToggle = userItem.shadowRoot
12+
const finalToggleSW = shadowToggle?.querySelector('div')
13+
finalToggleSW?.classList.add('hasIcon')
14+
});
15+
816
if (theme == 'CSK_Style'){
917
var headerToolbar = `.sopasjs-ui-header-toolbar-wrapper { background-color: #FFFFFF; }`
1018
var uiHeader = `.sopasjs-ui-header>.app-logo { margin-right:0px; }`

CSK_Module_MultiHTTPClient/pages/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ document.addEventListener('sopasjs-ready', () => {
1212
page_Setup.remove();
1313

1414
setTimeout(() => {
15+
const element = document.querySelector("div.sjs-wrapper > div > div.sjs-fullscreen-toggle")
16+
if(element) {
17+
element.parentElement.removeChild(element)
18+
}
1519
document.title = 'CSK_Module_MultiHTTPClient'
1620
}, 500);
1721
})

CSK_Module_MultiHTTPClient/project.mf.xml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ INFO: Other modules can check via "Script.isServedAsEvent" if event of sepecific
275275
<desc>Notify if module can be used on device.</desc>
276276
<param desc="Status" multiplicity="1" name="status" type="bool"/>
277277
</event>
278+
<event name="OnNewStatusBasicAuthentication">
279+
<desc>Notify status if HTTP basic authentication should be used.</desc>
280+
<param desc="Status" multiplicity="1" name="status" type="bool"/>
281+
</event>
282+
<event name="OnNewStatusBasicAuthenticationUser">
283+
<desc>Notify user for basic authentication.</desc>
284+
<param desc="Username" multiplicity="1" name="user" type="string"/>
285+
</event>
278286
<function name="setParameterName">
279287
<desc>Function to set the name of the parameters if saved/loaded via the CSK_PersistentData module.</desc>
280288
<param desc="Name of the parameter" multiplicity="1" name="name" type="string"/>
@@ -500,6 +508,31 @@ IMPORTANT: As instances start their own threads, the module needs to be restarte
500508
<function name="resetModule">
501509
<desc>Function to reset main configuration of module.</desc>
502510
</function>
511+
<function name="setBasicAuthentication">
512+
<desc>Function to set status to use HTTP basic authentication.</desc>
513+
<param desc="Status" multiplicity="1" name="status" type="bool"/>
514+
</function>
515+
<function name="setBasicAuthenticationUser">
516+
<desc>Function to set user for HTTP basic authentication.</desc>
517+
<param desc="User" multiplicity="1" name="user" type="string"/>
518+
</function>
519+
<function name="setBasicAuthenticationPassword">
520+
<desc>Function to set password for user of HTTP basic authentication.</desc>
521+
<param desc="Password" multiplicity="1" name="password" type="string"/>
522+
</function>
523+
<function name="sendRequestNUM">
524+
<desc>Example of dynamically served function to send a request of a specific instance. +
525+
NUM will be replaced by the number of instance (e.g. "sendRequest1"). +
526+
INFO: Other modules can check via "Script.isServedAsFunction" if function of sepecific instance exists. +
527+
Needs then to be called via "Script.callFunction".</desc>
528+
<param desc="Mode of request." multiplicity="1" name="mode" ref="CSK_MultiHTTPClient.RequestMode" type="enum"/>
529+
<param desc="Endpoint" multiplicity="1" name="endpoint" type="string"/>
530+
<param desc="Port" multiplicity="1" name="port" type="int"/>
531+
<param desc="Optional list of headers (JSON)." multiplicity="?" name="header" type="string"/>
532+
<param desc="Body content (JSON)." multiplicity="?" name="body" type="string"/>
533+
<param desc="Type of content." multiplicity="?" name="contentType" type="string"/>
534+
<return desc="Response (JSON)" multiplicity="1" name="response" type="string"/>
535+
</function>
503536
</serves>
504537
</crown>
505538
<crown name="MultiHTTPClient_FC">
@@ -530,7 +563,7 @@ IMPORTANT: As instances start their own threads, the module needs to be restarte
530563
</crown>
531564
</crown>
532565
<meta key="author">SICK AG</meta>
533-
<meta key="version">2.1.0</meta>
566+
<meta key="version">2.2.0</meta>
534567
<meta key="priority">low</meta>
535568
<meta key="copy-protected">false</meta>
536569
<meta key="read-protected">false</meta>

CSK_Module_MultiHTTPClient/scripts/CSK_Module_MultiHTTPClient.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ local multiHTTPClient_Instances = {} -- Handle all instances
5050
local multiHTTPClientController = require('Communication/MultiHTTPClient/MultiHTTPClient_Controller')
5151

5252
if _G.availableAPIs.default and _G.availableAPIs.specific then
53-
local setInstanceHandle = require('Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig')
53+
require('Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig')
5454
table.insert(multiHTTPClient_Instances, multiHTTPClient_Model.create(1)) -- Create at least 1 instance
5555
multiHTTPClientController.setMultiHTTPClient_Instances_Handle(multiHTTPClient_Instances) -- share handle of instances
56-
setInstanceHandle(multiHTTPClient_Instances)
5756
else
5857
_G.logger:warning("CSK_MultiHTTPClient: Relevant CROWN(s) not available on device. Module is not supported...")
5958
end

CSK_Module_MultiHTTPClient/scripts/CSK_MultiHTTPClient_Processing.lua

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ processingParams.clientActivated = scriptParams:get('clientActivated')
3232
processingParams.hostnameVerification = scriptParams:get('hostnameVerification')
3333
processingParams.peerVerification = scriptParams:get('peerVerification')
3434
processingParams.cookieStore = scriptParams:get('cookieStore')
35+
processingParams.basicAuthentication = scriptParams:get('basicAuthentication')
36+
processingParams.basicAuthenticationUser = scriptParams:get('basicAuthenticationUser')
37+
processingParams.basicAuthenticationPassword = scriptParams:get('basicAuthenticationPassword')
38+
3539
processingParams.clientAuthentication = scriptParams:get('clientAuthentication')
3640
processingParams.caBundleFileName = scriptParams:get('caBundleFileName')
3741
processingParams.clientCertificateType = scriptParams:get('clientCertificateType')
@@ -119,6 +123,11 @@ local function updateClient()
119123
clientObject = HTTPClient.create()
120124

121125
clientObject:setVerbose(processingParams.verboseMode)
126+
127+
if processingParams.basicAuthentication then
128+
clientObject:setAuthCredentials(processingParams.basicAuthenticationUser, processingParams.basicAuthenticationPassword)
129+
end
130+
122131
if processingParams.clientAuthentication then
123132
if File.exists(processingParams.caBundleFileName) then
124133
clientObject:setCABundle(processingParams.caBundleFileName)
@@ -179,12 +188,14 @@ end
179188

180189
--- Function to execute a request
181190
---@param tempRequestActive bool Status if it is just a temporarly configured request or a preconfigured one
182-
---@param showResponse bool Status if repsonse should be notified as event (e.g. to show it on UI)
183-
---@param eventName string Name of event to notify the response
184-
local function sendRequest(tempRequestActive, showResponse, eventName)
191+
---@param showResponse bool Status if response should be notified as event (e.g. to show it on UI)
192+
---@param eventName string? Optional name of event to notify the response
193+
---@return string response Response of HTTP request
194+
local function sendInternalRequest(tempRequestActive, showResponse, eventName)
185195

186196
local timerQueueSize = 0
187197
local eventQueueSize = 0
198+
local jsonResponse = {}
188199

189200
if tempRequestActive then
190201
updateInternalRequest(processingParams)
@@ -200,37 +211,50 @@ local function sendRequest(tempRequestActive, showResponse, eventName)
200211

201212
if timerQueueSize >= processingParams.queueSize-1 or eventQueueSize >= processingParams.queueSize-1 then
202213
_G.logger:warning(nameOfModule .. ": Internal request queue too high '(Timer:" .. tostring(timerQueueSize) .. '/Events:' .. tostring(eventQueueSize) .. ")'. Will skip new requests...")
214+
return ''
203215
else
204216
local tic = DateTime.getTimestamp()
217+
205218
local response = clientObject:execute(request)
206219
local procTime = DateTime.getTimestamp() - tic
207220

208221
local success = HTTPClient.Response.getSuccess(response)
222+
jsonResponse.Success = tostring(success)
209223
_G.logger:fine(nameOfModule .. ": Response success = " .. tostring(success))
210224

211225
-- Check response
212226
local responseMessage = 'After ' .. tostring(procTime) .. 'ms --> ' .. 'Request success = ' .. tostring(success) .. '\n'
213-
responseMessage = responseMessage .. 'Code: ' .. HTTPClient.Response.getStatusCode(response) .. '\n'
227+
local statusCode = HTTPClient.Response.getStatusCode(response)
228+
responseMessage = responseMessage .. 'Code: ' .. statusCode .. '\n'
229+
jsonResponse.StatusCode = statusCode
214230

215231
if success then
216232
-- Check if extended information of the response should be shown
217233
if processingParams.extendedResponse then
218-
responseMessage = responseMessage .. 'Request content type: ' .. HTTPClient.Response.getContentType(response) .. '\n'
234+
local contentType = HTTPClient.Response.getContentType(response)
235+
responseMessage = responseMessage .. 'Request content type: ' .. contentType .. '\n'
236+
jsonResponse.ContentType = contentType
219237

220238
local tempKeys = HTTPClient.Response.getHeaderKeys(response)
239+
jsonResponse.Headers = {}
221240
for _, headerKeys in pairs(tempKeys) do
241+
jsonResponse.Headers[headerKeys] = {}
222242

223243
local suc, tempValues = HTTPClient.Response.getHeaderValues(response, headerKeys)
224244
for _, headerValue in pairs(tempValues) do
225245
responseMessage = responseMessage .. 'Header-key: ' .. headerKeys .. ' = ' .. headerValue .. '\n'
246+
table.insert(jsonResponse.Headers[headerKeys], headerValue)
226247
end
227248
end
228249
end
229250

251+
jsonResponse.Response = HTTPClient.Response.getContent(response)
230252
responseMessage = responseMessage .. helperFuncs.jsonLine2Table(HTTPClient.Response.getContent(response)) .. '\n'
231253
else
232254
local error = HTTPClient.Response.getError(response)
233255
local errorDetail = HTTPClient.Response.getErrorDetail(response)
256+
jsonResponse.Error = error
257+
jsonResponse.ErrorDetail = errorDetail
234258
responseMessage = responseMessage .. 'Error = ' .. error .. '\n' .. 'Error details = ' .. errorDetail .. '\n'
235259
end
236260
if eventName then
@@ -244,8 +268,27 @@ local function sendRequest(tempRequestActive, showResponse, eventName)
244268
Script.notifyEvent("MultiHTTPClient_OnNewValueToForward" .. multiHTTPClientInstanceNumberString, "MultiHTTPClient_OnNewResponseMessage", responseMessage)
245269
end
246270
end
271+
return json.encode(jsonResponse)
272+
end
273+
end
274+
275+
local function sendRequest(mode, endpoint, port, header, body, contentType)
276+
processingParams.extendedResponse = true
277+
processingParams.requestMode = mode
278+
processingParams.requestEndpoint = endpoint
279+
processingParams.requestPort = port
280+
281+
if body then
282+
processingParams.requestContent = body
283+
else
284+
processingParams.requestContent = ''
247285
end
286+
287+
local response = sendInternalRequest(true, false)
288+
289+
return response
248290
end
291+
Script.serveFunction('CSK_MultiHTTPClient.sendRequest' .. multiHTTPClientInstanceNumberString, sendRequest, 'string, string, int, string:?, string:?, string:?', 'string')
249292

250293
--- Function to set timer if request should be executed periodically
251294
---@param requestName string Name of preconfigured request
@@ -260,9 +303,9 @@ local function setTimer(requestName)
260303
if processingParams.clientActivated then
261304
setSpecificRequest(requestName)
262305
if selectedRequest == requestName then
263-
sendRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
306+
sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
264307
else
265-
sendRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
308+
sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
266309
end
267310
end
268311
end
@@ -306,9 +349,9 @@ local function setRegisteredEvent(requestName)
306349
end
307350
setSpecificRequest(requestName)
308351
if selectedRequest == requestName then
309-
sendRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
352+
sendInternalRequest(false, true, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
310353
else
311-
sendRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
354+
sendInternalRequest(false, false, "MultiHTTPClient_OnNewReponse" .. multiHTTPClientInstanceNumberString .. '_' .. processingParams.requests[requestName].requestName)
312355
end
313356
end
314357
end
@@ -501,7 +544,7 @@ local function handleOnNewProcessingParameter(multiHTTPClientNo, parameter, valu
501544

502545
elseif parameter == 'sendRequest' then
503546
if processingParams.clientActivated then
504-
sendRequest(true, true)
547+
sendInternalRequest(true, true)
505548
end
506549

507550
elseif parameter == 'headerUpdate' then

CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_FlowConfig.lua

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,10 @@
55

66
require('Communication.MultiHTTPClient.FlowConfig.MultiHTTPClient_SendRequest')
77

8-
-- Reference to the multiHTTPClient_Instances handle
9-
local multiHTTPClient_Instances
10-
118
--- Function to react if FlowConfig was updated
129
local function handleOnClearOldFlow()
1310
if _G.availableAPIs.default and _G.availableAPIs.specific then
14-
for i = 1, # multiHTTPClient_Instances do
15-
if multiHTTPClient_Instances[i].parameters.flowConfigPriority then
16-
CSK_MultiHTTPClient.clearFlowConfigRelevantConfiguration()
17-
break
18-
end
19-
end
11+
CSK_MultiHTTPClient.clearFlowConfigRelevantConfiguration()
2012
end
2113
end
2214
Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow)
23-
24-
--- Function to get access to the multiHTTPClient_Instances
25-
---@param handle handle Handle of multiHTTPClient_Instances object
26-
local function setMultiHTTPClient_Instances_Handle(handle)
27-
multiHTTPClient_Instances = handle
28-
end
29-
30-
return setMultiHTTPClient_Instances_Handle

CSK_Module_MultiHTTPClient/scripts/Communication/MultiHTTPClient/FlowConfig/MultiHTTPClient_SendRequest.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ local function create(instance, requestName, mode, protocol, endpoint, port)
4343
local fullInstanceName = tostring(instance) .. tostring(requestName)
4444

4545
-- Check if same instance is already configured
46-
if instance < 1 or nil ~= instanceTable[fullInstanceName] then
46+
if instanceTable[fullInstanceName] ~= nil then
4747
_G.logger:warning(nameOfModule .. ': Instance invalid or already in use, please choose another one')
4848
return nil
4949
else
5050
-- Otherwise create handle and store the restriced resource
5151
local handle = Container.create()
52-
instanceTable[instance] = instance
52+
instanceTable[fullInstanceName] = fullInstanceName
5353
Container.add(handle, 'Instance', instance)
5454
Container.add(handle, 'RequestName', requestName)
5555
Container.add(handle, 'Mode', mode)

0 commit comments

Comments
 (0)