Author: adrianc
Date: Thu Oct 24 17:12:46 2013
New Revision: 1535444
URL: http://svn.apache.org/r1535444
Log:
Some code simplification in the new URL generation classes.
Also loosened things up a bit in the OfbizUrlBuilder class: allow object
construction with partial information - required by some services. I don't like
this approach because it makes it possible to create nonsensical URLs, but it
is a necessary evil to keep the existing code working.
Modified:
ofbiz/trunk/framework/common/servicedef/services_email.xml
ofbiz/trunk/framework/common/src/org/ofbiz/common/email/NotificationServices.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/OfbizUrlBuilder.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java
Modified: ofbiz/trunk/framework/common/servicedef/services_email.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/servicedef/services_email.xml?rev=1535444&r1=1535443&r2=1535444&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/servicedef/services_email.xml (original)
+++ ofbiz/trunk/framework/common/servicedef/services_email.xml Thu Oct 24
17:12:46 2013
@@ -110,6 +110,7 @@ under the License.
<attribute name="xslfoAttachScreenLocationList" type="List" mode="IN"
optional="true"/>
<attribute name="attachmentNameList" type="List" mode="IN"
optional="true"/>
<attribute name="bodyParameters" type="Map" mode="IN" optional="true"/>
+ <!-- FIXME: webSiteId should not be optional, async service can't
construct valid URLs without it -->
<attribute name="webSiteId" type="String" mode="IN" optional="true"/>
<attribute name="subject" type="String" mode="OUT" optional="true"/>
<attribute name="body" type="String" mode="OUT" optional="false"/>
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/email/NotificationServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/email/NotificationServices.java?rev=1535444&r1=1535443&r2=1535444&view=diff
==============================================================================
---
ofbiz/trunk/framework/common/src/org/ofbiz/common/email/NotificationServices.java
(original)
+++
ofbiz/trunk/framework/common/src/org/ofbiz/common/email/NotificationServices.java
Thu Oct 24 17:12:46 2013
@@ -253,7 +253,10 @@ public class NotificationServices {
// If the baseUrl was not specified we can do a best effort instead
if (!context.containsKey("baseUrl")) {
try {
- WebappInfo webAppInfo =
WebAppUtil.getWebappInfoFromWebsiteId(webSiteId);
+ WebappInfo webAppInfo = null;
+ if (webSiteId != null) {
+ webAppInfo =
WebAppUtil.getWebappInfoFromWebsiteId(webSiteId);
+ }
OfbizUrlBuilder builder = OfbizUrlBuilder.from(webAppInfo,
delegator);
StringBuilder newURL = new StringBuilder();
builder.buildHostPart(newURL, "", false);
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/OfbizUrlBuilder.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/OfbizUrlBuilder.java?rev=1535444&r1=1535443&r2=1535444&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/OfbizUrlBuilder.java
(original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/OfbizUrlBuilder.java Thu
Oct 24 17:12:46 2013
@@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletReq
import org.ofbiz.base.component.ComponentConfig.WebappInfo;
import org.ofbiz.base.util.Assert;
-import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.GenericEntityException;
@@ -45,8 +44,7 @@ public final class OfbizUrlBuilder {
public static final String module = OfbizUrlBuilder.class.getName();
/**
- * Returns an <code>OfbizUrlBuilder</code> instance. The instance can be
reused in
- * the supplied request.
+ * Returns an <code>OfbizUrlBuilder</code> instance.
*
* @param request
* @throws GenericEntityException
@@ -54,22 +52,25 @@ public final class OfbizUrlBuilder {
*/
public static OfbizUrlBuilder from(HttpServletRequest request) throws
GenericEntityException, WebAppConfigurationException {
Assert.notNull("request", request);
- WebSiteProperties webSiteProps = (WebSiteProperties)
request.getAttribute("_WEBSITE_PROPS_");
- if (webSiteProps == null) {
- webSiteProps = WebSiteProperties.from(request);
- request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
+ OfbizUrlBuilder builder = (OfbizUrlBuilder)
request.getAttribute("_OFBIZ_URL_BUILDER_");
+ if (builder == null) {
+ WebSiteProperties webSiteProps = WebSiteProperties.from(request);
+ URL url =
ConfigXMLReader.getControllerConfigURL(request.getServletContext());
+ ControllerConfig config = ConfigXMLReader.getControllerConfig(url);
+ String servletPath = (String)
request.getAttribute("_CONTROL_PATH_");
+ builder = new OfbizUrlBuilder(config, webSiteProps, servletPath);
+ request.setAttribute("_OFBIZ_URL_BUILDER_", builder);
}
- URL url =
ConfigXMLReader.getControllerConfigURL(request.getServletContext());
- ControllerConfig config = ConfigXMLReader.getControllerConfig(url);
- String servletPath = (String) request.getAttribute("_CONTROL_PATH_");
- return new OfbizUrlBuilder(config, webSiteProps, servletPath);
+ return builder;
}
/**
* Returns an <code>OfbizUrlBuilder</code> instance. Use this method when
you
* don't have a <code>HttpServletRequest</code> object - like in scheduled
jobs.
*
- * @param webAppInfo
+ * @param webAppInfo Optional - if <code>null</code>, the builder can only
build the host part,
+ * and that will be based only on the settings in
<code>url.properties</code> (the WebSite
+ * entity will be ignored).
* @param delegator
* @throws WebAppConfigurationException
* @throws IOException
@@ -77,20 +78,24 @@ public final class OfbizUrlBuilder {
* @throws GenericEntityException
*/
public static OfbizUrlBuilder from(WebappInfo webAppInfo, Delegator
delegator) throws WebAppConfigurationException, IOException, SAXException,
GenericEntityException {
- Assert.notNull("webAppInfo", webAppInfo, "delegator", delegator);
WebSiteProperties webSiteProps = null;
- String webSiteId = WebAppUtil.getWebSiteId(webAppInfo);
- if (webSiteId != null) {
- GenericValue webSiteValue = delegator.findOne("WebSite",
UtilMisc.toMap("webSiteId", webSiteId), true);
- if (webSiteValue != null) {
- webSiteProps = WebSiteProperties.from(webSiteValue);
+ ControllerConfig config = null;
+ String servletPath = null;
+ if (webAppInfo != null) {
+ Assert.notNull("delegator", delegator);
+ String webSiteId = WebAppUtil.getWebSiteId(webAppInfo);
+ if (webSiteId != null) {
+ GenericValue webSiteValue = delegator.findOne("WebSite",
UtilMisc.toMap("webSiteId", webSiteId), true);
+ if (webSiteValue != null) {
+ webSiteProps = WebSiteProperties.from(webSiteValue);
+ }
}
+ config = ConfigXMLReader.getControllerConfig(webAppInfo);
+ servletPath = WebAppUtil.getControlServletPath(webAppInfo);
}
if (webSiteProps == null) {
webSiteProps = WebSiteProperties.defaults();
}
- ControllerConfig config =
ConfigXMLReader.getControllerConfig(webAppInfo);
- String servletPath = WebAppUtil.getControlServletPath(webAppInfo);
return new OfbizUrlBuilder(config, webSiteProps, servletPath);
}
@@ -140,7 +145,10 @@ public final class OfbizUrlBuilder {
if (queryIndex != -1) {
requestMapUri = requestMapUri.substring(0, queryIndex);
}
- RequestMap requestMap = config.getRequestMapMap().get(requestMapUri);
+ RequestMap requestMap = null;
+ if (config != null) {
+ requestMap = config.getRequestMapMap().get(requestMapUri);
+ }
if (requestMap != null) {
makeSecure = requestMap.securityHttps;
}
@@ -178,6 +186,9 @@ public final class OfbizUrlBuilder {
* @throws IOException
*/
public void buildPathPart(Appendable buffer, String url) throws
WebAppConfigurationException, IOException {
+ if (servletPath == null) {
+ throw new IllegalStateException("Servlet path is unknown");
+ }
buffer.append(servletPath);
if (!url.startsWith("/")) {
buffer.append("/");
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java?rev=1535444&r1=1535443&r2=1535444&view=diff
==============================================================================
---
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java
(original)
+++
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java
Thu Oct 24 17:12:46 2013
@@ -53,17 +53,24 @@ public final class WebSiteProperties {
*/
public static WebSiteProperties from(HttpServletRequest request) throws
GenericEntityException {
Assert.notNull("request", request);
- Delegator delegator = (Delegator) request.getAttribute("delegator");
- if (delegator != null) {
- String webSiteId = WebSiteWorker.getWebSiteId(request);
- if (webSiteId != null) {
- GenericValue webSiteValue = delegator.findOne("WebSite",
UtilMisc.toMap("webSiteId", webSiteId), true);
- if (webSiteValue != null) {
- return from(webSiteValue);
+ WebSiteProperties webSiteProps = (WebSiteProperties)
request.getAttribute("_WEBSITE_PROPS_");
+ if (webSiteProps == null) {
+ Delegator delegator = (Delegator)
request.getAttribute("delegator");
+ if (delegator != null) {
+ String webSiteId = WebSiteWorker.getWebSiteId(request);
+ if (webSiteId != null) {
+ GenericValue webSiteValue = delegator.findOne("WebSite",
UtilMisc.toMap("webSiteId", webSiteId), true);
+ if (webSiteValue != null) {
+ webSiteProps = from(webSiteValue);
+ }
}
}
- }
- return new WebSiteProperties();
+ if (webSiteProps == null) {
+ webSiteProps = new WebSiteProperties();
+ }
+ request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
+ }
+ return webSiteProps;
}
/**