1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
<?xml version="1.0" encoding="UTF-8"?>
<html><head><title>Remote Server Mode</title></head><body bgcolor="ffffff"><table cellspacing="10"><tr><td align="center"><a href="http://www.beanshell.org/"><img src="../images/homebutton.gif"/><br/>Home</a></td><td><a href="embeddedmode.html#Embedding_BeanShell_in_Your_Application"><img src="../images/backbutton.gif"/><br/>Back
</a></td><td align="center"><a href="contents.html"><img src="../images/upbutton.gif"/><br/>Contents</a></td><td align="center"><a href="servletmode.html#BshServlet_and_Servlet_Mode_Scripting"><img src="../images/forwardbutton.gif"/><br/>Next
</a></td></tr></table><h1>Remote Server Mode</h1>
<img src="../images/remotemode.gif"/>
<br CLEAR="ALL"/>
Remote server mode lets you access a BeanShell Interpreter inside of a
remote VM.
With remote server mode activated you can literally telnet into the running
application and type commands at the BeanShell shell prompt. Or, even better,
you can use any web browser to bring up a remote GUI console.
<p CLEAR="ALL"/>
<p CLEAR="ALL"/>
<center>
<table width="90%" border="1" cellpadding="5">
<tr><td>
<strong>Warning:</strong>
<br CLEAR="ALL"/>
<b>When activated remote server mode can provide unrestricted access
to all parts of your application and the host server. This mode should
not be used in production environments or anywhere that server security
is an issue.
</b>
</td></tr>
</table>
</center>
<p CLEAR="ALL"/>
To enable remote access simply issue the BeanShell server() command, specifying
a base port number:
<p/><center><table border="1" cellpadding="5" width="100%"><tr><td bgcolor="#dfdfdc"><pre>
server(1234);
// Httpd started on port: 1234
// Sessiond started on port: 1235
</pre></td></tr></table></center><p/>
At this point BeanShell will run two services: a tiny HTTP server on the
port you specified and the BeanShell telnet session server on the next port
(the port you specified + 1).
<p CLEAR="ALL"/>
<h2><a name="Web_Browser_Access">Web Browser Access</a></h2>
After starting the server you can connect your web browser to the port
you specified. BeanShell will respond by sending an HTML page offering
you a choice of the Swing based JConsole or the older AWTConsole. You
may choose whichever is appropriate for your web browser.
<p CLEAR="ALL"/>
You can skip this decision page by hitting one of the following URLs directly:
<table border="1" cellpadding="5">
<tr><td>http://<yourserver>:<port>/remote/jconsole.html</td><td>
Swing based JConsole page
</td></tr>
<tr><td>http://<yourserver>:<port>/remote/awtconsole.html</td><td>
Minmal (old) AWT based Console page
</td></tr>
</table>
The httpd server then serves the remote console applet.
When it starts you will have a BeanShell session that looks like the
regular console, but is connected to the remote BeanShell VM.
<p CLEAR="ALL"/>
<img src="../images/remoteconsole.gif"/>
<p CLEAR="ALL"/>
You can open as many sessions into that VM as you like in this way, but
note that unlike the BeanShell desktop environment -
<strong>
All remote sessions share the same global scope.
</strong>
You are effectively working in the same interpreter instance for all
connections. This is intended as a feature, as the primary usefulness of
this mode is for debugging. You can set variables and access components
across many sessions.
<p CLEAR="ALL"/>
<h2><a name="Example">Example</a></h2>
Let's look at a quick example of how you might start a remote session from
within your application:
<p/><center><table border="1" cellpadding="5" width="100%"><tr><td bgcolor="#dfdfdc"><pre>
// Java code
import bsh.Interpreter;
i = new Interpreter();
i.set( "myapp", this ); // Provide a reference to your app
i.set( "portnum", 1234 );
i.eval("setAccessibility(true)"); // turn off access restrictions
i.eval("server(portnum)");
</pre></td></tr></table></center><p/>
Here we have set up the interpreter instance just as we would to do any
other kind of scripting - passing in Java objects using set(). In this case
we passed a general reference to our application using 'this', as well.
We have turned on accessibility so that we can access private and protected
members of our classes (useful for debugging). Finally we start the server
on the desired port.
<h2><a name="Telnet_Access">Telnet Access</a></h2>
We mentioned earlier that BeanShell starts its telnet session server on
the port next to the HTTP port. You can use any telnet client to access
a BeanShell command line directly, in text only-mode, without the use of
a web browser.
<p/><center><table border="1" cellpadding="5" width="100%"><tr><td bgcolor="#dfdfdc"><pre>
telnet <myhost> <port+1>
</pre></td></tr></table></center><p/>
Note that this command line is not very friendly. In particular it does not
respond to gratuitous newlines with a new prompt (as the text only
Interpreter command line does).
<p CLEAR="ALL"/>
<em>
At the time of this writing there is no explicit way to close a session.
BeanShell will simply detect the end of streams.
</em>
<table cellspacing="10"><tr><td align="center"><a href="http://www.beanshell.org/"><img src="../images/homebutton.gif"/><br/>Home</a></td><td><a href="embeddedmode.html#Embedding_BeanShell_in_Your_Application"><img src="../images/backbutton.gif"/><br/>Back
</a></td><td align="center"><a href="contents.html"><img src="../images/upbutton.gif"/><br/>Contents</a></td><td align="center"><a href="servletmode.html#BshServlet_and_Servlet_Mode_Scripting"><img src="../images/forwardbutton.gif"/><br/>Next
</a></td></tr></table></body></html>
|