Skip to content

Commit 77ee118

Browse files
committed
Update the configuration for the agent docker containers to use json v2 and created a cutting tool test for v2. Added Date to the response header per 1.1
1 parent b46ab74 commit 77ee118

5 files changed

Lines changed: 111 additions & 5 deletions

File tree

‎demo/compose/agent/agent.cfg‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
Devices = Devices.xml
22
SchemaVersion = 2.7
33
WorkerThreads = 3
4-
MonitorConfigFiles = yes
54
Port = 5000
6-
JsonVersion = 1
75

86
MinCompressFileSize = 10k
97

‎demo/compose/agent/agentmqtt.cfg‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
Devices = Devices.xml
22
SchemaVersion = 2.7
33
WorkerThreads = 3
4-
MonitorConfigFiles = yes
54
Port = 5000
6-
JsonVersion = 1
5+
JsonVersion = 2
76

87
MinCompressFileSize = 10k
98

‎demo/styles/styles.xsl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
4-
xmlns:m="urn:mtconnect.org:MTConnectDevices:2.0" xmlns:s="urn:mtconnect.org:MTConnectStreams:2.0" xmlns:e="urn:mtconnect.org:MTConnectError:2.0" xmlns:js="urn:custom-javascript"
4+
xmlns:m="urn:mtconnect.org:MTConnectDevices:2.7" xmlns:s="urn:mtconnect.org:MTConnectStreams:2.7" xmlns:e="urn:mtconnect.org:MTConnectError:2.7" xmlns:js="urn:custom-javascript"
55
exclude-result-prefixes="msxsl js" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
66

77
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

‎src/mtconnect/sink/rest_sink/session_impl.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,15 @@ namespace mtconnect::sink::rest_sink {
302302
m_complete = complete;
303303
m_mimeType = mimeType;
304304
m_streaming = true;
305+
306+
auto now = std::chrono::floor<std::chrono::seconds>(std::chrono::system_clock::now());
307+
std::string date = std::format("{:%a, %d %b %Y %T} GMT", now);
305308

306309
auto res = make_shared<http::response<empty_body>>(status::ok, 11);
307310
m_response = res;
308311
res->chunked(true);
309312
res->set(field::server, "MTConnectAgent");
313+
res->set(field::date, date);
310314
res->set(field::connection, "close");
311315
res->set(field::content_type, "multipart/mixed;boundary=" + m_boundary);
312316
res->set(field::expires, "-1");
@@ -361,6 +365,10 @@ namespace mtconnect::sink::rest_sink {
361365
void SessionImpl<Derived>::addHeaders(const Response &response, Message &res)
362366
{
363367
res->set(http::field::server, "MTConnectAgent");
368+
auto now = std::chrono::floor<std::chrono::seconds>(std::chrono::system_clock::now());
369+
std::string date = std::format("{:%a, %d %b %Y %T} GMT", now);
370+
res->set(http::field::date, date);
371+
364372
if (response.m_close || m_close)
365373
res->set(http::field::connection, "close");
366374
if (response.m_expires == 0s)

‎test_package/cutting_tool_test.cpp‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,107 @@ TEST_F(CuttingToolTest, test_extended_cutting_item)
635635
sdoc);
636636
}
637637

638+
TEST_F(CuttingToolTest, test_extended_cutting_tool_with_json_v2)
639+
{
640+
const auto doc =
641+
R"DOC(<CuttingTool assetId="123456.10" serialNumber="10" toolId="123456">
642+
<CuttingToolLifeCycle>
643+
<CutterStatus>
644+
<Status>AVAILABLE</Status>
645+
</CutterStatus>
646+
<ProgramToolNumber>10</ProgramToolNumber>
647+
<Location negativeOverlap="0" positiveOverlap="0" type="POT">13</Location>
648+
<CuttingItems count="12">
649+
<CuttingItem indices="1">
650+
<ItemLife countDirection="UP" initial="0" limit="0" type="PART_COUNT">0</ItemLife>
651+
<ItemLife countDirection="UP" initial="0" limit="0" type="MINUTES">0</ItemLife>
652+
<ItemLife countDirection="UP" initial="0" limit="0" type="WEAR">0</ItemLife>
653+
<x:ItemCutterStatus xmlns:x="okuma.com:OkumaToolAssets">
654+
<Status>AVAILABLE</Status>
655+
</x:ItemCutterStatus>
656+
<x:ItemProgramToolGroup xmlns:x="okuma.com:OkumaToolAssets">0</x:ItemProgramToolGroup>
657+
</CuttingItem>
658+
</CuttingItems>
659+
</CuttingToolLifeCycle>
660+
</CuttingTool>
661+
)DOC";
662+
663+
ErrorList errors;
664+
entity::XmlParser parser;
665+
666+
auto entity = parser.parse(Asset::getRoot(), doc, errors);
667+
ASSERT_EQ(0, errors.size());
668+
669+
auto asset = dynamic_cast<Asset *>(entity.get());
670+
ASSERT_NE(nullptr, asset);
671+
672+
entity::JsonEntityPrinter jprinter(2, true);
673+
auto jdoc = jprinter.print(entity);
674+
675+
EXPECT_EQ(R"({
676+
"CuttingTool": {
677+
"CuttingToolLifeCycle": {
678+
"CutterStatus": {
679+
"Status": [
680+
{
681+
"value": "AVAILABLE"
682+
}
683+
]
684+
},
685+
"CuttingItems": {
686+
"CuttingItem": [
687+
{
688+
"ItemLife": [
689+
{
690+
"value": 0.0,
691+
"countDirection": "UP",
692+
"initial": 0.0,
693+
"limit": 0.0,
694+
"type": "PART_COUNT"
695+
},
696+
{
697+
"value": 0.0,
698+
"countDirection": "UP",
699+
"initial": 0.0,
700+
"limit": 0.0,
701+
"type": "MINUTES"
702+
},
703+
{
704+
"value": 0.0,
705+
"countDirection": "UP",
706+
"initial": 0.0,
707+
"limit": 0.0,
708+
"type": "WEAR"
709+
}
710+
],
711+
"indices": "1",
712+
"x:ItemCutterStatus": {
713+
"Status": "AVAILABLE",
714+
"xmlns:x": "okuma.com:OkumaToolAssets"
715+
},
716+
"x:ItemProgramToolGroup": {
717+
"value": "0",
718+
"xmlns:x": "okuma.com:OkumaToolAssets"
719+
}
720+
}
721+
],
722+
"count": 12
723+
},
724+
"Location": {
725+
"value": "13",
726+
"negativeOverlap": 0,
727+
"positiveOverlap": 0,
728+
"type": "POT"
729+
},
730+
"ProgramToolNumber": "10"
731+
},
732+
"assetId": "123456.10",
733+
"serialNumber": "10",
734+
"toolId": "123456"
735+
}
736+
})", jdoc);
737+
}
738+
638739
TEST_F(CuttingToolTest, test_xmlns_with_top_element_alias)
639740
{
640741
const auto doc =

0 commit comments

Comments
 (0)