Questo contenuto non è disponibile nella lingua selezionata.

6.3. Creating a New Module Source Type


JBoss ON can load a CommonJS script module from different locations, including both local directories and remote repositories.
It is possible to create support for loading modules from a different source, such as a URL. Creating a new module source location requires three things:
  • Creating a new ScriptSourceProvider interface.
  • Adding the Java service entry in the META-INF/services directory of a JAR for the class.
  • Putting the new JAR into the lib/ directory of the CLI installation directory to be available to clients and in serverRoot/jon-server-3.3/modules/org/rhq/server-startup/main/deployments/rhq.ear/lib on the JBoss ON server so that it is available to server-side scripts (alert scripts).

Example 6.1. HTTP Module Source Location

This script source provider downloads a script module from a given URI as long as the Java version supports HTTP or HTTPS protocols.
  public class URLScriptSourceProvider implements ScriptSourceProvider {
  public Reader getScriptSource(URI scriptUri) {
  if (scriptUri == null) {
  return null;
  }
  try {
  return new InputStreamReader(scriptUri.toURL().openStream())
  } 
  catch (MalformedURLException e) {
  return null;
  } 
  catch (IOException e) {
  return null;
  }
  }
}
Copy to Clipboard Toggle word wrap
In the META-INF directory of the script provider JAR, create a services directory.
Then, within the META-INF/services/ directory, create a file called org.rhq.scripting.ScriptSourceProvider. Put the full class names of any source providers implemented in the JAR, one per line. For example, if the URLScriptSourceProvider is the only source provider:
com.example.URLScriptSourceProvider
Copy to Clipboard Toggle word wrap
This is the layout of the JAR:
* com
* example 
* URLScriptSourceProvider.class
* META-INF 
* services 
* org.rhq.scripting.ScriptSourceProvider
Copy to Clipboard Toggle word wrap
This JAR must then ba added to the lib of the CLI installation directory. After that, scripts run through the JBoss ON CLI on that system can use the HTTP provider to download the file from the network:
var myModule = require("http://server.example.com/rhq-scripts/stuff.js");
Copy to Clipboard Toggle word wrap
For the same source provider to be available to alert scripts, the JAR needs to be added to the modules/org/rhq/server-startup/main/deployments/rhq.ear/lib/ directory of the JBoss ON server.
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2025 Red Hat