Author: jleroux
Date: Sun Jan 23 17:58:43 2011
New Revision: 1062476
URL: http://svn.apache.org/viewvc?rev=1062476&view=rev
Log:
A patch from René Scheibe "Groovy shell."
(https://issues.apache.org/jira/browse/OFBIZ-3954) - OFBIZ-3954
A Groovysh container to connect to. Just do a 'telnet localhost 9991' and you
have a fully fledged groovysh.
This is a Groovy equivalent to the already existing BeanShell container.
Added:
ofbiz/trunk/framework/base/lib/scripting/jansi-1.2.1.jar (with props)
ofbiz/trunk/framework/base/lib/scripting/jline-0.9.94.jar (with props)
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
(with props)
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
(with props)
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
(with props)
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
(with props)
Modified:
ofbiz/trunk/LICENSE
ofbiz/trunk/NOTICE
ofbiz/trunk/framework/base/config/ofbiz-containers.xml
Modified: ofbiz/trunk/LICENSE
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=1062476&r1=1062475&r2=1062476&view=diff
==============================================================================
--- ofbiz/trunk/LICENSE (original)
+++ ofbiz/trunk/LICENSE Sun Jan 23 17:58:43 2011
@@ -68,6 +68,7 @@ ofbiz/trunk/framework/base/lib/j2eespecs
ofbiz/trunk/framework/base/lib/scripting/bsf-2.4.0.jar
ofbiz/trunk/framework/base/lib/scripting/jakarta-oro-2.0.8.jar
ofbiz/trunk/framework/base/lib/scripting/groovy-all-1.7.4.jar
+ofbiz/trunk/framework/base/lib/scripting/jansi-1.2.1.jar
ofbiz/trunk/framework/base/lib/xmlrpc-client-3.1.2.jar
ofbiz/trunk/framework/base/lib/xmlrpc-common-3.1.2.jar
ofbiz/trunk/framework/base/lib/xmlrpc-server-3.1.2.jar
@@ -498,6 +499,7 @@ ofbiz/trunk/framework/base/lib/scripting
ofbiz/trunk/framework/base/lib/scripting/asm-tree-3.2.jar
ofbiz/trunk/framework/base/lib/scripting/asm-util-3.2.jar
ofbiz/trunk/framework/base/lib/scripting/janino-2.5.15.jar
+ofbiz/trunk/framework/base/lib/scripting/jline-0.9.94.jar
ofbiz/trunk/specialpurpose/ldap/lib/cas-server-core-3.3.jar
ofbiz/trunk/specialpurpose/pos/lib/looks-2.0.2.jar
Modified: ofbiz/trunk/NOTICE
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/NOTICE?rev=1062476&r1=1062475&r2=1062476&view=diff
==============================================================================
--- ofbiz/trunk/NOTICE (original)
+++ ofbiz/trunk/NOTICE Sun Jan 23 17:58:43 2011
@@ -339,3 +339,9 @@ This product includes software developed
This product includes software developed by the Indiana University
Extreme! Lab (http://www.extreme.indiana.edu/).
+=========================================================================
+== jline Notice ==
+=========================================================================
+
+This product includes software developed by Marc Prud'hommeaux
+<[email protected]>
Modified: ofbiz/trunk/framework/base/config/ofbiz-containers.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/config/ofbiz-containers.xml?rev=1062476&r1=1062475&r2=1062476&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/config/ofbiz-containers.xml (original)
+++ ofbiz/trunk/framework/base/config/ofbiz-containers.xml Sun Jan 23 17:58:43
2011
@@ -268,4 +268,9 @@ under the License.
<property name="telnet-port" value="9990"/>
<property name="app-name" value="OFBiz"/>
</container>
+
+ <!-- load Groovy remote telnet server -->
+ <container name="groovyshell-container"
class="org.ofbiz.base.container.GroovyShellContainer">
+ <property name="telnet-port" value="9991"/>
+ </container>
</ofbiz-containers>
Added: ofbiz/trunk/framework/base/lib/scripting/jansi-1.2.1.jar
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/scripting/jansi-1.2.1.jar?rev=1062476&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/scripting/jansi-1.2.1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: ofbiz/trunk/framework/base/lib/scripting/jline-0.9.94.jar
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/scripting/jline-0.9.94.jar?rev=1062476&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/scripting/jline-0.9.94.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java?rev=1062476&view=auto
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
(added)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
Sun Jan 23 17:58:43 2011
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
*******************************************************************************/
+package org.ofbiz.base.container;
+
+import org.apache.log4j.Logger;
+
+import org.ofbiz.base.container.ContainerConfig.Container.Property;
+import org.ofbiz.base.container.groovy.GroovyService;
+import org.ofbiz.base.container.groovy.GroovyShellService;
+
+public class GroovyShellContainer implements Container {
+
+ private static final Logger log =
Logger.getLogger(GroovyShellContainer.class);
+
+ private String configFileLocation = null;
+ private GroovyService gsh = null;
+
+ /**
+ * @see org.ofbiz.base.container.Container#init(java.lang.String[],
java.lang.String)
+ */
+ @Override
+ public void init(String[] args, String configFile) {
+ configFileLocation = configFile;
+ }
+
+ /**
+ * @see org.ofbiz.base.container.Container#start()
+ */
+ @Override
+ public boolean start() throws ContainerException {
+ int port = getTelnetPort();
+ gsh = new GroovyShellService(port);
+ gsh.launchInBackground();
+
+ log.info("Started Groovy telnet service on port [" + port + "].");
+ log.info("NOTICE: The Groovy service port is not secure. Please
protect it.");
+
+ return true;
+ }
+
+ /**
+ * @see org.ofbiz.base.container.Container#stop()
+ */
+ @Override
+ public void stop() throws ContainerException {
+ gsh = null;
+ }
+
+ private int getTelnetPort() throws ContainerException {
+ ContainerConfig.Container config =
ContainerConfig.getContainer("groovyshell-container", configFileLocation);
+ Property telnetPort = config.getProperty("telnet-port");
+ try {
+ return Integer.parseInt(telnetPort.value);
+ } catch (NumberFormatException e) {
+ throw new ContainerException("Invalid telnet port [" +
telnetPort.value + "] defined in container configuration.");
+ }
+ }
+}
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/GroovyShellContainer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java?rev=1062476&view=auto
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
(added)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
Sun Jan 23 17:58:43 2011
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2007 Bruce Fancher
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file is a modified version of the original one.
+ */
+
+package org.ofbiz.base.container.groovy;
+
+import groovy.lang.Binding;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+public abstract class GroovyService {
+
+ protected Logger log = Logger.getLogger(getClass());
+
+ private Map<String, Object> bindings;
+ private boolean launchAtStart;
+ private Thread serverThread;
+
+ public GroovyService() {
+ }
+
+ public GroovyService(Map<String, Object> bindings) {
+ this.bindings = bindings;
+ }
+
+ public void launchInBackground() {
+ serverThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ launch();
+ } catch (Exception e) {
+ log.error("Could not launch the Groovy service.", e);
+ }
+ }
+ };
+
+ serverThread.setDaemon(true);
+ serverThread.start();
+ }
+
+ public abstract void launch();
+
+ protected Binding createBinding() {
+ return new Binding(bindings);
+ }
+
+ public void initialize() {
+ if (launchAtStart) {
+ launchInBackground();
+ }
+ }
+
+ public void destroy() {}
+
+ public void setBindings(final Map<String, Object> bindings) {
+ this.bindings = bindings;
+ }
+
+ public boolean isLaunchAtStart() {
+ return launchAtStart;
+ }
+
+ public void setLaunchAtStart(boolean launchAtStart) {
+ this.launchAtStart = launchAtStart;
+ }
+}
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java?rev=1062476&view=auto
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
(added)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
Sun Jan 23 17:58:43 2011
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2007 Bruce Fancher
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file is a modified version of the original one.
+ */
+
+package org.ofbiz.base.container.groovy;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class GroovyShellService extends GroovyService {
+
+ private ServerSocket serverSocket;
+ private int port;
+ private List<Socket> clientSockets = new ArrayList<Socket>();
+
+ public GroovyShellService() {
+ super();
+ }
+
+ public GroovyShellService(int port) {
+ super();
+ this.port = port;
+ }
+
+ public GroovyShellService(Map<String, Object> bindings, int port) {
+ super(bindings);
+ this.port = port;
+ }
+
+ @Override
+ public void launch() {
+ try {
+ serverSocket = new ServerSocket(port);
+ log.info("Opened server socket: " + serverSocket);
+
+ acceptClientConnections();
+ } catch (IOException e) {
+ log.error("Could not open server socket.", e);
+ } finally {
+ closeServerSocket();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ closeServerSocket();
+
+ for (Socket clientSocket : clientSockets) {
+ closeClientSocket(clientSocket);
+ }
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ private void acceptClientConnections() {
+ while (true) {
+ Socket clientSocket = null;
+ try {
+ clientSocket = serverSocket.accept();
+ log.info("Opened client socket: " + clientSocket);
+ } catch (IOException e) {
+ log.error("Could not open client socket.", e);
+ continue;
+ }
+
+ clientSockets.add(clientSocket);
+ GroovyShellThread clientThread = new
GroovyShellThread(clientSocket, createBinding());
+ clientThread.start();
+ }
+ }
+
+ private void closeServerSocket() {
+ try {
+ if (serverSocket != null) {
+ log.info("Closing server socket: " + serverSocket);
+ serverSocket.close();
+ }
+ } catch (IOException e) {
+ log.error("Could not close server socket: " + serverSocket, e);
+ }
+ }
+
+ private void closeClientSocket(Socket socket) {
+ try {
+ if (socket != null) {
+ log.info("Closing client socket: " + socket);
+ socket.close();
+ }
+ } catch (IOException e) {
+ log.error("Could not close client socket: " + socket, e);
+ }
+ }
+}
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java?rev=1062476&view=auto
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
(added)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
Sun Jan 23 17:58:43 2011
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2007 Bruce Fancher
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file is a modified version of the original one.
+ */
+
+package org.ofbiz.base.container.groovy;
+
+import groovy.lang.Binding;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.net.Socket;
+
+import org.apache.log4j.Logger;
+import org.codehaus.groovy.tools.shell.Groovysh;
+import org.codehaus.groovy.tools.shell.IO;
+
+public class GroovyShellThread extends Thread {
+
+ private static final Logger log =
Logger.getLogger(GroovyShellThread.class);
+
+ private Socket socket;
+ private Binding binding;
+
+ public GroovyShellThread(Socket socket, Binding binding) {
+ super();
+ this.socket = socket;
+ this.binding = binding;
+ }
+
+ @Override
+ public void run() {
+ PrintStream out = null;
+ InputStream in = null;
+
+ try {
+ in = socket.getInputStream();
+ out = new PrintStream(socket.getOutputStream());
+ binding.setVariable("out", out);
+
+ final IO io = new IO(in, out, out);
+ final Groovysh gsh = new Groovysh(binding, io);
+ gsh.run();
+ } catch (Exception e) {
+ log.error("Error running the Groovy shell.", e);
+ } finally {
+ try { if (out != null) out.close(); } catch (Exception e) {}
+ try { if (in != null) in.close(); } catch (Exception e) {}
+ try { if (socket != null) socket.close(); } catch (Exception e) {}
+ }
+ }
+
+ public Socket getSocket() {
+ return socket;
+ }
+}
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/trunk/framework/base/src/org/ofbiz/base/container/groovy/GroovyShellThread.java
------------------------------------------------------------------------------
svn:mime-type = text/plain