1 25 package org.ofbiz.base.container; 26 27 import bsh.Interpreter; 28 import bsh.EvalError; 29 30 import org.ofbiz.base.util.Debug; 31 32 39 public class BeanShellContainer implements Container { 40 41 public static final String module = BeanShellContainer.class.getName(); 42 43 protected String configFileLocation = null; 44 protected Interpreter bsh = null; 45 protected String name; 46 protected int port; 47 48 51 public void init(String [] args, String configFile) { 52 this.configFileLocation = configFile; 53 } 54 55 58 public boolean start() throws ContainerException { 59 ContainerConfig.Container cfg = ContainerConfig.getContainer("beanshell-container", configFileLocation); 61 62 ContainerConfig.Container.Property appName = cfg.getProperty("app-name"); 64 if (appName == null || appName.value == null || appName.value.length() == 0) { 65 throw new ContainerException("Invalid app-name defined in container configuration"); 66 } else { 67 this.name = appName.value; 68 } 69 70 ContainerConfig.Container.Property telnetPort = cfg.getProperty("telnet-port"); 72 if (telnetPort == null || telnetPort.value == null || telnetPort.value.length() == 0) { 73 throw new ContainerException("Invalid telnet-port defined in container configuration"); 74 } else { 75 try { 76 this.port = Integer.parseInt(telnetPort.value); 77 } catch (Exception e) { 78 throw new ContainerException("Invalid telnet-port defined in container configuration; not a valid int"); 79 } 80 } 81 82 bsh = new Interpreter(); 84 85 if (bsh != null) { 87 try { 88 bsh.set(name, this); 89 } catch (EvalError evalError) { 90 throw new ContainerException(evalError); 91 } 92 try { 93 bsh.set("portnum", (port - 1)); 94 } catch (EvalError evalError) { 95 throw new ContainerException(evalError); 96 } 97 try { 98 bsh.eval("setAccessibility(true)"); 99 } catch (EvalError evalError) { 100 throw new ContainerException(evalError); 101 } 102 103 try { 104 bsh.eval("server(portnum)"); 105 } catch (EvalError evalError) { 106 throw new ContainerException(evalError); 107 } 108 109 Debug.logInfo("Started BeanShell telnet service on " + (port - 1) + ", " + port, module); 110 Debug.logInfo("NOTICE: BeanShell service ports are not secure. Please protect the ports", module); 111 return true; 112 } else { 113 return false; 114 } 115 } 116 117 123 public void stop() throws ContainerException { 124 bsh = null; 125 } 126 } 127 | Popular Tags |