444 lines
24 KiB
JavaScript
444 lines
24 KiB
JavaScript
import jaasNativeHandlers from './cheerpj/natives/jaas.js';
|
||
|
||
/* WidgetWorkbench CheerpJ 5.0 runner (4.3 selectable as a compatibility fallback).
|
||
* CheerpJ Core has no documented runJNLP(url) API: parse the manifest and run JAR(s).
|
||
* Deliberately SAME-ORIGIN only. Do not turn this into an open server-side URL proxy.
|
||
*/
|
||
const screen=document.getElementById('display');
|
||
const notice=document.getElementById('state');
|
||
const BRIDGE_JAR='/app/backend/hmi/cheerpj/workplace-window-monitor-v3.jar';
|
||
// JS implementation for OpenJDK UnixSystem.getUnixInfo. Register the handler via
|
||
// cheerpjInit({natives}) AND keep the JS native library for System.loadLibrary.
|
||
// Note: registration cannot repair a missing CheerpJ JVM_LoadLibrary import.
|
||
const JAAS_JS_URL='/backend/hmi/cheerpj/natives/jaas.js';
|
||
const JAAS_NATIVE_PATH='/app/backend/hmi/cheerpj/natives';
|
||
const JAAS_BRIDGE_JAR='/app/backend/hmi/cheerpj/jaas-identity-bridge.jar';
|
||
// Optional, experimentally isolated Java 11 fallback for iTAC SysParameter.
|
||
// MUST come before vendor JARs; class loading/signature conflicts are checked
|
||
// separately and MUST NOT be silently ignored.
|
||
const SYSPARAM_PATCH_URL='/backend/hmi/cheerpj/sysparameter-jaas-fallback-java11.jar';
|
||
const SYSPARAM_PATCH_JAR='/app'+SYSPARAM_PATCH_URL;
|
||
|
||
// JSON-P 1.1 provider required by iTAC ParameterType; NOT included in Workplace.jnlp.
|
||
// Maven packages this dependency as a static WAR resource.
|
||
const JSONP_PROVIDER_URL='/backend/hmi/cheerpj-libs/javax.json-1.1.4.jar';
|
||
const JSONP_PROVIDER_JAR='/app'+JSONP_PROVIDER_URL;
|
||
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';
|
||
// CheerpJ /files is writable. A flat and finally root fallback handle engines
|
||
// that cannot create nested directories or previously conflicting user files.
|
||
const WORKPLACE_TMP_CANDIDATES=[WORKPLACE_TMP_DIR,'/files/itac-workplace-tmp','/files'];
|
||
let busy=false;
|
||
// Collect the last boot stage so a CheerpJ WASM exit code can be tied to the
|
||
// Java startup phase. No credentials, JNLP arguments or MES URLs are logged.
|
||
let bootStage='not-started';
|
||
function boot(stage){
|
||
bootStage=stage;
|
||
console.info('[WidgetWorkbench/CheerpJ] '+stage);
|
||
}
|
||
// CheerpJ can reject library-mode calls with a Java Throwable proxy. Such
|
||
// objects do NOT necessarily implement JS Symbol.toPrimitive/toString, so
|
||
// String(error), a template literal or `'' + error` can replace the original
|
||
// JAAS exception with "Cannot convert object to primitive value".
|
||
function primitiveText(value){
|
||
switch(typeof value){
|
||
case 'string': return value;
|
||
case 'number': case 'boolean': case 'bigint': return String(value);
|
||
default: return null;
|
||
}
|
||
}
|
||
async function describeThrowable(error,depth=0,seen=new Set()){
|
||
const direct=primitiveText(error);
|
||
if(direct!==null)return direct;
|
||
if(error===null||error===undefined)return 'Unbekannte JavaScript-Ausnahme';
|
||
if(depth>2||seen.has(error))return 'Weitere Exception (rekursiv)';
|
||
seen.add(error);
|
||
let className=null, message=null, stack=null, cause=null;
|
||
try{
|
||
const getClass=error.getClass;
|
||
if(typeof getClass==='function'){
|
||
const cls=await getClass.call(error);
|
||
if(cls && typeof cls.getName==='function')className=primitiveText(await cls.getName());
|
||
}
|
||
}catch(_ignored){ /* Java proxy may not expose class metadata. */ }
|
||
try{if(!className)className=primitiveText(error.name);}catch(_ignored){}
|
||
try{
|
||
const getMessage=error.getMessage;
|
||
if(typeof getMessage==='function')message=primitiveText(await getMessage.call(error));
|
||
}catch(_ignored){ /* Read the original exception below without replacing it. */ }
|
||
try{if(!message)message=primitiveText(error.message);}catch(_ignored){}
|
||
try{
|
||
if(!message && typeof error.toString==='function'){
|
||
message=primitiveText(await error.toString());
|
||
}
|
||
}catch(_ignored){}
|
||
try{stack=primitiveText(error.stack);}catch(_ignored){}
|
||
try{
|
||
if(typeof error.getCause==='function')cause=await error.getCause();
|
||
else cause=error.cause;
|
||
}catch(_ignored){}
|
||
let result=[className,message].filter(Boolean).join(': ');
|
||
if(!result && stack)result=stack;
|
||
if(!result)result='CheerpJ-Java-Exception (nicht als JavaScript-String lesbar)';
|
||
if(cause!==null&&cause!==undefined&&cause!==error)
|
||
result+=' | Ursache: '+await describeThrowable(cause,depth+1,seen);
|
||
return result.slice(0,900);
|
||
}
|
||
async function describeFailure(error){
|
||
// Keep the original object accessible in DevTools, not only a reformatted copy.
|
||
console.error('[WidgetWorkbench/CheerpJ] Failure in '+bootStage+' (original):',error);
|
||
const reason=await describeThrowable(error);
|
||
return 'CheerpJ-Start fehlgeschlagen in Phase "'+bootStage+'": '+reason+
|
||
'. Details in der Browser-Konsole (WidgetWorkbench/CheerpJ).';
|
||
}
|
||
// Optional browser-JVM probe: ?diagnose=jaas. Only exercised on demand.
|
||
// Does not replace the real iTAC authentication or modify vendor JARs.
|
||
async function probeJaasRuntime(lib){
|
||
boot('JAAS: UnixSystem-Klasse laden');
|
||
const UnixSystem=await lib.com.sun.security.auth.module.UnixSystem;
|
||
boot('JAAS: UnixSystem-Konstruktor (System.loadLibrary)');
|
||
const instance=await new UnixSystem();
|
||
boot('JAAS: UnixSystem.getUsername()');
|
||
const user=await instance.getUsername();
|
||
let identityOk=user==='cheerpj-client';
|
||
// CheerpJ generally passes Java String by value, but guard versions that
|
||
// expose a Java proxy instead of coercing that object with String(user).
|
||
if(!identityOk && user!=null){
|
||
try{if(typeof user.equals==='function')identityOk=(await user.equals('cheerpj-client'))===true;}
|
||
catch(_ignored){}
|
||
}
|
||
console.info('[WidgetWorkbench/CheerpJ] UnixSystem konstruiert; synthetische Benutzeridentität gültig:',identityOk);
|
||
if(!identityOk)throw Error('JAAS-Runtimeprüfung: unerwartete virtuelle Benutzeridentität');
|
||
boot('JAAS-Laufzeittest erfolgreich (UnixSystem)');
|
||
}
|
||
|
||
const trusted=(raw,base=location.href)=>{
|
||
const u=new URL(raw,base);
|
||
if(u.origin!==location.origin)throw Error('JNLP und alle JARs müssen von derselben Origin wie WidgetWorkbench kommen.');
|
||
if(!['http:','https:'].includes(u.protocol))throw Error('Nur HTTP und HTTPS werden unterstützt.');
|
||
if(u.username||u.password||u.hash)throw Error('URL mit Zugangsdaten oder Fragment nicht unterstützt.');
|
||
return u;
|
||
};
|
||
function readManifest(xml,jnlpUrl){
|
||
if(xml.length>1024*1024||/<!\s*(?:DOCTYPE|ENTITY)/i.test(xml))throw Error('Unsichere oder zu große JNLP-Datei.');
|
||
const documentXml=new DOMParser().parseFromString(xml,'application/xml');
|
||
if(documentXml.getElementsByTagName('parsererror').length)throw Error('JNLP-XML ungültig.');
|
||
const root=documentXml.documentElement;
|
||
if(root.localName!=='jnlp')throw Error('Das Dokument ist keine JNLP-Datei.');
|
||
if(root.getElementsByTagName('extension').length)
|
||
throw Error('JNLP mit Extension-JNLP ist noch nicht unterstützt.');
|
||
const app=root.getElementsByTagName('application-desc')[0];
|
||
if(!app)throw Error('Nur JNLP mit application-desc wird unterstützt (kein Applet/Installer).');
|
||
// Browser-VM: nur plattformunabhängige Gruppen laden; Windows/Linux-JNI ist nicht ausführbar.
|
||
const groups=Array.from(root.getElementsByTagName('resources'));
|
||
const platformGroups=groups.filter(g=>g.hasAttribute('os')||g.hasAttribute('arch'));
|
||
const jars=groups.filter(g=>!g.hasAttribute('os')&&!g.hasAttribute('arch'))
|
||
.flatMap(g=>Array.from(g.getElementsByTagName('jar')));
|
||
if(!jars.length||jars.length>256)throw Error('Keine JAR-Dateien oder mehr als 256 JARs.');
|
||
const jvm=groups.flatMap(g=>Array.from(g.getElementsByTagName('java')))[0];
|
||
const required=jvm?.getAttribute('version')?.match(/^(8|11|17)/)?.[1];
|
||
const warnings=[];
|
||
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.');
|
||
const u=trusted(href,base.href.endsWith('/')?base.href:base.href+'/');
|
||
if(!u.pathname.toLowerCase().endsWith('.jar'))throw Error('Nur direkte .jar-Ressourcen unterstützt.');
|
||
if(u.search)throw Error('Signierte JAR-URLs mit Queryparametern benötigen eine besondere Integration.');
|
||
return '/app'+u.pathname;
|
||
});
|
||
const main=app.getAttribute('main-class')||'';
|
||
if(main&&!/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(main))throw Error('Ungültige Java-Main-Klasse.');
|
||
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,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(lib) {
|
||
// Use Java NIO through CheerpJ Library Mode. Checking Files.isDirectory()
|
||
// with `=== true` is not reliable across CheerpJ versions: the reported
|
||
// value can be a bridge wrapper, even when the directory is writable.
|
||
// The real requirement for java.io.tmpdir is that Java can create a file.
|
||
if (!lib)throw Error('CheerpJ Library Mode für das Temp-Verzeichnis nicht verfügbar.');
|
||
const Paths=await lib.java.nio.file.Paths;
|
||
const Files=await lib.java.nio.file.Files;
|
||
const System=await lib.java.lang.System;
|
||
const errors=[];
|
||
for(const candidate of WORKPLACE_TMP_CANDIDATES){
|
||
try{
|
||
const dir=await Paths.get(candidate);
|
||
if(candidate!=='/files')await Files.createDirectories(dir,[]);
|
||
// A successful write/delete is stronger proof than isDirectory() and
|
||
// works independently of Java boolean conversion in the JS bridge.
|
||
const probe=await Files.createTempFile(dir,'hmi-tmp-check-','.tmp',[]);
|
||
try{
|
||
const deleted=await Files.deleteIfExists(probe);
|
||
if(deleted===false)throw Error('Schreibtestdatei konnte nicht entfernt werden.');
|
||
}catch(cleanupError){
|
||
throw Error('Temporäre Testdatei konnte nicht gelöscht werden: '+await describeThrowable(cleanupError));
|
||
}
|
||
// Bootstrap with java.io.tmpdir=/files (always an existing mount point),
|
||
// then configure the tested directory before invoking Workplace main().
|
||
await System.setProperty('java.io.tmpdir',candidate);
|
||
return candidate;
|
||
}catch(error){
|
||
errors.push(candidate+': '+await describeThrowable(error));
|
||
}
|
||
}
|
||
throw Error('CheerpJ-Temp-Verzeichnis nicht beschreibbar ('+errors.join(' | ')+').');
|
||
}
|
||
|
||
// V5.10.21: Do NOT concurrently call a CheerpJ Library Mode method from
|
||
// JS timers. CheerpJ may reject the second invocation with:
|
||
// "Java code still running, check for a missing 'await'".
|
||
// The Java bridge starts ONE daemon monitor before main(), which handles
|
||
// resize and window inspection entirely inside the JVM/AWT thread domain.
|
||
// No further JS -> CheerpJ library-mode calls are made while main() runs.
|
||
async function attachWorkplaceRuntimeMonitor(container, lib, windowMode, displayMode) {
|
||
if(!lib)throw Error('CheerpJ Library Mode für Fensterüberwachung nicht verfügbar.');
|
||
const bridge=await lib.com.widgetworkbench.cheerpj.WorkplaceResizeBridge;
|
||
if(typeof bridge.startRuntimeMonitor!=='function')
|
||
throw Error('Workplace Window Monitor v3 fehlt: startRuntimeMonitor nicht vorhanden. JAR V5.10.21 prüfen.');
|
||
const panel=document.getElementById('window-diagnostics');
|
||
const output=document.getElementById('window-diagnostics-output');
|
||
const bounds=container.getBoundingClientRect();
|
||
const width=displayMode==='original'?1280:Math.max(200,Math.floor(bounds.width));
|
||
const height=displayMode==='original'?1024:Math.max(150,Math.floor(bounds.height));
|
||
// This sequential library-mode call completes before cheerpjRunMain().
|
||
// startRuntimeMonitor returns immediately; Java then polls independently.
|
||
const started=await bridge.startRuntimeMonitor(width,height,windowMode);
|
||
if(Number(started)!==1&&Number(started)!==2)
|
||
throw Error('Workplace Window Monitor wurde nicht gestartet (Code '+(primitiveText(started)??'?')+').');
|
||
if(windowMode!=='off'){
|
||
if(panel)panel.hidden=false;
|
||
if(output)output.textContent='Java-11-Fensterdiagnose aktiv ('+windowMode+').\n'
|
||
+'Ausgabe in der Browser-Konsole: [WidgetWorkbench/WindowGeometry]\n'
|
||
+'Die Abfragen laufen im Java-Hintergrundthread, ohne parallele CheerpJ-Library-Aufrufe.';
|
||
}
|
||
console.info('[WidgetWorkbench/WindowGeometry] Java-interner Monitor gestartet; '
|
||
+width+'x'+height+'; Modus='+windowMode+'; keine JS-Library-Polling-Aufrufe.');
|
||
return {stop(){ /* Monitor lebt als Java-Daemon bis zum Ende der JVM. */ }};
|
||
}
|
||
|
||
function status(requestId,state,message){
|
||
const text=String(message).slice(0,350);
|
||
notice.textContent=text;notice.className=state==='error'?'fail':'';
|
||
if(window.parent!==window)parent.postMessage({type:'hmi-cheerpj-state',requestId,state,message:text},location.origin);
|
||
}
|
||
async function start(e,data){
|
||
const id=data.requestId;
|
||
try {
|
||
if(busy)throw Error('Eine Java-Anwendung läuft bereits in diesem Frame.');
|
||
busy=true;
|
||
const url=trusted(data.jnlpUrl);
|
||
const version=Number(data.javaVersion);
|
||
if(![8,11,17].includes(version))throw Error('Ungültige Java-Version.');
|
||
const isWorkplace=data.workplace===true && url.pathname===WORKPLACE_MANIFEST;
|
||
const displayMode=data.displayMode==='original'?'original':'fit';
|
||
const params=new URL(location.href).searchParams;
|
||
const rawWindowMode=data.windowMode ?? params.get('windows');
|
||
const windowMode=isWorkplace && ['off','diagnose','rescue'].includes(rawWindowMode)
|
||
? rawWindowMode : 'off';
|
||
boot('JNLP-Abruf');
|
||
status(id,'loading','JNLP wird gelesen …');
|
||
const r=await fetch(url.href,{credentials:'same-origin',redirect:'follow',cache:'no-store'});
|
||
if(!r.ok||!r.url||trusted(r.url).origin!==location.origin)throw Error('JNLP nicht abrufbar (HTTP '+r.status+').');
|
||
const xml=await r.text();
|
||
const manifest=readManifest(xml,url.href);
|
||
if(manifest.required && Number(manifest.required)!==version)throw Error('JNLP erfordert Java '+manifest.required+', Widget ist auf Java '+version+' eingestellt.');
|
||
status(id,'loading',manifest.paths.length+' Java-Bibliotheken · '+(manifest.warnings.join(' ')||'CheerpJ wird geladen …'));
|
||
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);});
|
||
}
|
||
// Keep a single JVM library context for tmp, optional JAAS diagnostics and
|
||
// ResizeBridge: CheerpJ allows only one library thread in this configuration.
|
||
const sysparamPatchEnabled=isWorkplace && params.get('sysparam')==='on';
|
||
// Put the patch FIRST, before the vendor JNLP JARs, for both the one
|
||
// CheerpJ Library Mode context and main(). When off, retain the old classpath.
|
||
const cp=(sysparamPatchEnabled ? SYSPARAM_PATCH_JAR+':' : '')
|
||
+manifest.paths.join(':')+(isWorkplace
|
||
? ':'+JSONP_PROVIDER_JAR+':'+JAAS_BRIDGE_JAR+':'+BRIDGE_JAR : '');
|
||
const diag=new URL(location.href).searchParams.get('diagnose');
|
||
// Explicitly verify native JavaScript is delivered before VM initialization;
|
||
// a successful HTTP response alone does NOT guarantee System.loadLibrary works.
|
||
if(isWorkplace){
|
||
boot('JAAS-JavaScript abrufen');
|
||
const nativeResponse=await fetch(JAAS_JS_URL,{credentials:'same-origin',cache:'no-store'});
|
||
if(!nativeResponse.ok)throw Error('JAAS-Kompatibilitätsmodul fehlt (HTTP '+nativeResponse.status+').');
|
||
if(typeof jaasNativeHandlers?.Java_com_sun_security_auth_module_UnixSystem_getUnixInfo!=='function')
|
||
throw Error('JAAS-JavaScript enthält keine gültige UnixSystem-JNI-Implementierung.');
|
||
}
|
||
// Verify delivery before starting the JVM. This is a same-origin immutable
|
||
// build asset, never a dynamic/JNLP-defined classpath entry.
|
||
if(sysparamPatchEnabled){
|
||
boot('SysParameter-JAAS-Fallback-JAR prüfen');
|
||
const patchResponse=await fetch(SYSPARAM_PATCH_URL,{
|
||
credentials:'same-origin',cache:'no-store',headers:{Range:'bytes=0-0'}
|
||
});
|
||
if(patchResponse.status!==206)throw Error('SysParameter-JAAS-Fallback-JAR nicht mit HTTP 206 abrufbar '
|
||
+'(HTTP '+patchResponse.status+'). Build/Deployment prüfen oder mit ?sysparam=off isoliert testen.');
|
||
}
|
||
// JNLP URL query parameters are not Java system properties.
|
||
// CheerpJ supplies -D equivalents through javaProperties.
|
||
const javaProperties=isWorkplace && manifest.clusterNodes
|
||
? ['itac.artes.clusternodes='+manifest.clusterNodes] : [];
|
||
// /files exists already when the Java VM initializes; choose the actual
|
||
// writable subdirectory after probing, before launching the application.
|
||
if(isWorkplace){
|
||
javaProperties.push('java.io.tmpdir=/files');
|
||
if(params.get('identity')!=='native')javaProperties.push('os.name=CheerpJ Browser','user.name=cheerpj-client');
|
||
// Must be present at VM initialization: UnixSystem() calls loadLibrary("jaas")
|
||
// before running its private native method getUnixInfo().
|
||
javaProperties.push('java.library.path='+JAAS_NATIVE_PATH);
|
||
}
|
||
boot('CheerpJ-Initialisierung');
|
||
await window.cheerpjInit({version,status:'none',javaProperties,
|
||
...(isWorkplace ? {natives:jaasNativeHandlers} : {})});
|
||
boot('CheerpJ initialisiert');
|
||
let sharedLib=null;
|
||
if(isWorkplace){
|
||
boot('Gemeinsamen Java-Library-Kontext starten');
|
||
sharedLib=await window.cheerpjRunLibrary(cp);
|
||
if(sysparamPatchEnabled){
|
||
// Force resolution of this exact class BEFORE the vendor main launches.
|
||
// An absent marker means an original iTAC class shadowed our patch.
|
||
// SecurityException / NoClassDefFoundError here may signal signed-package
|
||
// conflict and are NEVER suppressed as an apparent successful patch.
|
||
boot('SysParameter-Ersatzklasse verifizieren');
|
||
try{
|
||
const SysParameter=await sharedLib.com.itac.util.system.SysParameter;
|
||
if(typeof SysParameter?.widgetWorkbenchJaasFallbackLevel!=='function')
|
||
throw Error('Originalklasse aktiv: Patch-Marker nicht gefunden. Klassenpfad-Reihenfolge prüfen.');
|
||
const level=await SysParameter.widgetWorkbenchJaasFallbackLevel();
|
||
if(Number(level)!==1)throw Error('Unerwartete SysParameter-Patchversion.');
|
||
console.info('[WidgetWorkbench/SysParameter] JAAS-Fallback-Ersatzklasse v1 aktiviert; '
|
||
+'iTAC PersonService-Authentifizierung unverändert.');
|
||
}catch(error){
|
||
const original=await describeThrowable(error);
|
||
throw Error('SysParameter-Patch konnte nicht geladen oder verifiziert werden: '+original+
|
||
'. Möglicher Signatur-/Split-Package-Konflikt mit iTAC-JARs. '
|
||
+'Für den unveränderten Klassenpfad ?sysparam=off verwenden.');
|
||
}
|
||
}
|
||
status(id,'loading','Virtuelles Workplace-Temp-Verzeichnis wird vorbereitet …');
|
||
boot('Temp-Verzeichnis prüfen');
|
||
const tempDir=await ensureWorkplaceTempDirectory(sharedLib);
|
||
if(tempDir!==WORKPLACE_TMP_DIR)manifest.warnings.push('Temp-Ausweichverzeichnis: '+tempDir+'.');
|
||
}
|
||
boot('Java-Anzeigefläche vorbereiten');
|
||
if(isWorkplace && displayMode==='original'){
|
||
document.body.classList.add('cheerpj-original-mode');
|
||
window.cheerpjCreateDisplay(1280,1024,screen);
|
||
}else{
|
||
window.cheerpjCreateDisplay(-1,-1,screen);
|
||
}
|
||
let windowMonitor=null;
|
||
if(isWorkplace){
|
||
// Range probe catches a missing WAR-bundled provider (or server-side
|
||
// Range misconfiguration) before Java reports opaque ExceptionInInitializerError.
|
||
boot('JSON-P-JAR prüfen');
|
||
const jsonpProbe=await fetch(JSONP_PROVIDER_URL,{
|
||
credentials:'same-origin',cache:'no-store',headers:{Range:'bytes=0-0'}
|
||
});
|
||
if(jsonpProbe.status!==206){
|
||
throw Error('JSON-P-Provider im WAR fehlt oder unterstützt kein HTTP Range '
|
||
+'(HTTP '+jsonpProbe.status+'). Maven-Build und '
|
||
+'hmi/cheerpj-libs/javax.json-1.1.4.jar prüfen.');
|
||
}
|
||
// Validate the helper JAR before Java main(); the native JS module has
|
||
// already been registered via cheerpjInit({natives}) above.
|
||
boot('JAAS-Bridge-JAR prüfen');
|
||
const bridgeProbe=await fetch(JAAS_BRIDGE_JAR.slice(4),{
|
||
credentials:'same-origin',cache:'no-store',headers:{Range:'bytes=0-0'}
|
||
});
|
||
if(bridgeProbe.status!==206)throw Error('JAAS-Java-Hilfsklasse nicht als JAR abrufbar '
|
||
+'(HTTP '+bridgeProbe.status+'). hmi/cheerpj/jaas-identity-bridge.jar prüfen.');
|
||
// The vendor JNLP contains javax.json API but not its implementation.
|
||
// Keep proprietary JARs untouched; helpers are part of the shared cp.
|
||
if(diag==='jaas' || diag==='jaas-only'){
|
||
try{
|
||
await probeJaasRuntime(sharedLib);
|
||
}catch(error){
|
||
console.error('[WidgetWorkbench/CheerpJ] JAAS-Laufzeittest Original-Exception:',error);
|
||
const msg=await describeThrowable(error);
|
||
throw Error('JAAS-Laufzeittest fehlgeschlagen. '+msg+'; '
|
||
+'falls JVM_LoadLibrary oder no jaas in java.library.path gemeldet wird, '
|
||
+'liegt das Problem bereits beim nativen Library-Loader der CheerpJ-JVM.',
|
||
{cause:error});
|
||
}
|
||
if(diag==='jaas-only'){
|
||
boot('JAAS-Laufzeittest erfolgreich – kein Workplace-Start');
|
||
status(id,'finished','JAAS UnixSystem erfolgreich initialisiert. Workplace nicht gestartet (Diagnosemodus).');
|
||
return;
|
||
}
|
||
}
|
||
boot('Java-internen Swing-Fenstermonitor starten ('+windowMode+')');
|
||
try{
|
||
windowMonitor=await attachWorkplaceRuntimeMonitor(screen,sharedLib,windowMode,displayMode);
|
||
}catch(error){
|
||
console.warn('[WidgetWorkbench/WindowGeometry] Java-interner Monitor nicht verfügbar:',error);
|
||
manifest.warnings.push('Fenstermonitor nicht verfügbar; Workplace-Start wird fortgesetzt.');
|
||
}
|
||
}
|
||
if(isWorkplace && params.get('identity')!=='native'){
|
||
// Browser JVM has no host OS identity. The original signed SysParameter
|
||
// explicitly falls back to user.name for non-desktop OS names. Set this
|
||
// in the library context too; init properties also cover runMain.
|
||
// Manufacturer bytecode remains unchanged.
|
||
boot('Browser-Identität ohne Desktop-JAAS vorbereiten');
|
||
const System=await sharedLib.java.lang.System;
|
||
await System.setProperty('os.name','CheerpJ Browser');
|
||
await System.setProperty('user.name','cheerpj-client');
|
||
}
|
||
boot('iTAC Workplace main(): '+(manifest.main?'Startklasse vorhanden':'JAR-Start'));
|
||
status(id,'running','Java-Anwendungsstart wird versucht. '+manifest.warnings.join(' '));
|
||
try{
|
||
const exitCode=manifest.main
|
||
? await window.cheerpjRunMain(manifest.main,cp,...manifest.args)
|
||
: await window.cheerpjRunJar(manifest.paths[0],...manifest.args);
|
||
boot('Java main() beendet');
|
||
status(id,'finished','Anwendung beendet (Exit-Code '+exitCode+').');
|
||
}finally{windowMonitor?.stop();}
|
||
}catch(error){status(id,'error',await describeFailure(error));}
|
||
}
|
||
window.addEventListener('message',event=>{
|
||
if(event.source!==window.parent||event.origin!==location.origin)return;
|
||
const data=event.data;
|
||
if(!data||data.type!=='hmi-cheerpj-launch'||typeof data.requestId!=='string'||data.requestId.length>150)return;
|
||
void start(event,data);
|
||
});
|
||
|
||
// Direct, full-window workplace mode. This URL is deliberately limited to the
|
||
// fixed authenticated MES JNLP bridge. No arbitrary JNLP or Java class name
|
||
// can be supplied through query parameters.
|
||
if(new URL(location.href).searchParams.get('standalone')==='workplace'){
|
||
document.body.classList.add('cheerpj-standalone');
|
||
void start(null,{
|
||
requestId:'standalone-workplace',
|
||
jnlpUrl:new URL(WORKPLACE_MANIFEST,location.href).href,
|
||
javaVersion:11,
|
||
workplace:true,
|
||
displayMode:'fit',
|
||
windowMode:new URL(location.href).searchParams.get('windows')
|
||
});
|
||
}
|