<?php

admin_init();

$pages = load_pages("rest");

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

?>

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

<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.

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

<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>

<code><pre>
&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>
</pre></code>

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

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

<code><pre>
&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);

?>
</pre></code>

<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>
