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
  • Constructor Details

    • DefaultContentTypeHandlerManager

      public DefaultContentTypeHandlerManager()
  • Method Details

    • setDefaultExtension

      public void setDefaultExtension(String name)
    • setContainer

      public void setContainer(Container container)
    • getHandlerForRequest

      public ContentTypeHandler getHandlerForRequest(jakarta.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(jakarta.servlet.http.HttpServletRequest request, jakarta.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(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