6 Monitoring RESTful Web Services

This chapter describes how to monitor WebLogic Web services that conform to the Representational State Transfer (REST) architectural style using Java API for RESTful Web Services (JAX-RS).

This chapter includes the following sections:

About Monitoring RESTful Web Services

To monitor your RESTful Web services, you can use one of the methods defined in Table 6-1.

Table 6-1 Methods for Monitoring RESTful Web Services

Method More Information

Use the WebLogic Scripting Tool (WLST) command-line scripting environment to access run-time information and monitor run-time statistics.

Monitoring RESTful Web Services Using WLST

Enable the logging filter to monitor how a request is processed and dispatched to Jersey JAX-RS RI components.

Enabling the Tracing Feature


Monitoring RESTful Web Services Using WLST

WebLogic Server provides several run-time MBeans, including those defined in Table 6-2, that capture run-time information and let you monitor run-time statistics for your RESTful Web service applications.

Table 6-2 Run-time MBeans for Monitoring RESTful Web Services

Run-time MBean Description

JaxRsApplication

Displays monitoring information for the RESTful Web service application. For more information, see "JaxRsApplicationRuntimeBean" in the WebLogic Server MBean Reference.

ResourceConfig

Displays monitoring information about the RESTful Web service application resource configuration. For more information, see "JaxRsResourceConfigTypeRuntimeBean" in the WebLogic Server MBean Reference.

RootResources

Displays monitoring information about the RESTful Web service resource. Any object that is managed by a container (such as EJB) will have application scope. All other resources by default will have request scope. For more information, see "JaxRsResourceRuntimeBean" in the WebLogic Server MBean Reference.

Servlet

Displays monitoring information for the servlet that hosts the RESTful Web service application. For more information, see "ServletRuntimeMBean" in the WebLogic Server MBean Reference.


To monitor RESTful Web services using WLST, perform the steps provided in the following procedure.

In this procedure, the example steps provided demonstrate how to monitor the RESTful Web Services sample delivered with the WebLogic Server Samples Server, described at "Sample Application and Code Examples" in Understanding Oracle WebLogic Server

  1. Invoke WLST, as described in "Invoking WLST" in Oracle WebLogic Scripting Tool.

    For example:

    c:\> java weblogic.WLST
    
  2. Connect to the Administration Server instance, as described in "connect" in WebLogic Scripting Tool Command Reference.

    For example:

    wls:/offline> connect('weblogic','welcome1','t3://localhost:8001') 
    
  3. Navigate to the server run-time MBean, as described in "serverRuntime" in WebLogic Scripting Tool Command Reference.

    For example:

    wls:/wl_server/serverConfig> serverRuntimes()
    Location changed to serverRuntime tree. This is a read-only tree
    with ServerRuntimeMBean as the root.
    For more help, use help('serverRuntime')
    wls:/wl_server/serverRuntime> 
    
  4. Navigate to the Web application component run-time MBean.

    For example:

    wls:/wl_server/serverRuntime> cd('ApplicationRuntimes/jaxrs')
    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs> cd('ComponentRuntimes')
    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs/ComponentRuntimes> cd('examplesServer_/jaxrs')
    
  5. Navigate to the application run-time MBean for the RESTful Web service servlet.

    For example:

    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs/ComponentRuntimes/examplesServer_/jaxrs> cd('JaxRsApplications/RestServlet')
    
  6. Review the monitoring information displayed for the RESTful Web service application. For more information, see "JaxRsApplicationRuntimeBean" in the WebLogic Server MBean Reference.

    For example:

    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs/ComponentRuntimes/example
    sServer_/jaxrs/JaxRsApplications/RestServlet> ls()
    dr--   ResourceConfig
    dr--   RootResources
    dr--   Servlet
     
    -r--   ErrorCount                                   0
    -r--   ExecutionTimeAverage                         0
    -r--   ExecutionTimeHigh                            0
    -r--   ExecutionTimeLow                             0
    -r--   ExecutionTimeTotal                           0
    -r--   HttpMethodCounts                             {}
    -r--   InvocationCount                              0
    -r--   LastErrorDetails                             null
    -r--   LastErrorMapper                              null
    -r--   LastErrorTime                                0
    -r--   LastHttpMethod                               null
    -r--   LastInvocationTime                           0
    -r--   LastResponseCode                             -1
    -r--   Name                                         RestServlet
    -r--   ResponseCodeCounts                           {}
    -r--   StartTime                                    1321907929703
    -r--   Type                                         JaxRsApplicationRuntime
     
    -r-x   preDeregister                                Void :
    
    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs/ComponentRuntimes/example
    sServer_/jaxrs/JaxRsApplications/RestServlet>
    
  7. Navigate to any of the following run-time MBeans to view additional monitoring information. For more information about the MBeans, see Table 6-2 or the WebLogic Server MBean Reference.

    • ResourceConfig

    • RootResources

    • Servlet

  8. Exit WLST, as described in "Exiting WLST" in Oracle WebLogic Scripting Tool.

    For example:

    wls:/wl_server/serverRuntime/ApplicationRuntimes/jaxrs/ComponentRuntimes/example
    sServer_/jaxrs/JaxRsApplications/RestServlet> exit()
    Exiting WebLogic Scripting Tool ...
    c:\>
    

Enabling the Tracing Feature

The Jersey tracing feature provides useful information that describes how a request is processed and dispatched to Jersey JAX-RS RI components. Trace messages are output in the same order as they occur, so the numbering is useful to reconstruct the tracing order.

The following provides an example of a trace message. The message shows the request path and the initial set of regular expressions that will be matched, in order from left to right.

Example 6-1 Example of a Trace Message

Trace 001:
X-Jersey-Trace-001  match path "/items/3/tracks/2/" -> "/application\\.wadl(/.\*)?", "/happy(/.\*)?", "(/.\*)?"

You can enable this feature server-wide or on a per-request basis, as described in the following sections:

How to Enable Server-wide Tracing

To enable server-wide tracing:

  • Update the web.xml deployment descriptor that is packaged with your application to add the following <init-param> element:

    <init-param>
        <param-name>com.sun.jersey.config.feature.Trace</param-name>
        <param-value>true</param-value>
    </init-param>
    

    For more information about the <init-param> element, see "servlet" in Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server.

  • Enable the com.sun.jersey.api.core.ResourceConfig.FEATURE_TRACE property. For more information, see http://jersey.java.net/nonav/apidocs/1.9/jersey/com/sun/jersey/api/core/ResourceConfig.html#FEATURE_TRACE.

How to Enable Per-request Tracing

With per-request tracing, trace messages are output if a request header is present with the header name of X-Jersey-Trace-Accept.

Trace messages are output primarily as response headers with a header name of the form X-Jersey-Trace-XXX, where XXX is a decimal value corresponding to the trace message number, and a header value that is the trace message. In certain cases, trace messages will be logged to the server if they cannot be included in the response headers, for example if the messages are too long.

To enable tracing on a per-request basis:

  • Update the web.xml deployment descriptor that is packaged with your application to add the following <init-param> element:

    <init-param>
        <param-name>com.sun.jersey.config.feature.TracePerRequest</param-name>
        <param-value>true</param-value>
    </init-param>
    

    For more information about the <init-param> element, see "servlet" in Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server.

  • Enable the com.sun.jersey.api.core.ResourceConfig.FEATURE_TRACE_PER_REQUEST property. For more information, see http://jersey.java.net/nonav/apidocs/1.9/jersey/com/sun/jersey/api/core/ResourceConfig.html#FEATURE_TRACE_PER_REQUEST.