Workplace Widget 5.10.8

This commit is contained in:
chris
2026-11-01 10:09:34 +00:00
parent 513550f58d
commit 180127e2ae
21 changed files with 397 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "workbench-hmi",
"private": true,
"version": "5.10.6",
"version": "5.10.8",
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0 --port 5173",

View File

@@ -6,6 +6,8 @@ const screen=document.getElementById('display');
const notice=document.getElementById('state');
const BRIDGE_JAR='/app/backend/hmi/cheerpj/workplace-resize-bridge-v2.jar';
const WORKPLACE_MANIFEST='/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp';
// Writable, browser-local CheerpJ directory; never a GlassFish/server filesystem path.
const WORKPLACE_TMP_DIR='/files/itac-workplace/tmp';
let busy=false;
const trusted=(raw,base=location.href)=>{
const u=new URL(raw,base);
@@ -36,6 +38,18 @@ function readManifest(xml,jnlpUrl){
if(platformGroups.length)warnings.push('Plattformspezifische/native JNLP-Ressourcen werden nicht geladen.');
if(root.getElementsByTagName('nativelib').length)warnings.push('Native RXTX-/JNI-Treiber laufen nicht im Browser.');
if(jvm?.getAttribute('java-vm-args'))warnings.push('JNLP-JVM-Optionen werden nicht vollständig übernommen.');
const properties=groups.filter(g=>!g.hasAttribute('os')&&!g.hasAttribute('arch'))
.flatMap(g=>Array.from(g.getElementsByTagName('property')));
const clusterValues=properties.filter(p=>p.getAttribute('name')==='itac.artes.clusternodes')
.map(p=>String(p.getAttribute('value')||''));
if(clusterValues.length>1)throw Error('Mehrfache MES-Clusterkonfiguration ist nicht zulässig.');
let clusterNodes='';
if(clusterValues.length){
const target=new URL(clusterValues[0]);
if(!['http:','https:'].includes(target.protocol)||target.username||target.password||target.search||target.hash||target.pathname!=='/mes')
throw Error('Ungültige MES-Clusteradresse in der JNLP.');
clusterNodes=target.origin+'/mes';
}
const base=root.getAttribute('codebase')?trusted(root.getAttribute('codebase'),jnlpUrl):new URL('.',jnlpUrl);
const paths=jars.map(j=>{
const href=j.getAttribute('href');if(!href)throw Error('JAR ohne href.');
@@ -49,12 +63,35 @@ function readManifest(xml,jnlpUrl){
const args=Array.from(app.childNodes).filter(e=>e.nodeType===1&&e.localName==='argument').map(e=>e.textContent||'');
if(args.length>32||args.some(a=>a.length>2048))throw Error('Zu viele/lange JNLP-Argumente.');
if(!main&&paths.length>1)throw Error('JNLP mit mehreren JARs benötigt main-class für einen sicheren Klassenpfad.');
return {main,paths,args,required,warnings};
return {main,paths,args,required,warnings,clusterNodes};
}
/** Load a separate, unsigned iTAC-independent helper in the same CheerpJ runtime.
* Only the immutable, locally packaged Bridge JAR is loaded; no vendor JAR is modified.
* When the JVM has not created MesSuiteFrame yet, retry for a bounded startup window.
*/
async function ensureWorkplaceTempDirectory() {
// /app is read-only and /str is read-only to Java. CheerpJ's /files mount
// supports Java writes (IndexedDB, per-browser origin). Create via Java NIO,
// not JavaScript, because JS cannot write directly into /files.
if (typeof window.cheerpjRunLibrary !== 'function')
throw Error('CheerpJ Library Mode für die Temp-Verzeichnisanlage nicht verfügbar.');
const lib=await window.cheerpjRunLibrary('');
const Paths=await lib.java.nio.file.Paths;
const Files=await lib.java.nio.file.Files;
const path=await Paths.get(WORKPLACE_TMP_DIR);
try {
await Files.createDirectories(path, []);
if (await Files.isDirectory(path, []) !== true)
throw Error('Pfad ist kein Verzeichnis.');
// Checking the directory alone is not enough: verify actual write access.
const probe=await Files.createTempFile(path,'hmi-tmp-check-','.tmp',[]);
await Files.deleteIfExists(probe);
} catch(error) {
throw Error('CheerpJ-Temp-Verzeichnis '+WORKPLACE_TMP_DIR+' nicht verfügbar: '+
(error instanceof Error ? error.message : String(error)));
}
}
async function attachWorkplaceResize(container, classPath, mode) {
if (typeof window.cheerpjRunLibrary !== 'function')
throw Error('CheerpJ Library Mode für die ResizeBridge nicht verfügbar.');
@@ -121,7 +158,16 @@ async function start(e,data){
if(typeof window.cheerpjInit!=='function'){
await new Promise((resolve,reject)=>{let count=0;const timer=setInterval(()=>{if(typeof window.cheerpjInit==='function'){clearInterval(timer);resolve();}else if(++count>150){clearInterval(timer);reject(Error('CheerpJ CDN nicht erreichbar oder durch CSP blockiert.'));}},100);});
}
await window.cheerpjInit({version,status:'none'});
// JNLP URL query parameters are not Java system properties.
// CheerpJ 4.3 supplies -D equivalents through javaProperties.
const javaProperties=isWorkplace && manifest.clusterNodes
? ['itac.artes.clusternodes='+manifest.clusterNodes] : [];
if(isWorkplace)javaProperties.push('java.io.tmpdir='+WORKPLACE_TMP_DIR);
await window.cheerpjInit({version,status:'none',javaProperties});
if(isWorkplace){
status(id,'loading','Virtuelles Workplace-Temp-Verzeichnis wird vorbereitet …');
await ensureWorkplaceTempDirectory();
}
if(isWorkplace && displayMode==='original'){
document.body.classList.add('cheerpj-original-mode');
window.cheerpjCreateDisplay(1280,1024,screen);

View File

@@ -14,7 +14,8 @@ class DOMParser {
const jars=[...html.matchAll(/<jar\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('jar',x[1]));
const natives=[...html.matchAll(/<nativelib\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('nativelib',x[1]));
const java=[...html.matchAll(/<java\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('java',x[1]));
return fixtureNode('resources',m[1],[...java,...jars,...natives]);
const properties=[...html.matchAll(/<property\b([^>]*?)\s*\/>/g)].map(x=>fixtureNode('property',x[1]));
return fixtureNode('resources',m[1],[...java,...jars,...natives,...properties]);
});
const args=[...xml.matchAll(/<argument>([^<]*)<\/argument>/g)].map(m=>fixtureNode('argument','',[],m[1]));
const appMatch=xml.match(/<application-desc\b([^>]*?)(?:\/>|>(?:[\s\S]*?)<\/application-desc>)/);
@@ -27,16 +28,40 @@ class DOMParser {
const source=fs.readFileSync(new URL('../public/cheerpj-runner.js',import.meta.url),'utf8');
let responseText='';
const origin='https://demo.example.org:8181';
async function launch(path,version=11,opts={}){
async function launch(path,version=11,opts={},testOptions={}){
const sent=[],called=[];
const context={URL,DOMParser,
location:{href:origin+'/backend/hmi/cheerpj-runner.html',origin,hostname:'demo.example.org'},
document:{body:{classList:{add:()=>{}}},getElementById:()=>({textContent:'',className:'',getBoundingClientRect:()=>({width:960,height:640})})},
window:{parent:{postMessage:m=>sent.push(m)},addEventListener:(type,fn)=>{if(type==='message')context._handler=fn},
cheerpjInit:async()=>called.push('init'),cheerpjCreateDisplay:(w,h)=>{assert.equal(w,-1);assert.equal(h,-1);called.push('display')},
cheerpjInit:async(opts)=>called.push(['init',opts]),cheerpjCreateDisplay:(w,h)=>{assert.equal(w,-1);assert.equal(h,-1);called.push('display')},
cheerpjRunMain:async (...args)=>{called.push(['runMain',...args]);return 0},
cheerpjRunJar:async (...args)=>{called.push(['runJar',...args]);return 0},
cheerpjRunLibrary:async cp=>{called.push(['library',cp]);return {com:{widgetworkbench:{cheerpj:{WorkplaceResizeBridge:{resize:async (w,h)=>{called.push(['resize',w,h]);return 1}}}}}}}},
cheerpjRunLibrary:async cp=>{
called.push(['library',cp]);
if(cp==='')return {java:{nio:{file:{
Paths:{get:async path=>{called.push(['tempPath',path]);return {value:path}}},
Files:{
createDirectories:async (path,attributes)=>{
called.push(['tempMkdir',path.value,attributes]);
if(testOptions.failTemp)throw Error('Speicherplatz erschöpft');
return path;
},
isDirectory:async (path,options)=>{
called.push(['tempIsDir',path.value,options]);
return !testOptions.notDirectory;
},
createTempFile:async (path,prefix,suffix,attributes)=>{
called.push(['tempProbe',path.value,prefix,suffix,attributes]);
if(testOptions.readOnly)throw Error('Schreiben nicht erlaubt');
return {value:path.value+'/hmi-tmp-check-1.tmp'};
},
deleteIfExists:async path=>{called.push(['tempProbeRemove',path.value]);return true;}
}
}}}};
return {com:{widgetworkbench:{cheerpj:{WorkplaceResizeBridge:{resize:async (w,h)=>{called.push(['resize',w,h]);return 1}}}}}};
},
},
parent:{postMessage:m=>sent.push(m)},
fetch:async u=>({ok:true,status:200,url:u,text:async()=>responseText}),
setInterval,clearInterval,Error,Promise,ResizeObserver:class { observe(){} disconnect(){} },
@@ -65,8 +90,24 @@ assert.equal(result.end?.state,'error');
responseText=fs.readFileSync(new URL('../../backend/src/main/resources/hmi/Workplace.jnlp',import.meta.url),'utf8')
.replace('codebase="https://partner.itacsoftware.com:8181/mes/webstart/clients"',
'codebase="/backend/api/hmi/v1/cheerpj/workplace/jars"');
// The server rewrites the JNLP to include a verified MES JVM property.
responseText=responseText.replace('<resources>',
'<resources><property name="itac.artes.clusternodes" value="https://demo.example.org:8181/mes"/>');
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true,displayMode:'fit'});
assert.equal(result.end?.state,'finished',JSON.stringify(result.end));
assert.deepEqual(Array.from(result.called.find(c=>Array.isArray(c)&&c[0]==='init')[1].javaProperties),
['itac.artes.clusternodes=https://demo.example.org:8181/mes',
'java.io.tmpdir=/files/itac-workplace/tmp']);
const initIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='init');
const mkdirIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='tempMkdir');
const runIndex=result.called.findIndex(c=>Array.isArray(c)&&c[0]==='runMain');
assert.ok(initIndex>=0&&mkdirIndex>initIndex&&runIndex>mkdirIndex,
'Java-Temp-Ordner muss vor dem Workplace-Start erzeugt werden.');
assert.equal(result.called[mkdirIndex][1],'/files/itac-workplace/tmp');
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempIsDir'&&c[1]==='/files/itac-workplace/tmp'));
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempProbe'&&c[1]==='/files/itac-workplace/tmp'));
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='tempProbeRemove'));
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='library'&&c[1].endsWith('workplace-resize-bridge-v2.jar')));
assert.ok(result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'&&c[2].endsWith('workplace-resize-bridge-v2.jar')));
const workplaceCall=result.called.find(c=>Array.isArray(c)&&c[0]==='runMain');
@@ -74,6 +115,19 @@ assert.equal(workplaceCall[1],'com.itac.mes.suite.presentation.MesSuiteFrameWebs
assert.equal(workplaceCall[3],'itac.appid=Workplace');
assert.equal(workplaceCall[2].split(':').length,130);
assert.match(result.sent.find(s=>s.state==='running')?.message||'',/RXTX/);
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{failTemp:true});
assert.equal(result.end?.state,'error');
assert.match(result.end.message,/Temp-Verzeichnis.*Speicherplatz erschöpft/);
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'),
'Workplace darf nicht ohne benutzbaren Temp-Ordner starten.');
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{notDirectory:true});
assert.equal(result.end?.state,'error');
assert.match(result.end.message,/kein Verzeichnis/);
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',11,{workplace:true},{readOnly:true});
assert.equal(result.end?.state,'error');
assert.match(result.end.message,/Schreiben nicht erlaubt/);
assert.ok(!result.called.some(c=>Array.isArray(c)&&c[0]==='runMain'));
result=await launch(origin+'/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp',8);
assert.equal(result.end?.state,'error');
assert.match(result.end?.message||'',/Java 11/);
@@ -90,4 +144,4 @@ const backend=fs.readFileSync(new URL('../../backend/src/main/java/com/workbench
assert.match(backend,/HmiImsapiGateway\.targetOrigin\(request\)/);
assert.doesNotMatch(backend,/private static final String BASE = "https:\/\/partner/);
assert.ok(fs.statSync(new URL('../public/cheerpj/workplace-resize-bridge-v2.jar',import.meta.url)).size>1000);
console.log('CheerpJ contracts: JNLP, HTTP same-origin, no cross-origin, iTAC 129 JARs, Bridge classpath validated.');
console.log('CheerpJ contracts: JNLP, HTTP same-origin, iTAC 129 JARs, writable virtual temp directory and startup ordering validated.');