Class GenericProxyRequest

  • All Implemented Interfaces:
    GenericProxyService

    public class GenericProxyRequest
    extends Object
    implements GenericProxyService
    a configurable proxy request service factory usable directly and also as a base for special proxy implementations
    • Field Detail

      • XML_CONTENT_URL

        public static final Pattern XML_CONTENT_URL
      • XML_CONTENT_TYPE

        public static final Pattern XML_CONTENT_TYPE
      • targetPattern

        protected Pattern targetPattern
      • bundleContext

        protected org.osgi.framework.BundleContext bundleContext
    • Constructor Detail

      • GenericProxyRequest

        public GenericProxyRequest()
    • Method Detail

      • activate

        protected void activate​(org.osgi.service.component.ComponentContext context,
                                GenericProxyConfig config)
      • doProxy

        public boolean doProxy​(@NotNull
                               @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                               @NotNull
                               @NotNull org.apache.sling.api.SlingHttpServletResponse response,
                               @NotNull
                               @NotNull String targetUrl)
                        throws IOException
        Handles the proxy request if appropriate (target pattern matches and access allowed)
        Specified by:
        doProxy in interface GenericProxyService
        Parameters:
        request - the proxy request
        response - the response for the answer
        targetUrl - the url of the request which is addressing the target
        Returns:
        'true' if the request is supported by the service, allowed for the user and handle by the service
        Throws:
        IOException
      • doRequest

        protected void doRequest​(@NotNull
                                 @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                                 @NotNull
                                 @NotNull org.apache.sling.api.SlingHttpServletResponse response,
                                 @NotNull
                                 @NotNull String targetRef,
                                 @NotNull
                                 @NotNull Matcher matcher)
                          throws Exception
        Send the request to the proxies target and sends the reveived answer ans response
        Parameters:
        request - the request to the proxy servlet
        response - the response of the rquest to the proxy servlet
        targetRef - the URL derived from the request to the proxy servlet
        matcher - the prepared matcher used to determine this proxy service implementation as the right one
        Throws:
        Exception
      • doResponse

        protected void doResponse​(@NotNull
                                  @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                                  @NotNull
                                  @NotNull org.apache.sling.api.SlingHttpServletResponse response,
                                  @NotNull
                                  @NotNull String targetUrl,
                                  @NotNull
                                  @NotNull org.apache.http.HttpEntity entity)
                           throws IOException
        Prepare, filter and deliver the content entity reveived from the target.
        Parameters:
        request - the request to the proxy servlet
        response - the response object to send the answer
        targetUrl - the URL used to request the entity
        entity - the content received from the target
        Throws:
        IOException
      • getContentType

        @Nullable
        protected @Nullable String getContentType​(@NotNull
                                                  @NotNull String targetUrl,
                                                  @NotNull
                                                  @NotNull org.apache.http.HttpEntity entity)
        Returns:
        the type of the requested content determined from the entity or the requested URL
      • getContentReader

        @NotNull
        protected @NotNull Reader getContentReader​(@NotNull
                                                   @NotNull String targetUrl,
                                                   @NotNull
                                                   @NotNull InputStream entityContent)
        the factory method for the reader to prepare and filter the content received from the target
        Parameters:
        targetUrl - the URL used to request the entity
        entityContent - the received content as stream
        Returns:
        the reader to use to receive the content
      • getTargetUrl

        @Nullable
        protected @Nullable String getTargetUrl​(@NotNull
                                                @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                                                @NotNull
                                                @NotNull String targetRef,
                                                @NotNull
                                                @NotNull Matcher matcher)
        Builds the URL for the target request using the URI built by the ProxyServlet and the matcher of that URI.
        Parameters:
        request - the original request received by the ProxyServlet
        targetRef - the target URI derived from the original request (suffix + query string)
        matcher - the URI pattern matcher (gives access to the groups declared by the pattern)
        Returns:
        the URL for the HTTP request to the target
      • addHttpValues

        protected void addHttpValues​(@NotNull
                                     @NotNull Map<String,​Object> values)
      • getXsltFilter

        @Nullable
        protected @Nullable XMLFilter getXsltFilter​(@NotNull
                                                    @NotNull SAXTransformerFactory stf,
                                                    @NotNull
                                                    @NotNull org.apache.sling.api.resource.ResourceResolver resolver,
                                                    @NotNull
                                                    @NotNull String[] xsltChainPaths)
        Returns:
        a chain of XML filters initialized with the XSLT resources resolved from the given path list
      • getXmlFilter

        public static XMLFilter getXmlFilter​(@NotNull
                                             @NotNull SAXTransformerFactory stf,
                                             @Nullable
                                             @Nullable org.apache.sling.api.resource.Resource xsltResource)
      • getFileContent

        @Nullable
        public static @Nullable InputStream getFileContent​(@Nullable
                                                           @Nullable org.apache.sling.api.resource.Resource resource)
      • getFileResource

        @Nullable
        public static @Nullable org.apache.sling.api.resource.Resource getFileResource​(@Nullable
                                                                                       @Nullable org.apache.sling.api.resource.Resource resource)