Package com.composum.sling.core.proxy
Class GenericProxyRequest
- java.lang.Object
-
- com.composum.sling.core.proxy.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 Summary
Fields Modifier and Type Field Description protected org.osgi.framework.BundleContext
bundleContext
protected GenericProxyConfig
config
protected Pattern
targetPattern
static Pattern
XML_CONTENT_TYPE
static Pattern
XML_CONTENT_URL
-
Constructor Summary
Constructors Constructor Description GenericProxyRequest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
activate(org.osgi.service.component.ComponentContext context, GenericProxyConfig config)
protected void
addHttpValues(@NotNull Map<String,Object> values)
boolean
doProxy(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, @NotNull String targetUrl)
Handles the proxy request if appropriate (target pattern matches and access allowed)protected void
doRequest(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, @NotNull String targetRef, @NotNull Matcher matcher)
Send the request to the proxies target and sends the reveived answer ans responseprotected void
doResponse(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, @NotNull String targetUrl, @NotNull org.apache.http.HttpEntity entity)
Prepare, filter and deliver the content entity reveived from the target.protected @NotNull Reader
getContentReader(@NotNull String targetUrl, @NotNull InputStream entityContent)
the factory method for the reader to prepare and filter the content received from the targetprotected @Nullable String
getContentType(@NotNull String targetUrl, @NotNull org.apache.http.HttpEntity entity)
static @Nullable InputStream
getFileContent(@Nullable org.apache.sling.api.resource.Resource resource)
static @Nullable org.apache.sling.api.resource.Resource
getFileResource(@Nullable org.apache.sling.api.resource.Resource resource)
@NotNull String
getName()
return the key of the serviceprotected @Nullable String
getTargetUrl(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull String targetRef, @NotNull Matcher matcher)
Builds the URL for the target request using the URI built by the ProxyServlet and the matcher of that URI.static XMLFilter
getXmlFilter(@NotNull SAXTransformerFactory stf, @Nullable org.apache.sling.api.resource.Resource xsltResource)
protected @Nullable XMLFilter
getXsltFilter(@NotNull SAXTransformerFactory stf, @NotNull org.apache.sling.api.resource.ResourceResolver resolver, @NotNull String[] xsltChainPaths)
-
-
-
Field Detail
-
XML_CONTENT_URL
public static final Pattern XML_CONTENT_URL
-
XML_CONTENT_TYPE
public static final Pattern XML_CONTENT_TYPE
-
config
protected GenericProxyConfig config
-
targetPattern
protected Pattern targetPattern
-
bundleContext
protected org.osgi.framework.BundleContext bundleContext
-
-
Method Detail
-
activate
protected void activate(org.osgi.service.component.ComponentContext context, GenericProxyConfig config)
-
getName
@NotNull public @NotNull String getName()
Description copied from interface:GenericProxyService
return the key of the service- Specified by:
getName
in interfaceGenericProxyService
-
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 interfaceGenericProxyService
- Parameters:
request
- the proxy requestresponse
- the response for the answertargetUrl
- 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 servletresponse
- the response of the rquest to the proxy servlettargetRef
- the URL derived from the request to the proxy servletmatcher
- 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 servletresponse
- the response object to send the answertargetUrl
- the URL used to request the entityentity
- 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 entityentityContent
- 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 ProxyServlettargetRef
- 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
-
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)
-
-