Enterprise Server provides representational state transfer (REST) interfaces to enable you to access monitoring and configuration data for Enterprise Server, including data that is provided by newly installed add-on components.
You can access the Enterprise Server REST interfaces through client applications such as:
You can also use the Enterprise Server REST interfaces in REST client applications that are developed in languages such as:
JavaScript
Ruby
Perl
Java
JavaFX
The implementation of the Enterprise Server REST interfaces is based on project Jersey. Project Jersey is the reference implementation of Java TM Specification Request (JSR) 311: JAX-RS: The Java API for RESTful Web Services. Information about JSR 311 is also available from the JSR 311 project home page.
The following topics are addressed here:
Each node in the configuration and monitoring object trees is represented as a REST resource that is accessible through an HTTP uniform resource locator (URL). Access to REST resources for Enterprise Server monitoring and configuration data requires a running DAS.
The formats of the URLs to resources that represent nodes in the configuration and monitoring object trees are as follows:
Configuration: http://host:port/management/domain/path
Monitoring: http://host:port/monitoring/domain/path
The replaceable items in these URLs are as follows:
The host where the DAS is running.
The HTTP port or HTTPS port for administration.
The path to the node. The path is the dotted name of the node in which each dot (.) is replaced with a slash (/). For more information, see the following documentation:
If the URL to a REST resource for Enterprise Server monitoring or configuration data is opened in a web browser, the browser displays a web page that contains the following information about the resource:
A list of the attributes of the resource and their values. If the resource represents a node in the configuration tree, these attributes are presented in an HTML form that you can use to update the resource. Attributes of a resource for a node in the monitoring tree are read only.
A list of hypertext links to the children of the resource. This list of links enables you to traverse the tree that contains the resource and to discover the all resources in the tree.
The following figure shows the web page for the REST resource for managing a domain.
The Enterprise Server REST interfaces support methods for accessing nodes in the monitoring and configuration object trees.
The following table shows the REST methods for administering monitoring and configuration data and the tasks that you can perform with each method. These methods are HTTP 1.1 primitives. For the detailed specification of these primitives, see Hypertext Transfer Protocol -- HTTP/1.1.
Table 2–1 REST Resource Methods for Administering Monitoring and Configuration Data
Task |
REST Method |
---|---|
Determine the methods and method parameters that a node in the tree supports |
OPTIONS or GET |
Retrieve data for a node in the tree |
GET |
Add a node to the tree |
POST |
Update a node in the tree |
POST |
Delete a node from the tree |
DELETE |
The GET method can be used instead of the OPTIONS method to determine the methods and method parameters that a node in the tree supports. The GET method also provides additional information about the node. For details, see To Retrieve Data for a Node in the Tree.
The methods and method parameters that a node in the tree supports depend on the REST resource that represents the node:
REST resources for monitoring support only the GET method.
All REST resources for configuration support the GET method and the OPTIONS method. However, only some REST resources for configuration also support the POST method and the DELETE method.
Before performing any operations on a node in the tree, determine the methods and method parameters that the node supports.
You can specify the format in which this information is presented. For more information, see Formats for Resource Representation.
Ensure that the server is running.
Operations on REST resources for Enterprise Server data require a running server.
Use the appropriate method on the REST resource that represents the node.
If the node is in the monitoring object tree, use the GET method.
If the node is in the configuration object tree, use the OPTIONS method or the GET method.
The GET method and the OPTIONS method return the list of methods that the resource supports. For each method, the list of acceptable message parameters or the list of acceptable query parameters are returned.
This example uses the cURL utility to determine the methods and method parameters that the resource for the domain supports. The example uses the following options of the cURL utility:
-X to specify that the OPTIONS method is used
-H to specify that the resource is represented in JavaScript Object Notation (JSON)
In this example, the DAS is running on the local host and the HTTP port for administration is 4848. In addition to the OPTIONS method, the resource supports the POST method and the GET method.
curl -X OPTIONS -H "Accept: application/json" http://localhost:4848/management/domain {"Domain": { "Method":{ "Name":"POST", "Message Parameters":{ "log-root":{"Key":"false", "Type":"string", "Optional":"true"}, "application-root":{"Key":"false", "Type":"string", "Optional":"true"}, "locale":{"Key":"false", "Type":"string", "Optional":"true"}, "version":{"Key":"false", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" } } } |
Retrieving data for a node in the tree obtains the following information about the REST resource that represents the node:
A list of the REST methods that the resource supports
A list of the attributes of the resource and their values
A list of URLs to the children of the resource
You can specify the format in which this information is presented. For more information, see Formats for Resource Representation.
Ensure that the server is running.
Operations on REST resources for Enterprise Server data require a running server.
Use the GET method on the REST resource that represents the node.
This example uses the cURL utility to retrieve data for the resource for a domain. The example uses the following options of the cURL utility:
-X to specify that the GET method is used
-H to specify that the resource is represented in JavaScript Object Notation (JSON)
In this example, the DAS is running on the local host and the HTTP port for administration is 4848.
Line breaks are added to enhance readability.
curl -X GET -H "Accept: application/json" http://localhost:4848/management/domain { "Domain":{"log-root":"${com.sun.aas.instanceRoot}/logs", "application-root":"${com.sun.aas.instanceRoot}/applications", "locale":"", "version":"74.1"}, "Methods":{ "Method":{ "Name":"POST", "Message Parameters":{ "log-root":{"Key":"false", "Type":"string", "Optional":"true"}, "application-root":{"Key":"false", "Type":"string", "Optional":"true"}, "locale":{"Key":"false", "Type":"string", "Optional":"true"}, "version":{"Key":"false", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" } }, "Child Resources":[ "http://localhost:4848/management/domain/configs", "http://localhost:4848/management/domain/resources", "http://localhost:4848/management/domain/servers", "http://localhost:4848/management/domain/property", "http://localhost:4848/management/domain/applications", "http://localhost:4848/management/domain/system-applications", "http://localhost:4848/management/domain/stop", "http://localhost:4848/management/domain/restart", "http://localhost:4848/management/domain/uptime", "http://localhost:4848/management/domain/version", "http://localhost:4848/management/domain/rotate-log", "http://localhost:4848/management/domain/host-port" ] |
Ensure that the server is running.
Operations on REST resources for Enterprise Server data require a running server.
Determine the acceptable message parameters for the POST method of the resource that represents the parent of the node.
For information about how to perform this step, see To Determine the Methods and Method Parameters That a Node in the Tree Supports.
Use the POST method on the REST resource that represents the parent of the node that you are adding.
Confirm that the node has been added.
Perform this step on the resource that represents the node that you have just added, not the parent. For information about how to perform this step, see To Retrieve Data for a Node in the Tree.
This example uses the cURL utility to add a JDBC resource node to the tree by creating a REST resource to represent the JDBC resource.
In this example, the DAS is running on the local host and the HTTP port for administration is 4848.
Line breaks are added to enhance readability.
This step determines the acceptable message parameters for the POST method of the resource jdbc-resource.
curl -X OPTIONS -H "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc-resource {"JdbcResource": { "Method":{ "Name":"POST", "Message Parameters":{ "id":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"false"}, "enabled":{"Acceptable Values":"", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "description":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "property":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "connectionpoolid":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"false"} } }, "Method":{ "Name":"GET" } } } |
This step adds a resource as a child of the jdbc-resource resource. The -d option of the cURL utility sets the required message parameters as follows:
id is set to jdbc/myjdbcresource.
connectionpoolid is set to DerbyPool.
curl -X POST -d "id=jdbc/myjdbcresource&connectionpoolid=DerbyPool" http://localhost:4848/management/domain/resources/jdbc-resource "http://localhost:4848/management/domain/resources/jdbc-resource/ jdbc/myjdbcresource" created successfully. |
This step confirms that the node has been added by retrieving data for the REST resource that represents the node.
curl -X GET -H "Accept: application/json" http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource { "JdbcMyjdbcresource":{"enabled":"true", "pool-name":"DerbyPool", "description":"", "jndi-name":"jdbc/myjdbcresource", "object-type":"user"}, "Methods":{ "Method":{ "Name":"POST", "Message Parameters":{ "enabled":{"Key":"false", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "pool-name":{"Key":"false", "Type":"string", "Optional":"true"}, "description":{"Key":"false", "Type":"string", "Optional":"true"}, "jndi-name":{"Key":"true", "Type":"string", "Optional":"true"}, "object-type":{"Key":"false", "Default Value":"user", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" }, "Method":{ "Name":"DELETE", "Message Parameters":{ "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"} } } } } |
Ensure that the server is running.
Operations on REST resources for Enterprise Server data require a running server.
Determine the acceptable message parameters for the POST method of the resource that represents the node.
For information about how to perform this step, see To Determine the Methods and Method Parameters That a Node in the Tree Supports.
Use the POST method on the REST resource that represents the node that you are updating.
Confirm that the node has been updated.
For information about how to perform this step, see To Retrieve Data for a Node in the Tree.
This example uses the cURL utility to update a JDBC resource in the tree by modifying the REST resource that represents the JDBC resource.
In this example, the DAS is running on the local host and the HTTP port for administration is 4848.
Line breaks are added to enhance readability.
This step determines the acceptable message parameters for the POST method of the resource jdbc-myjdbcresource.
curl -X OPTIONS -H "Accept: application/json" http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource {"JdbcMyjdbcresource": { "Method":{ "Name":"POST", "Message Parameters":{ "enabled":{"Key":"false", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "pool-name":{"Key":"false", "Type":"string", "Optional":"true"}, "description":{"Key":"false", "Type":"string", "Optional":"true"}, "jndi-name":{"Key":"true", "Type":"string", "Optional":"true"}, "object-type":{"Key":"false", "Default Value":"user", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" }, "Method":{ "Name":"DELETE", "Message Parameters":{ "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"} } } } } |
This step updates the REST resource jdbc-myjdbcresource to disable the JDBC resource that jdbc-myjdbcresource represents. The -d option of the cURL utility sets the enabled message parameter to disabled.
curl -X POST -d "enabled=false" http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource "http://localhost:4848/management/domain/resources/jdbc-resource/ jdbc-myjdbcresource" updated successfully. |
This step confirms that the node has been updated by retrieving data for the REST resource that represents the node.
curl -X GET -H "Accept: application/json" http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource { "JdbcMyjdbcresource":{"enabled":"false", "pool-name":"DerbyPool", "description":"", "jndi-name":"jdbc/myjdbcresource", "object-type":"user"}, "Methods":{ "Method":{ "Name":"POST", "Message Parameters":{ "enabled":{"Key":"false", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "pool-name":{"Key":"false", "Type":"string", "Optional":"true"}, "description":{"Key":"false", "Type":"string", "Optional":"true"}, "jndi-name":{"Key":"true", "Type":"string", "Optional":"true"}, "object-type":{"Key":"false", "Default Value":"user", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" }, "Method":{ "Name":"DELETE", "Message Parameters":{ "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"} } } } } |
Ensure that the server is running.
Operations on REST resources for Enterprise Server data require a running server.
Confirm that the node can be deleted.
For information about how to perform this step, see To Determine the Methods and Method Parameters That a Node in the Tree Supports.
Confirm that the node has been deleted.
Perform this step on the resource that represents the parent of the node that you have just deleted. For information about how to perform this step, see To Retrieve Data for a Node in the Tree.
This example uses the cURL utility to delete a JDBC resource from the tree by deleting the REST resource that represents the JDBC resource.
In this example, the DAS is running on the local host and the HTTP port for administration is 4848.
Line breaks are added to enhance readability.
This step confirms that the node can be deleted by retrieving the REST methods that the resource jdbc-myjdbcresource supports.
curl -X OPTIONS -H "Accept: application/json" http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource {"JdbcMyjdbcresource": { "Method":{ "Name":"POST", "Message Parameters":{ "enabled":{"Key":"false", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "pool-name":{"Key":"false", "Type":"string", "Optional":"true"}, "description":{"Key":"false", "Type":"string", "Optional":"true"}, "jndi-name":{"Key":"true", "Type":"string", "Optional":"true"}, "object-type":{"Key":"false", "Default Value":"user", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" }, "Method":{ "Name":"DELETE", "Message Parameters":{ "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"} } } } } |
This step deletes the jdbc-myjdbcresource resource.
curl -X DELETE http://localhost:4848/management/domain/resources/ jdbc-resource/jdbc-myjdbcresource |
This step confirms that the node has been deleted by retrieving data for the REST resource that represents the parent of the node.
curl -X GET -H "Accept: application/json" http://localhost:4848/management/domain/resources/jdbc-resource/ { "JdbcResource":{}, "Methods":{ "Method":{ "Name":"POST", "Message Parameters":{ "id":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"false"}, "enabled":{"Acceptable Values":"", "Default Value":"true", "Type":"boolean", "Optional":"true"}, "description":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "target":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "property":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"true"}, "connectionpoolid":{"Acceptable Values":"", "Default Value":"", "Type":"string", "Optional":"false"} } }, "Method":{ "Name":"GET" } }, "Child Resources":[ "http://localhost:4848/management/domain/resources/jdbc-resource/ jdbc-__TimerPool", "http://localhost:4848/management/domain/resources/jdbc-resource/ jdbc-__default" ] |
The Enterprise Server REST interfaces also support operations other than create, read, update, and delete (CRUD) operations, for example:
State management
Queries
Application deployment
These operations are supported through child resources of the resource on which the operation is performed. The child resources do not represent nodes in the configuration object tree.
For example, the resource for managing a domain provides child resources for non-CRUD operations as shown in the following table.
Table 2–2 Child Resources for Non-CRUD Operations on a Domain
Resource |
Action |
---|---|
host-port |
Displays the host on which the DAS is running and the port on which the DAS listens for HTTP requests. |
restart |
Stops and then restarts the DAS of the domain. |
rotate-log |
Rotates the server log file by renaming the file with a timestamp name in the format server.log_date-and-time, and creating an empty log file. |
stop |
Stops the DAS of the domain. |
uptime |
Displays the length of time that the DAS has been running since it was last restarted. |
version |
Displays version information for Enterprise Server. |
The Enterprise Server REST interfaces support basic authentication over a secure connection. When security is enabled, you must specify https as the protocol in the URLs to REST resources and provide a username and password.
Securing Enterprise Server REST Interfaces involves the following sequence of tasks:
Adding an admin-realm user to the asadmin user group
Enabling Secure Sockets Layer (SSL)
For information about how to perform these tasks from the command line, see the following documentation:
For information about how to perform these tasks by using the Administration Console, see the following topics in the Administration Console online help:
To Add a User to the Admin Realm
To Edit SSL Settings for a Protocol
The Enterprise Server REST interfaces represent resources in the following formats:
XML
HTML
How to specify the resource representation depends on how you are accessing the Enterprise Server REST interfaces. For example, if you are using the cURL utility, specify the resource representation through the -H option as follows:
For JSON, specify -H "Accept: application/json".
For XML, specify -H "Accept: application/xml".
For HTML, omit the -H option.
The general format for the JSON representation of a resource is as follows:
{ "resource":{attributes}, "Methods": { method-list } "Child Resources":[urls] }
The replaceable items in this format are as follows:
The name of the resource.
Zero or more name-value pairs separated by a comma (,). Each name-value pair is specified as "name":value.
One or more metadata sets separated by a comma (,) that represent the methods that the resource supports. For the format of each metadata set, see JSON Representation of a Method in a Method List.
Zero or more URLs to child resources separated by a comma (,).
The JSON representation of a method in a method list is as follows:
Method":{ "Name":"method-name", "Message Parameters":{ message-parameter-list } "Query Parameters":{ queryparameter- list } }
The replaceable items in this format are as follows:
The name of the method, which is GET, POST, or DELETE.
Zero or more metadata sets separated by a comma (,) that represent the message parameters that are allowed for the method. For the format of each metadata set, see JSON Representation of a Message Parameter or a Query Parameter.
Zero or more metadata sets separated by a comma (,) that represent the query parameters that are allowed for the method. For the format of each metadata set, see JSON Representation of a Message Parameter or a Query Parameter.
The JSON representation of a message parameter or a query parameter is as follows:
"parameter-name":{attribute-list}
The replaceable items in this format are as follows:
The name of the parameter.
A comma-separated list of name-value pairs of attributes for the parameter. Each pair is in the following format:
"name":"value"
Possible attributes are as follows:
The default value of the parameter.
The set or range of acceptable values for the parameter.
The data type of the parameter, which is one of the following types:
boolean
int
string
Indicates whether the parameter is optional. If true, the parameter is optional. If false, the parameter is required.
Indicates whether the parameter is key. If true, the parameter is key. If false, the parameter is not key.
This example shows the JSON representation of the resource for managing a domain. In this example, the DAS is running on the local host and the HTTP port for administration is 4848. The URL to the resource in this example is http://localhost:4848/management/domain.
Line breaks are added to enhance readability.
{ "Domain":{"log-root":"${com.sun.aas.instanceRoot}/logs", "application-root":"${com.sun.aas.instanceRoot}/applications", "locale":"", "version":"73"}, "Methods":{ "Method":{ "Name":"POST", "Message Parameters":{ "log-root":{"Key":"false", "Type":"string", "Optional":"true"}, "application-root":{"Key":"false", "Type":"string", "Optional":"true"}, "locale":{"Key":"false", "Type":"string", "Optional":"true"}, "version":{"Key":"false", "Type":"string", "Optional":"true"} } }, "Method":{ "Name":"GET" } }, "Child Resources":[ "http://localhost:4848/management/domain/configs", "http://localhost:4848/management/domain/resources", "http://localhost:4848/management/domain/servers", "http://localhost:4848/management/domain/property", "http://localhost:4848/management/domain/applications", "http://localhost:4848/management/domain/system-applications", "http://localhost:4848/management/domain/stop", "http://localhost:4848/management/domain/restart", "http://localhost:4848/management/domain/uptime", "http://localhost:4848/management/domain/version", "http://localhost:4848/management/domain/rotate-log", "http://localhost:4848/management/domain/host-port" ] } |
The general format for the XML representation of a resource is as follows:
<resource attributes> <Methods> method-list </Methods> children </type>
The replaceable items in this format are as follows:
The name of the resource.
Zero or more name-value pairs separated by a space. Each name-value pair is specified as name="value".
One or more XML elements that represent the methods that the resource supports. For the format of each element, see XML Representation of a Resource Method.
Zero or more XML elements that specify the URLs of child resources. Each element is specified as <child-resource>url</child-resource>, where child-resource is the name of the child resource and url is the URL to the child resource.
The XML representation of a method in a method list is as follows:
<Method name="method-name"> <Message-Parameters> message-parameter-list </Message-Parameters> <Query-Parameters> query-parameter-list </Query-Parameters> </Method>
The replaceable items in this format are as follows:
The name of the method, which is GET, POST, or DELETE.
Zero or more XML elements separated by a line feed that represent the message parameters that are allowed for the method. For the format of each element, see XML Representation of a Message Parameter or a Query Parameter.
Zero or more XML elements separated by a line feed that represent the query parameters that are allowed for the method. For the format of each element, see XML Representation of a Message Parameter or a Query Parameter.
The XML representation of a message parameter or a query parameter is as follows:
<parameter-name attribute-list/>
The replaceable items in this format are as follows:
The name of the parameter.
A space-separated list of name-value pairs of attributes for the parameter. Each pair is in the following format:
name="value"
Possible attributes are as follows:
The default value of the parameter.
The set or range of acceptable values for the parameter.
The data type of the parameter, which is one of the following types:
boolean
int
string
Indicates whether the parameter is optional. If true, the parameter is optional. If false, the parameter is required.
Indicates whether the parameter is key. If true, the parameter is key. If false, the parameter is not key.
This example shows the XML representation of the resource for managing a domain. In this example, the DAS is running on the local host and the HTTP port for administration is 4848. The URL to the resource in this example is http://localhost:4848/management/domain.
Line breaks are added to enhance readability.
<Domain log-root="${com.sun.aas.instanceRoot}/logs" application-root="${com.sun.aas.instanceRoot}/applications" locale="" version="73"> <Methods> <Method name="POST"> <Message-Parameters> <log-root Key="false" Type="string" Optional="true"/> <application-root Key="false" Type="string" Optional="true"/> <locale Key="false" Type="string" Optional="true"/> <version Key="false" Type="string" Optional="true"/> </Message-Parameters> </Method> <Method name="GET"> </Method> </Methods> <Child-Resources> <Child-Resource>http://localhost:4848/management/domain/configs</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/resources</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/servers</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/property</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/applications</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/system-applications</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/stop</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/restart</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/uptime</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/version</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/rotate-log</Child-Resource> <Child-Resource>http://localhost:4848/management/domain/host-port</Child-Resource> </Child-Resources> </Domain> |
The format for the HTML representation of a resource is a web page that provides the following information about the resource:
A list of the attributes of the resource and their values.
A list of the methods and method parameters that the resource supports. Each method and its parameters are presented as a field of the appropriate type in an HTML form.
A list of hypertext links to the children of the resource.
For a sample web page, see Figure 2–1. In this example, the DAS is running on the local host and the HTTP port for administration is 4848. The URL to the resource in this example is http://localhost:4848/management/domain.