<?php

admin_init();

$pages = load_pages("rest");

echo "<h1>REST Links</h1>";

echo "<ul>\n";
foreach ($pages as $key => $page) {
  if ($key == "index")
    continue;
    
  echo "<li><a href='?q=" . $key . "'>" . $key . "</a></li>\n";
}
echo "</ul>\n";

?>

<br/>

<h2>Writing a custom REST page</h2>

<p>To gather custom JMX data, you'll create a custom REST page, which
is just a PHP page accessing JMX.  The page has the extension .rest
and can be named whatever you like, e.g. mypage.rest.  Put the 
my-app.rest page in WEB-INF/php/mypage.rest.</p>

<h3>Location of mypage.rest</h3>

<p>The mypage.rest can be put directly in WEB-INF/php or in a custom 
location given by "resin_admin_ext_path.  We recommend using
resin_admin_ext_path so you can keep your extensions distinct from
Resin's standard pages.   The resin_admin_ext_path is configured
in the resin.xml like:</p>

<pre><code>
&lt;resin xmlns="http://caucho.com/ns/resin">
  ...

&lt;web-app id="/resin-admin" root-directory="${resin.root}/doc/admin">
  &lt;prologue>
    &lt;resin:set var="resin_admin_external" value="false"/>
    &lt;resin:set var="resin_admin_insecure" value="true"/>
    <b>&lt;resin:set var="resin_admin_ext_path"
               value="/var/www/admin/php"/></b>
 &lt;/prologue>
&lt;/web-app>
</code></pre>

<h3>mypage.rest sample code</h3>

<p>The code for a REST page will look like:</p>

<pre><code>
&lt;?php

header("Content-Type: text/plain; charset=utf-8");

$mbean_server = new MBeanServer();

$jvm_thread = $mbean_server->lookup("java.lang:type=Threading");

printf("JvmThreadCount: %d\n", $jvm_thread->ThreadCount);

?>
</code></pre>

<p>The $mbean_server is a Resin's PHP interface to Java JMX MBeanServer.
The <code>lookup($name)</code> method looks up a MBean by its
ObjectName.  The field reference is a JXM attribute.</p>

<?php
display_footer($g_page, $javascript);
?>
