From 9bae8e9d8749552ec3f8387b6c4aab190a3d5af1 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 29 Jan 2015 10:04:20 +0000 Subject: [PATCH] Timeout, cache size and cache expiry time for the site proxy can now be configured using the siteproxy.properties file git-svn-id: https://svn.libreccm.org/ccm/trunk@3106 8810af33-2d31-482b-a856-94f89814c4df --- .../src/ccm-cms-types-siteproxy.config | 3 +- .../SiteProxyExtraXMLGenerator.java | 11 +- .../cms/dispatcher/SiteProxyPanel.java | 119 ++++++++++-------- .../arsdigita/cms/CMSResources_de.properties | 2 +- .../portlet/ContentItemPortletRenderer.java | 1 + .../PublicationsConfig_parameter.properties | 2 +- 6 files changed, 79 insertions(+), 59 deletions(-) diff --git a/ccm-cms-types-siteproxy/src/ccm-cms-types-siteproxy.config b/ccm-cms-types-siteproxy/src/ccm-cms-types-siteproxy.config index adfdba100..c3182e67d 100755 --- a/ccm-cms-types-siteproxy/src/ccm-cms-types-siteproxy.config +++ b/ccm-cms-types-siteproxy/src/ccm-cms-types-siteproxy.config @@ -1,4 +1,5 @@ - + diff --git a/ccm-cms-types-siteproxy/src/com/arsdigita/cms/contenttypes/SiteProxyExtraXMLGenerator.java b/ccm-cms-types-siteproxy/src/com/arsdigita/cms/contenttypes/SiteProxyExtraXMLGenerator.java index 63f90ac1c..440c83432 100644 --- a/ccm-cms-types-siteproxy/src/com/arsdigita/cms/contenttypes/SiteProxyExtraXMLGenerator.java +++ b/ccm-cms-types-siteproxy/src/com/arsdigita/cms/contenttypes/SiteProxyExtraXMLGenerator.java @@ -34,10 +34,17 @@ public class SiteProxyExtraXMLGenerator implements ExtraXMLGenerator { private static final String C_DATA_DATA_TYPE = "cdata"; private static final String XML_DATA_TYPE = "xml"; private static final String s_cacheServiceKey = "SiteProxyPanel"; - private static final URLCache s_cache = new URLCache(1000000, 1 * 60 * 1000); - private static final URLPool s_pool = new URLPool(); + private static final SiteProxyConfig config = new SiteProxyConfig(); +// private static final URLCache s_cache = new URLCache(1000000, 1 * 60 * 1000); +// private static final URLPool s_pool = new URLPool(10, 10000); + private static final URLCache s_cache = new URLCache( + config.getUrlCacheSize(), config.getUrlCacheExpiryTime()); + private static final URLPool s_pool = new URLPool( + config.getUrlPoolSize(), config.getUrlPoolTimeout()); static { + config.load(); + logger.debug("Static initalizer starting..."); URLFetcher.registerService(s_cacheServiceKey, s_pool, s_cache); logger.debug("Static initalizer finished."); diff --git a/ccm-cms-types-siteproxy/src/com/arsdigita/cms/dispatcher/SiteProxyPanel.java b/ccm-cms-types-siteproxy/src/com/arsdigita/cms/dispatcher/SiteProxyPanel.java index fb2308ceb..c2931c852 100755 --- a/ccm-cms-types-siteproxy/src/com/arsdigita/cms/dispatcher/SiteProxyPanel.java +++ b/ccm-cms-types-siteproxy/src/com/arsdigita/cms/dispatcher/SiteProxyPanel.java @@ -24,24 +24,27 @@ import com.arsdigita.cms.contenttypes.util.SiteProxyGlobalizationUtil; import com.arsdigita.bebop.Label; import com.arsdigita.cms.CMS; import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.contenttypes.SiteProxyConfig; import com.arsdigita.util.url.URLFetcher; import com.arsdigita.util.url.URLPool; import com.arsdigita.util.url.URLCache; import com.arsdigita.util.url.URLData; import com.arsdigita.xml.Element; import com.arsdigita.xml.Document; + import org.apache.log4j.Logger; + import javax.servlet.http.*; + import java.util.*; import java.net.*; import java.io.*; - /** - *

