190 lines
8.0 KiB
JavaScript
190 lines
8.0 KiB
JavaScript
// WidgetWorkbench V5.10.19: self-contained, Java-11-only CheerpJ diagnostics.
|
|
// No iTAC JARs, MES calls, credentials or modification of JDK/vendor classes.
|
|
import wwprobeNativeHandlers from './cheerpj/natives/wwprobe.js';
|
|
|
|
const out = document.getElementById('result');
|
|
const diagnosticModes = ['environment', 'sysprop', 'direct', 'wwprobe', 'jaas', 'unix', 'bridge'];
|
|
const params = new URL(location.href).searchParams;
|
|
const mode = diagnosticModes.includes(params.get('mode')) ? params.get('mode') : 'environment';
|
|
const runtime = params.get('runtime') === '4.3' ? '4.3' : '5.0';
|
|
const pathVariant = params.get('path') === 'missing' ? 'missing' : 'normal';
|
|
const nativeRoot = '/backend/hmi/cheerpj/natives';
|
|
const classJar = '/backend/hmi/cheerpj/jaas-native-loader-smoke.jar';
|
|
const bridgeJar = '/backend/hmi/cheerpj/jaas-identity-bridge.jar';
|
|
const logs = [];
|
|
let resultCode = null;
|
|
let resultStatus = 'NOT_RUN';
|
|
const log = (...parts) => {
|
|
const line = parts.map(value => {
|
|
if (value === null) return 'null';
|
|
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
return '(Objekt: siehe Konsole)';
|
|
}).join(' ');
|
|
logs.push(line);
|
|
out.textContent += line + '\n';
|
|
console.info('[WidgetWorkbench/NativeLoaderSmoke]', ...parts);
|
|
};
|
|
|
|
function renderModeLinks() {
|
|
const links = document.getElementById('modes');
|
|
if (!links) return;
|
|
for (const name of diagnosticModes) {
|
|
const a = document.createElement('a');
|
|
const url = new URL(location.href);
|
|
url.searchParams.set('mode', name);
|
|
url.searchParams.set('runtime', runtime);
|
|
url.searchParams.delete('path');
|
|
a.href = url.pathname + url.search;
|
|
a.textContent = name;
|
|
a.setAttribute('aria-current', name === mode ? 'page' : 'false');
|
|
links.appendChild(a);
|
|
}
|
|
const variants = document.getElementById('runtime-links');
|
|
if (!variants) return;
|
|
for (const name of ['5.0', '4.3']) {
|
|
const a = document.createElement('a');
|
|
const url = new URL(location.href);
|
|
url.searchParams.set('runtime', name);
|
|
a.href = url.pathname + url.search;
|
|
a.textContent = 'CheerpJ ' + name;
|
|
a.setAttribute('aria-current', name === runtime ? 'page' : 'false');
|
|
variants.appendChild(a);
|
|
}
|
|
}
|
|
|
|
function report() {
|
|
return [
|
|
'WidgetWorkbench 5.10.19 - CheerpJ Native Loader Diagnosis',
|
|
'CheerpJ runtime: ' + runtime + ' | Java: 11 | mode: ' + mode,
|
|
'java.library.path variant: ' + pathVariant,
|
|
'Run result: ' + resultStatus + (resultCode !== null ? ' (exit ' + resultCode + ')' : ''),
|
|
'No MES account information or internal URLs are recorded.',
|
|
'',
|
|
...logs,
|
|
'',
|
|
'NOTE: Java System.out/System.err and JVM_LoadLibrary events appear separately',
|
|
'in the browser developer console. Attach only the relevant [NATIVE-LOADER]',
|
|
'lines when reporting to the runtime vendor.',
|
|
].join('\n');
|
|
}
|
|
function installCopyButton() {
|
|
const btn = document.getElementById('copy-report');
|
|
if (!btn) return;
|
|
btn.addEventListener('click', async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(report());
|
|
btn.textContent = 'Bericht kopiert';
|
|
} catch (_) {
|
|
const blob = new Blob([report()], { type: 'text/plain;charset=utf-8' });
|
|
const obj = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = obj;
|
|
a.download = 'cheerpj-native-' + runtime + '-' + mode + '.txt';
|
|
a.click();
|
|
URL.revokeObjectURL(obj);
|
|
btn.textContent = 'Bericht als Datei gespeichert';
|
|
}
|
|
});
|
|
}
|
|
|
|
async function checkResource(url, { range = false, module = false } = {}) {
|
|
const resp = await fetch(url, {
|
|
credentials: 'same-origin',
|
|
cache: 'no-store',
|
|
...(range ? { headers: { Range: 'bytes=0-0' } } : {}),
|
|
});
|
|
const type = resp.headers.get('content-type') || '(nicht angegeben)';
|
|
const ranges = resp.headers.get('accept-ranges') || '(nicht angegeben)';
|
|
const contentRange = resp.headers.get('content-range') || '(nicht angegeben)';
|
|
log(url, 'HTTP', resp.status, 'Content-Type:', type, 'Accept-Ranges:', ranges,
|
|
range ? 'Content-Range: ' + contentRange : '');
|
|
if (!resp.ok) throw new Error('Datei nicht abrufbar: ' + url + ' (HTTP ' + resp.status + ')');
|
|
if (range && resp.status !== 206) {
|
|
throw new Error('Java-JAR unterstützt keinen HTTP-Range-Abruf (HTTP ' + resp.status + '): ' + url);
|
|
}
|
|
if (range && !/^bytes\s+0-0\/\d+$/i.test(contentRange) && contentRange !== '(nicht angegeben)') {
|
|
throw new Error('Ungültige Content-Range für JAR: ' + contentRange);
|
|
}
|
|
if (module) {
|
|
const source = await resp.text();
|
|
if (type.toLowerCase().includes('text/html') || !source.includes('export default') ||
|
|
!source.includes('Java_com_')) {
|
|
throw new Error('JS-Native-Modul fehlt oder Server liefert HTML: ' + url);
|
|
}
|
|
} else if (resp.body && typeof resp.body.cancel === 'function') {
|
|
await resp.body.cancel(); // With Range, never fetch a complete large JAR.
|
|
}
|
|
}
|
|
|
|
async function ensureRuntimeLoader() {
|
|
if (typeof cheerpjInit === 'function') {
|
|
log('CheerpJ-Loader bereits verfügbar.');
|
|
return;
|
|
}
|
|
// Only these two fixed release URLs are permitted, never user-supplied URLs.
|
|
const url = 'https://cjrtnc.leaningtech.com/' + runtime + '/loader.js';
|
|
log('CheerpJ-Loader:', 'release ' + runtime);
|
|
await new Promise((resolve, reject) => {
|
|
const script = document.createElement('script');
|
|
script.src = url;
|
|
script.onload = () => resolve();
|
|
script.onerror = () => reject(new Error('CheerpJ-Loader nicht erreichbar: release ' + runtime));
|
|
document.head.appendChild(script);
|
|
});
|
|
if (typeof cheerpjInit !== 'function') throw new Error('cheerpjInit nach Laden nicht verfügbar');
|
|
}
|
|
|
|
async function run() {
|
|
resultStatus = 'RUNNING';
|
|
log('V5.10.19 | Modus:', mode, '| Java 11 | CheerpJ:', runtime);
|
|
log('Dieser Test ist unabhängig von iTAC und GlassFish-Java-Prozessen.');
|
|
await checkResource(classJar, { range: true });
|
|
if (mode === 'bridge') await checkResource(bridgeJar, { range: true });
|
|
if (mode === 'direct' || mode === 'wwprobe') {
|
|
await checkResource(nativeRoot + '/wwprobe.js', { module: true });
|
|
} else if (mode === 'jaas' || mode === 'unix') {
|
|
await checkResource(nativeRoot + '/jaas.js', { module: true });
|
|
}
|
|
await ensureRuntimeLoader();
|
|
const libPath = pathVariant === 'missing'
|
|
? '/app/backend/hmi/cheerpj/absichtlich-nicht-vorhanden'
|
|
: '/app' + nativeRoot;
|
|
const settings = {
|
|
version: 11,
|
|
status: 'none',
|
|
javaProperties: ['java.library.path=' + libPath],
|
|
};
|
|
if (mode === 'direct') {
|
|
settings.natives = wwprobeNativeHandlers;
|
|
log('Direkter JNI-Handler registriert. Kein System.loadLibrary.');
|
|
} else {
|
|
log('Kein direkter Native-Handler registriert; Isolation des Testmodus.');
|
|
}
|
|
await cheerpjInit(settings);
|
|
log('CheerpJ Java 11 initialisiert; Testklasse starten …');
|
|
const classpath = '/app' + classJar + (mode === 'bridge' ? ':/app' + bridgeJar : '');
|
|
const code = await cheerpjRunMain('com.widgetworkbench.cheerpj.NativeLoaderSmoke', classpath, mode);
|
|
resultCode = typeof code === 'number' ? code : null;
|
|
resultStatus = code === 0 ? 'PASS' : 'FAIL';
|
|
log('Java-Exit-Code:', resultCode === null ? 'nicht numerisch' : resultCode);
|
|
log('TESTERGEBNIS:', resultStatus);
|
|
if (mode === 'direct' && code === 0) {
|
|
log('Direct JNI funktioniert. System.loadLibrary/UnixSystem ist dadurch NICHT repariert.');
|
|
} else if (mode === 'bridge' && code === 0) {
|
|
log('Java-Bridge funktioniert OHNE UnixSystem-Konstruktor. Kein produktiver Login-Workaround.');
|
|
}
|
|
log('Für vollständige Java-Fehlerdetails die [NATIVE-LOADER]-Zeilen aus der Browserkonsole hinzufügen.');
|
|
}
|
|
|
|
renderModeLinks();
|
|
installCopyButton();
|
|
out.textContent = '';
|
|
run().catch(error => {
|
|
resultStatus = 'ABORT';
|
|
// CheerpJ Java Throwable proxies can fail conversion to String(); preserve original.
|
|
console.error('[WidgetWorkbench/NativeLoaderSmoke] Original exception:', error);
|
|
const reason = error instanceof Error && typeof error.message === 'string'
|
|
? error.message : 'Java-/Runtime-Exception; Original in der Browserkonsole';
|
|
log('TESTABBRUCH:', reason);
|
|
});
|