org.apache.struts2.rest

## Class DefaultContentTypeHandlerManager

- java.lang.Object
- - org.apache.struts2.rest.DefaultContentTypeHandlerManager

- All Implemented Interfaces:
    ContentTypeHandlerManager

      public class DefaultContentTypeHandlerManager
      extends Object
      implements ContentTypeHandlerManager

  Manages `ContentTypeHandler` instances and uses them to process results

- - ### Field Summary

    - ### Fields inherited from interface org.apache.struts2.rest.ContentTypeHandlerManager

      `STRUTS_REST_HANDLER_OVERRIDE_PREFIX`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultContentTypeHandlerManager()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `findExtension(String url)` Finds the extension in the url
    `String` | `getExtensionIfPresent(String url)` Gets the extension in the url
    `ContentTypeHandler` | `getHandlerForRequest(javax.servlet.http.HttpServletRequest request)` Gets the handler for the request by looking at the request content type and extension
    `ContentTypeHandler` | `getHandlerForResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse res)` Gets the handler for the response by looking at the extension of the request
    `String` | `handleResult(ActionConfig actionConfig, Object methodResult, Object target)` Handles the result using handlers to generate content type-specific content
    `String` | `handleResult(ActionInvocation invocation, Object methodResult, Object target)` Handles the result using handlers to generate content type-specific content
    `protected String` | `readResultCode(Object methodResult)`
    `protected Integer` | `readStatusCode(Object methodResult)`
    `void` | `setContainer(Container container)`
    `void` | `setDefaultExtension(String name)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultContentTypeHandlerManager

          public DefaultContentTypeHandlerManager()

  - ### Method Detail

    - #### setDefaultExtension

          public void setDefaultExtension(String name)

    - #### setContainer

          public void setContainer(Container container)

    - #### getHandlerForRequest

          public ContentTypeHandler getHandlerForRequest(javax.servlet.http.HttpServletRequest request)

      Gets the handler for the request by looking at the request content type and extension
      Specified by:
        `getHandlerForRequest` in interface `ContentTypeHandlerManager`
      Parameters:
        `request` - The request
      Returns:
        The appropriate handler

    - #### getHandlerForResponse

          public ContentTypeHandler getHandlerForResponse(javax.servlet.http.HttpServletRequest request,
                                                 javax.servlet.http.HttpServletResponse res)

      Gets the handler for the response by looking at the extension of the request
      Specified by:
        `getHandlerForResponse` in interface `ContentTypeHandlerManager`
      Parameters:
        `request` - The request
        `res` - The servlet response
      Returns:
        The appropriate handler WW-4588: modified to get a handler for the response side and auto generate the response type from the Accept: header

    - #### handleResult

          public String handleResult(ActionConfig actionConfig,
                            Object methodResult,
                            Object target)
                              throws IOException

      Description copied from interface: `ContentTypeHandlerManager`
      Handles the result using handlers to generate content type-specific content
      Specified by:
        `handleResult` in interface `ContentTypeHandlerManager`
      Parameters:
        `actionConfig` - The action config for the current request
        `methodResult` - The object returned from the action method
        `target` - The object to return, usually the action object
      Returns:
        The new result code to process
      Throws:
        `IOException` - If unable to write to the response

    - #### handleResult

          public String handleResult(ActionInvocation invocation,
                            Object methodResult,
                            Object target)
                              throws IOException

      Handles the result using handlers to generate content type-specific content
      Specified by:
        `handleResult` in interface `ContentTypeHandlerManager`
      Parameters:
        `invocation` - The action invocation for the current request
        `methodResult` - The object returned from the action method
        `target` - The object to return, usually the action object
      Returns:
        The new result code to process
      Throws:
        `IOException` - If unable to write to the response

    - #### readStatusCode

          protected Integer readStatusCode(Object methodResult)

    - #### readResultCode

          protected String readResultCode(Object methodResult)

    - #### getExtensionIfPresent

          public String getExtensionIfPresent(String url)

      Gets the extension in the url
      Parameters:
        `url` - The url
      Returns:
        The extension, or null

    - #### findExtension

          public String findExtension(String url)

      Finds the extension in the url
      Specified by:
        `findExtension` in interface `ContentTypeHandlerManager`
      Parameters:
        `url` - The url
      Returns:
        The extension, or the default extension if there is none

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.