REST Interface to Configure GlassFish
REST Interface to Configure GlassFish
In my earlier blog I talked about REST interface to monitor and manage
GlassFish.
We have seen how to monitor GlassFish using REST interface. Now, I
would like to demonstrate how we can manage (configure) GlassFish
through this interface. The url for management root resource
is
http://{host}
:{port}
/management/domain,
where {host} is the server host and {port} is the administration port.
 |
Lets access http://localhost:4848/management/domain
through browser. Here we are
addressing the management root resource, Domain, on my
local GlassFish v3 install using its REST url. Domain resource has some
attributes and children. By clicking through the child resource links
you can access the entire GlassFish configuration model.
So far we have seen how to read GlassFish
configuration using
browser. Using java client, we can
see how to write configuration. Through browser we were using
html
representations, whereas, with java client we will use JSON and XML
representations.
You can
download java client by clicking here.
Java client uses Jersey client API's
and we used this client earlier to demonstrate
GlassFish monitoring.
For example, lets create a new iiop listener. In this example, we will
use XML and JSON
representations interchangeably to demonstrate REST interface
support for these formats- |
Step 1. GET iiop listeners
rget
http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener "application/xml"
<IiopListener>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/orb-listener-1</child-resource>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/SSL</child-resource>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/SSL_MUTUALAUTH</child-resource>
</IiopListener> |
We see that three are three
iiop-listeners
available. How do I know
whether I can create a fourth one and if yes, how do I know what input
representation to use? Well, we can use OPTIONS method to query this.
Step 2. Get
OPTIONS for iiop listeners
roptions
http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener "application/json"
{
"Method":"POST",
"Message Parameters":{
"id":{"Acceptable Values":"","Default
Value":"",
"Type":"class java.lang.String","Optional":"false"},
"enabled":{"Acceptable
Values":"","Default Value":"true",
"Type":"class java.lang.Boolean","Optional":"true"},
"securityenabled":{"Acceptable
Values":"","Default Value":"false",
"Type":"class
java.lang.Boolean","Optional":"true"},
"iiopport":{"Acceptable
Values":"","Default Value":"1072",
"Type":"class
java.lang.String","Optional":"true"},
"listeneraddress":{"Acceptable
Values":"","Default Value":"",
"Type":"class
java.lang.String","Optional":"false"},
"target":{"Acceptable
Values":"","Default Value":"",
"Type":"class
java.lang.String","Optional":"true"},
"property":{"Acceptable
Values":"","Default Value":"",
"Type":"class
java.util.Properties","Optional":"true"}
}
"Method":"GET"
} |
For the meta-data,
id
and
listeeneraddress
are madatory parameters. To
create new
iiop-listener
we must, at least provide these two parameters.
Step 3. Create (POST) new iiop listener
rpost
http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener "{\"id\" :
\"my-new-listener\", \"listeneraddress\" : \"0.0.0.0\"}" "application/json"
201
"http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener/my-new-listener"
created successfully.
|
Step 4. GET iiop listeners
rget
http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener "application/xml"
<IiopListener>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/orb-listener-1</child-resource>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/SSL</child-resource>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/SSL_MUTUALAUTH</child-resource>
<child-resource>http://localhost:4848/management/domain/configs/config/
server-config/iiop-service/iiop-listener/my-new-listener</child-resource>
</IiopListener>
|
Now we see that the fourth iiop listener,
my-new-listener,
is available on the server.
Step 5. GET
iiop
listener,
my-new-listener
rget http://localhost:4848/management/domain/configs/config/server-config/
iiop-service/iiop-listener/my-new-listener "application/xml"
<IiopListener
id="my-new-listener"
port="1072" enabled="true" address="0.0.0.0"
security-enabled="false" lazy-init="false">
</IiopListener> |
Through
this example, above, we saw read, write of GlassFish configuration
through REST interface using different representations (HTML, JSON and
XML).
Posted at
05:31PM Aug 03, 2009
by rajeshwar in Sun |
Hi Rajeshwar. On my browser/platform configuration (Firefox/MacOS), these entries look very skinny in the "single page" format. They look OK when going through the base weblog format, though.
Compare [1] and [2].
[1]http://blogs.sun.com/aquatic/entry/rest_interface_to_configure_glassfish
[2]http://blogs.sun.com/aquatic
Posted by Eduardo Pelegri-Llopart on August 07, 2009 at 12:11 PM PDT #