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
master
jensp 2015-01-29 10:04:20 +00:00
parent f3e88be801
commit 9bae8e9d87
6 changed files with 79 additions and 59 deletions

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<!-- nothing yet -->
<config class="com.arsdigita.cms.contenttypes.SiteProxyConfig"
storage="ccm-cms-types-siteproxy/siteproxy.properties"/>
</registry>

View File

@ -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.");

View File

@ -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.*;
/**
* <p>This <code>SiteProxyPanel</code> 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
* <p>
* This <code>SiteProxyPanel</code> 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 <code>XMLGenerator</code> 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
* <code>XMLGenerator</code> 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 = "<?xml version=\"1.0\"?> \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<paramValues.length; ++i) {
for (int i = 0; i < paramValues.length; ++i) {
if (sb.indexOf("?") < 0) {
sb.append("?");
} else {
@ -195,5 +206,5 @@ public class SiteProxyPanel extends ContentPanel {
}
return sb.toString();
}
}

View File

@ -964,7 +964,7 @@ cms.ui.item.lifecycle.do=Ausf\u00fchren
cms.ui.item.lifecycle.do.not_authorized=Sie sind nicht berechtigt, dieses Item zu publizieren.
cms.ui.item.lifecycle.publish_locked=Dieses Content-Item wird gerade (re-)publiziert
cms.ui.item.lifecycle.publish_locked.update=Aktualisieren
cms.ui.lifecycle.publish.error=W\u00e4hrend des Publizierens ist ein Fehler aufgetreten. Der System-Administrator wurde per \u00fcber das Problem informiert. Dieses Item bleibt besperrt, bis der Administrator die Sperre manuell entfernt.
cms.ui.lifecycle.publish.error=W\u00e4hrend des Publizierens ist ein Fehler aufgetreten. Der System-Administrator wurde \u00fcber das Problem informiert. Dieses Item bleibt gesperrt, bis der Administrator die Sperre manuell entfernt.
cms.ui.delete_confirmation=Wollen Sie dieses Content-Item l\u00f6schen?
cms.ui.lifecycle.details.last_published=Das Item wurde zuletzt republiziert am
cms.ui.item_search.flat.filter=Liste filtern

View File

@ -24,6 +24,7 @@ import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentItemXMLRenderer;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.cms.portlet.ContentItemPortlet;
import com.arsdigita.dispatcher.AccessDeniedException;

View File

@ -6,7 +6,7 @@ com.arsdigita.cms.contenttypes.publications.attach_orgaunits_step.format = [Bool
com.arsdigita.cms.contenttypes.publications.orgaunits_step_sort_key.title = Sort key for the publication -> 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.