Re: Generating DA urls on background thread
Aaron Rosenzweig <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.wonder-disc |
|---|---|
| Message-ID | <CANEQY+wN9MwvxPv+JLG2t_HT1o+fb=2k1zTCtXQpFPzsn9BPKw@mail.gmail.com> |
Hi Ramsey,
Perhaps you need a better "dummy" WOContext. It's a bit of a black art.
Here's what we use:
/**
* Creates a WOContext using a dummy WORequest.
* @return the new WOContext
*/
public static WOContext dummyContext() {
WOApplication app = WOApplication.application();
// Try to create a URL with a relative path into the application to mimic a
real request.
// We must create a request with a relative URL, as using an absolute URL
makes the new
// WOContext's URL absolute, and it is then unable to render relative
paths. (Long story short.)
//
// Note: If you configured the adaptor's WebObjectsAlias to something other
than the default,
// make sure to also set your WOAdaptorURL property to match. Otherwise,
asking the new context
// the path to a direct action or component action URL will give an
incorrect result.
String requestUrl = app.cgiAdaptorURL() + "/" + app.name() + ".woa";
try {
URL url = new URL(requestUrl);
requestUrl = url.getPath(); // Get just the part of the URL that is
relative to the server root.
} catch (MalformedURLException mue) {
// The above should never fail. As a last resort, using the empty string
will
// look funny in the request, but still allow the context to use a relative
url.
requestUrl = "";
}
return new WOContext(app.createRequest("GET", requestUrl, "HTTP/1.1", null,
null, null));
}
... and then calling the dummy context to create a directAction URL:
protected String taskLinkToDownloadFinishedProductEmailMessage() {
String linkMessage = "";
if (finishedTaskDownloadableFullFileNamePath() != null &&
finishedTaskDownloadableFullFileNamePath().trim().length() > 0) {
WOContext dummyContext = AmagaviUtilities.dummyContext();
NSMutableDictionary<String, Object> queryParameters =
newNSMutableDictionary<String, Object>();
queryParameters.takeValueForKey(finishedTaskDownloadableFullFileNamePath(),
DOWNLOAD_FULL_FILENAME_QUERY_PARAMETER);
String directActionURL = ERXWOContext.directActionUrl(dummyContext,
"downloadTaskResults", queryParameters, true /*secure*/, false
/*includeSessionID*/);
linkMessage += "Download your file now: <a href=\"" + directActionURL
+ "\">click
here to download</a><br /><br />";
linkMessage += "Note: file will be deleted within 7 days<br /><br />";
} else {
linkMessage += "No file download available " + "<br /><br />";
}
return linkMessage;
}
-- Aaron
http://www.chatnbike.com/
On Wed, Feb 20, 2013 at 12:02 PM, Ramsey Gurley <[email protected]>wrote:
> I'm generating emails on a background thread. I need to generate the
> direct action unsubscribe url. To do this, I generate a new context using
> ERXWOContext.newContext() and create my DA urls off that.
>
> The problem is when direct connect is false, I'm getting host:port in my
> URLs. None of the methods on WOContext/ERXWOContext appear to work
> correctly. Am I missing something?
>
> Ramsey
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_d2d_feb
> _______________________________________________
> Wonder-disc mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wonder-disc
>
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Wonder-disc mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wonder-disc