Zamples, Inc. logo
 Home   Search   Solutions   My Zamples   FAQ   News   Contact 
Zamples ID:
Password:
   
0 anonymous users;
16 users logged in.

Sandbox Discovery

Each Zamples server is configured by the administrator, who defines the language sandboxes and assigns a unique numeric ID and an alphanumeric language code to each language sandbox.  Before a client can execute a code example, it must specify the sandbox ID or sandbox code along with the code to be executed.  There are two types of queries with return the same information, but presented differently.  The plain text query is quick and easy to parse, but requires that you write a program for the returned data.  The XML query takes longer to parse, but many XML libraries will automatically parse the data and return a collection of objects.

There will always be at least three sandboxes defined because the HTML or JSP Fragment, Java Servlet Fragment and HTML and Applet sandboxes are hardwired.  All other sandboxes are defined in the Zamples sandbox configuration file (Zamples administrators know this as dispatch.properties).

Plain Text Query

You can easily discover the active sandboxes defined for a specific Zamples server by an HTTP GET or POST to /JspExplorer/zamples/discover/.  The results are returned as a text/plain page.  The default imports, cmd and applet lines are HTML encoded.  As with all Zamples REST calls, the common Zamples REST parameters must be specified.

In the following example, replace myUid with your Zamples user id and myPwd with your Zamples password.

<a href=/JspExplorer/zamples/discover?clientUser=myUid&clientPassword=myPwd>Discover</a> 
the Zamples language sandboxes on this Zamples server 
by clicking on the link.

Typical Output

The sections are color-coded for your convenience.

  1. Version number of the Zamples Client Specification that this Zamples server implements
  2. Number of active language sandboxes
  3. Language IDs
  4. Short form of the sandbox names
  5. Displayable names of the sandboxes
  6. Default values for imports (or command line parameters)
  7. Default values for cmd
  8. Default values for applet (usually ignored, except for applets)

You don't have to use all the languages in your client - discovery only shows you what you have to work with for that particular Zamples installation. The HTML-encoded lines of the last three sections of the following output have been truncated for clarity (default values for imports, cmd and applet.)