This SiteProxyPanel component fetches - * the {@link com.arsdigita.cms.dispatcher.XMLGenerator} for the content - * section. It also uses the url from the SiteProxy object to - * retrieve XML or HTML from the specified location. This XML/HTML is + *

+ * This SiteProxyPanel component fetches the + * {@link com.arsdigita.cms.dispatcher.XMLGenerator} for the content section. It also uses the url + * from the SiteProxy object to retrieve XML or HTML from the specified location. This XML/HTML is * integrated in to the resulting DOM * * @author Michael Pih (pihman@arsdigita.com) @@ -56,26 +59,34 @@ public class SiteProxyPanel extends ContentPanel { private static String DATA_TYPE = "dataType"; private static String C_DATA_DATA_TYPE = "cdata"; private static String XML_DATA_TYPE = "xml"; - + private static String s_cacheServiceKey = "SiteProxyPanel"; - private static URLCache s_cache = new URLCache(1000000, 15*60*1000); - private static URLPool s_pool = new URLPool(); + private static final SiteProxyConfig config = new SiteProxyConfig(); +// private static URLCache s_cache = new URLCache(1000000, 15*60*1000); +// private static URLPool s_pool = new URLPool(); + private static final URLCache s_cache = new URLCache( + config.getUrlCacheSize(), config.getUrlCacheExpiryTime()); + private static final URLPool s_pool = new URLPool( + config.getUrlPoolSize(), config.getUrlPoolTimeout()); static { + config.load(); + s_log.debug("Static initalizer starting..."); URLFetcher.registerService(s_cacheServiceKey, s_pool, s_cache); s_log.debug("Static initalizer finished."); - }; + } + + ; public SiteProxyPanel() { super(); } /** - * Fetches an XML Generator. This method can be overidden to fetch - * any {@link com.arsdigita.cms.dispatcher.XMLGenerator}, but by default, - * it fetches the XMLGenerator registered to the current - * {@link com.arsdigita.cms.ContentSection}. + * Fetches an XML Generator. This method can be overidden to fetch any + * {@link com.arsdigita.cms.dispatcher.XMLGenerator}, but by default, it fetches the + * XMLGenerator registered to the current {@link com.arsdigita.cms.ContentSection}. * * @param state The page state */ @@ -83,24 +94,22 @@ public class SiteProxyPanel extends ContentPanel { return new SiteProxyXMLGenerator(); } - /** * Retrieve remote XML for SiteProxy item. - * + * * @param child com.arsdigita.xml.Element where remote XML is placed - * @param url remote XML URL (text/xml) + * @param url remote XML URL (text/xml) */ public static URLData internalGetRemoteXML(Element child, String url) { URLData data = URLFetcher.fetchURLData(url, s_cacheServiceKey); if (data == null || data.getException() != null || data.getContent().length == 0) { - return data; + return data; } String contentType = data.getContentType(); boolean success = false; - if (contentType != null && - contentType.toLowerCase().indexOf("/xml") > -1) { + if (contentType != null && contentType.toLowerCase().indexOf("/xml") > -1) { // we use the /xml intead of text/xml because // things like application/xml are also valid Document document = null; @@ -108,77 +117,79 @@ public class SiteProxyPanel extends ContentPanel { document = new Document(data.getContent()); success = true; } catch (Exception ex) { - s_log.info("The document is not proper XML, trying to " + - "add the property xml headers to the file " + - "retrieved from " + url, ex); + s_log.info("The document is not proper XML, trying to " + + "add the property xml headers to the file " + "retrieved from " + url, + ex); try { String xmlString = data.getContentAsString(); xmlString = " \n" + xmlString; document = new Document(xmlString); success = true; - s_log.info("Adding the headers to " + url + - " allowed it to be properly parsed."); + s_log + .info("Adding the headers to " + url + " allowed it to be properly parsed."); } catch (Exception exception) { - s_log.info("The document found at " + url + - " is not correctly formed XML", exception); + s_log.info("The document found at " + url + " is not correctly formed XML", + exception); } } - if (success) { - child.addContent(document.getRootElement()); - child.addAttribute(DATA_TYPE, XML_DATA_TYPE); - } + if (success) { + child.addContent(document.getRootElement()); + child.addAttribute(DATA_TYPE, XML_DATA_TYPE); + } } if (!success) { // just add the item as CDATA child.setCDATASection(data.getContentAsString()); child.addAttribute(DATA_TYPE, C_DATA_DATA_TYPE); - } - return data; + } + return data; } - + class SiteProxyXMLGenerator extends SimpleXMLGenerator { @Override public void generateXML(PageState state, Element parent, String useContext) { ContentSection section = CMS.getContext().getContentSection(); - SiteProxy item = (SiteProxy)getContentItem(state); + SiteProxy item = (SiteProxy) getContentItem(state); String url = passParameters(state.getRequest(), item.getURL()); - - Element child = parent.newChildElement(SITE_PROXY_PANEL_NAME, + + Element child = parent.newChildElement(SITE_PROXY_PANEL_NAME, CMS.CMS_XML_NS); URLData data = internalGetRemoteXML(child, url); - + if (data == null) { String[] urlArray = {url}; - (new Label(SiteProxyGlobalizationUtil.globalize - ("cms.contenttypes.dispatcher.siteproxy.error_fetching_url", - urlArray))).generateXML(state, parent); + (new Label(SiteProxyGlobalizationUtil.globalize( + "cms.contenttypes.dispatcher.siteproxy.error_fetching_url", + urlArray))).generateXML(state, parent); } else if (data.getException() != null) { - String[] urlArray = - {url, data.getException().getClass().getName(), - data.getException().getMessage()}; - (new Label(SiteProxyGlobalizationUtil.globalize - ("cms.contenttypes.siteproxy.dispatcher.exception_fetching_url", - urlArray))).generateXML(state, parent); + String[] urlArray = {url, data.getException().getClass().getName(), + data.getException().getMessage()}; + (new Label(SiteProxyGlobalizationUtil.globalize( + "cms.contenttypes.siteproxy.dispatcher.exception_fetching_url", + urlArray))).generateXML(state, parent); } else if (data.getContent().length == 0) { String[] urlArray = {url}; - (new Label(SiteProxyGlobalizationUtil.globalize - ("cms.contenttypes.siteproxy.dispatcher.empty_page_returned", - urlArray))).generateXML(state, parent); + (new Label(SiteProxyGlobalizationUtil.globalize( + "cms.contenttypes.siteproxy.dispatcher.empty_page_returned", + urlArray))).generateXML(state, parent); } } + } - private String passParameters(HttpServletRequest request, String url){ + private String passParameters(HttpServletRequest request, String url) { StringBuffer sb = new StringBuffer(url); String enc = request.getCharacterEncoding(); - if (enc == null) enc = "UTF-8"; + if (enc == null) { + enc = "UTF-8"; + } Enumeration en = request.getParameterNames(); - while (en.hasMoreElements()){ + while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); String[] paramValues = request.getParameterValues(paramName); - for(int i=0; i GenericOrganizationalUnit authoring step com.arsdigita.cms.contenttypes.publications.orgaunits_step_sort_key.purpose = Sort key for the publication -> GenericOrganizationalUnit authoring step com.arsdigita.cms.contenttypes.publications.orgaunits_step_sort_key.example = 10 -com.arsdigita.cms.contenttypes.publications.orgaunits_step_sort_key = [Integer] +com.arsdigita.cms.contenttypes.publications.orgaunits_step_sort_key.format = [Integer] com.arsdigita.cms.contenttypes.publications.attach_organization_publications_step_to.title = Enable OrganizationPublications step com.arsdigita.cms.contenttypes.publications.attach_organization_publications_step_to.purpose = Attaches an authoring step to GenericOrganizationalUnit which displays all publications of the type UnPublished to which the organizational unit is assigned as publishing organization.