Workplace Widget 5.10.8
This commit is contained in:
@@ -58,12 +58,18 @@ final class HmiWorkplaceConfiguration {
|
||||
try {
|
||||
URI expected=URI.create(HmiImsapiGateway.targetOrigin(request));
|
||||
URI actual=URI.create(value);
|
||||
if (actual.getUserInfo()!=null || actual.getQuery()!=null || actual.getFragment()!=null
|
||||
if (actual.getUserInfo()!=null || actual.getFragment()!=null
|
||||
|| !expected.getScheme().equalsIgnoreCase(actual.getScheme())
|
||||
|| !expected.getHost().equalsIgnoreCase(actual.getHost())
|
||||
|| effectivePort(expected)!=effectivePort(actual)
|
||||
|| actual.getRawPath()==null || !actual.getRawPath().startsWith(ROOT))
|
||||
throw new IllegalArgumentException("JNLP muss vom angemeldeten MES-Server unter /mes/webstart/clients/ stammen");
|
||||
// Accept the legacy link format for convenience, but do NOT forward
|
||||
// its query to the JNLP server. CheerpJ receives the equivalent
|
||||
// System property via the rewritten local manifest instead.
|
||||
if (actual.getQuery()!=null && !actual.getQuery().equals(
|
||||
"itac.artes.clusternodes=" + expected.toString().replaceAll("/+$", "") + "/mes"))
|
||||
throw new IllegalArgumentException("Nur der MES-eigene itac.artes.clusternodes Parameter ist erlaubt");
|
||||
return verifiedFilename(actual.getRawPath().substring(ROOT.length()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException("Ungültige JNLP-Adresse: "+e.getMessage(),e);
|
||||
|
||||
@@ -27,7 +27,7 @@ final class HmiWorkplaceManifest {
|
||||
final String rewritten;
|
||||
final Set<String> jars;
|
||||
private HmiWorkplaceManifest(String rewritten, Set<String> jars){this.rewritten=rewritten;this.jars=Collections.unmodifiableSet(jars);}
|
||||
static HmiWorkplaceManifest fetch(URL url) throws Exception {
|
||||
static HmiWorkplaceManifest fetch(URL url, String clusterNodes) throws Exception {
|
||||
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
|
||||
connection.setConnectTimeout(8000);connection.setReadTimeout(20000);
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
@@ -61,6 +61,37 @@ final class HmiWorkplaceManifest {
|
||||
approved.add(name);
|
||||
}
|
||||
if(approved.isEmpty()||approved.size()>256)throw new IOException("Unexpected JNLP JAR inventory");
|
||||
// The JNLP URL is a download location. The iTAC cluster-nodes setting is
|
||||
// a JVM system property, so provide it in the sanitized local manifest.
|
||||
java.net.URI mesUri=java.net.URI.create(clusterNodes);
|
||||
if (( !"https".equalsIgnoreCase(mesUri.getScheme()) && !"http".equalsIgnoreCase(mesUri.getScheme()) )
|
||||
|| mesUri.getHost()==null || mesUri.getUserInfo()!=null
|
||||
|| mesUri.getQuery()!=null || mesUri.getFragment()!=null
|
||||
|| !"/mes".equals(mesUri.getPath()))
|
||||
throw new IOException("Invalid MES cluster-nodes origin");
|
||||
Element commonResources=null;
|
||||
NodeList resources=root.getElementsByTagName("resources");
|
||||
for (int i=0;i<resources.getLength();i++) {
|
||||
Element candidate=(Element)resources.item(i);
|
||||
if (!candidate.hasAttribute("os") && !candidate.hasAttribute("arch")) {
|
||||
commonResources=candidate;break;
|
||||
}
|
||||
}
|
||||
if (commonResources==null) throw new IOException("JNLP missing common resources");
|
||||
boolean found=false;
|
||||
NodeList properties=commonResources.getElementsByTagName("property");
|
||||
for(int i=0;i<properties.getLength();i++) {
|
||||
Element property=(Element)properties.item(i);
|
||||
if ("itac.artes.clusternodes".equals(property.getAttribute("name"))) {
|
||||
property.setAttribute("value",clusterNodes);found=true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
Element property=xml.createElement("property");
|
||||
property.setAttribute("name","itac.artes.clusternodes");
|
||||
property.setAttribute("value",clusterNodes);
|
||||
commonResources.appendChild(property);
|
||||
}
|
||||
root.setAttribute("codebase",LOCAL_JARS);
|
||||
// Do not let a static remote href override the cached manifest source.
|
||||
root.removeAttribute("href");
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HmiWorkplaceProxyResource {
|
||||
synchronized(MANIFEST_LOCK) {
|
||||
if(cachedManifest!=null && key.equals(manifestKey)
|
||||
&& System.currentTimeMillis()-manifestLoaded<MANIFEST_TTL_MS)return cachedManifest;
|
||||
HmiWorkplaceManifest downloaded=HmiWorkplaceManifest.fetch(new URL(key));
|
||||
HmiWorkplaceManifest downloaded=HmiWorkplaceManifest.fetch(new URL(key), origin + "/mes");
|
||||
cachedManifest=downloaded;
|
||||
manifestKey=key;
|
||||
manifestLoaded=System.currentTimeMillis();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user