0.8beta4
8
0 2 3 10 15 20 25 4608
jsp javaFragment applet jdk14 jdk14cl jdk15 jdk15cl csharp
HTML or JSP Fragment Java Servlet Fragment HTML and Applet JDK 1.4 Fragment JDK 1.4 Class JDK 5.0 Fragment JDK 5.0 Class C# (Mono)
//&#32;Type&#32;the&#32;names&#32;of&#32;packages&#32;to&#32;be&#32;imported&#32;here,&#10;//&#32;... //&#32;Type&#32;the&#32;names&#32;of&#32;packages&#32;to&#32;be&#32;imported&#32;here,&#10;//&#32;...
//&#32;No&#32;imports&#32;are&#32;needed&#32;in&#32;a&#32;JSP&#32;that&#32;loads&#32;an&#32;applet
//&#32;Put&#32;import&#32;statements&#32;here
Zamples&#32;says&#32;it&#32;is&#32;now&#32;&lt;&#37;&#61;new&#32;java.util.Date()&#37;&gt;.
out.println(&quot;Zamples&#32;says&#32;it&#32;is&#32;now&#32;&quot;&#32;&#43;&#32;new&#32;java.util.Date());
&lt;!--&#32;Do&#32;not&#32;change&#32;the&#32;next&#32;three&#32;lines&#32;--&gt;&#10;&lt;APPLET&#10;&#32;&...
System.out.println(&quot;I&#32;love&#32;zamples!!!!&quot;);
//&#32;This&#32;is&#32;a&#32;text&#32;area&#32;for&#32;applet&#32;Java&#32;code.&#10;//&#32;Ignore&#32;this... //&#32;This&#32;is&#32;a&#32;text&#32;area&#32;for&#32;applet&#32;Java&#32;code.&#10;//&#32;Ignore&#32;this... //&#32;Do&#32;not&#32;change&#32;&lt;&#37;&#61;appletName()&#37;&gt;&#32;in&#32;the&#32;next&#32;line.&#10;... //&#32;This&#32;is&#32;a&#32;text&#32;area&#32;for&#32;applet&#32;Java&#32;code.&#10;//&#32;Ignore&#32;this...

The above output shows that eight language sandboxes are defined, as shown in this table:

Sandbox ID Sandbox Code Sandbox Name
0 jsp HTML or JSP Fragment
2 javaFragment Java Servlet Fragment
3 applet HTML and Applet
10 jdk14 JDK 1.4 Fragment
15 jdk14cl JDK 1.4 Class
20 jdk15 JDK 5.0 Fragment
25 jdk15cl JDK 5.0 Class
4608 csharp C# (Mono)

The third column above (Sandbox Name) is not stored with the code example, so your client may display something different, for example, you can display the Sandbox Name in a different language.

Some languages, such as Java, have two similarly named sandboxes - one that requires complete programs, and one that accepts code fragments and wraps them in a main() method.  Zamples convention is to indicate the sandboxes which require entire programs in 'cl'.  For example, JDK 1.4's sandboxes are called jdk14 (for code fragments) and jdk14cl for (entire programs).  Sandbox names are case sensitive.

XML Query

You can use REST to retrieve the same information in an XML format.  The results are returned as a application/xml; charset=UTF-8 page.  In the following example, replace myUid with your Zamples user id and myPwd with your Zamples password.

<a href=/JspExplorer/zamples/discoverRest?clientUser=myUid&clientPassword=myPwd>Discover</a> 
the Zamples language sandboxes on this Zamples server 
by clicking on the link.

Typical Output

For clarity, the default values for imports, cmd and applet are not shown.  These values are not encoded.

<?xml version="1.0"?>
<sandboxes number="8" version="0.8beta4">
   <sandbox id="0" code="jsp" name="HTML or JSP Fragment">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="2" code="javaFragment" name="Java Servlet Fragment">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="3" code="applet" name="HTML and Applet">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="10" code="jdk14" name="JDK 1.4 Fragment">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="15" code="jdk14cl" name="JDK 1.4 Class">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="20" code="jdk15" name="JDK 5.0 Fragment">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="25" code="jdk15cl" name="JDK 5.0 Class">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
   <sandbox id="4608" code="csharp" name="C# (Mono)">
       <defaultImports><![CDATA[...]]></defaultImports>
       <defaultCmd><![CDATA[...]]></defaultCmd>
       <defaultApplet><![CDATA[...]]></defaultApplet>
   </sandbox>
</sandboxes>

Standard Sandbox Definitions

Here are the standard definitions for language sandboxes.  Again, the default values for imports, cmd and applet are not shown.

Sandbox ID Sandbox Code Sandbox Name Default Imports Default Cmd Default Applet
0 jsp HTML or JSP Fragment not shown not shown not shown
2 javaFragment Java Servlet Fragment not shown not shown not shown
3 applet HTML and Applet not shown not shown not shown
10 jdk14 JDK 1.4 Fragment not shown not shown not shown
15 jdk14cl JDK 1.4 Class not shown not shown not shown
20 jdk15 JDK 5.0 Fragment not shown not shown not shown
25 jdk15cl JDK 5.0 Class not shown not shown not shown
30 jdk16 JDK 6.0 Fragment not shown not shown not shown
35 jdk16cl JDK 6.0 Class not shown not shown not shown
500 groovy Groovy not shown not shown not shown
512 perl Perl 5 not shown not shown not shown
1024 php PHP 4 not shown not shown not shown
1536 python Python 2.3 not shown not shown not shown
4608 csharp C# (Mono) not shown not shown not shown
5120 haskell Haskell (Hugs 98) not shown not shown not shown
5632 ruby Ruby 1.8 not shown not shown not shown
5635 eruby eRuby 1.8 not shown not shown not shown
6144 flex Flex not shown not shown not shown
6656 mbas VB.Net (Mono) not shown not shown not shown

Possible error messages

In addition to the common Zamples REST error status codes, this Zamples REST call can generate the following error statuses and messages:

506 Unspecified failure An unknown error occured when saving the code fragment


Controlling the Range of Lines Displayed for a Posting Zamples Client REST Interface Specification Execution of Arbitrary Code