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.BundleContextbundleContextprotected GenericProxyConfigconfigprotected PatterntargetPatternstatic PatternXML_CONTENT_TYPEstatic PatternXML_CONTENT_URL
-
Constructor Summary
Constructors Constructor Description GenericProxyRequest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidactivate(org.osgi.service.component.ComponentContext context, GenericProxyConfig config)protected voidaddHttpValues(@NotNull Map<String,Object> values)booleandoProxy(@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 voiddoRequest(@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 voiddoResponse(@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 ReadergetContentReader(@NotNull String targetUrl, @NotNull InputStream entityContent)the factory method for the reader to prepare and filter the content received from the targetprotected @Nullable StringgetContentType(@NotNull String targetUrl, @NotNull org.apache.http.HttpEntity entity)static @Nullable InputStreamgetFileContent(@Nullable org.apache.sling.api.resource.Resource resource)static @Nullable org.apache.sling.api.resource.ResourcegetFileResource(@Nullable org.apache.sling.api.resource.Resource resource)@NotNull StringgetName()return the key of the serviceprotected @Nullable StringgetTargetUrl(@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 XMLFiltergetXmlFilter(@NotNull SAXTransformerFactory stf, @Nullable org.apache.sling.api.resource.Resource xsltResource)protected @Nullable XMLFiltergetXsltFilter(@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:GenericProxyServicereturn the key of the service- Specified by:
getNamein 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 IOExceptionHandles the proxy request if appropriate (target pattern matches and access allowed)- Specified by:
doProxyin 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 ExceptionSend 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 IOExceptionPrepare, 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)
-
-