Re: Generating DA urls on background thread

Ramsey Gurley <[email protected]>
Newsgroups gmane.comp.web.webobjects.wonder-disc
Message-ID <[email protected]>
On Feb 20, 2013, at 10:49 AM, Aaron Rosenzweig wrote:

> 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));
> 	}

This part looks identical to ERXWOContext.newContext() btw :-)

> 
> ... 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 = new NSMutableDictionary<String, Object>();
> 			queryParameters.takeValueForKey(finishedTaskDownloadableFullFileNamePath(), DOWNLOAD_FULL_FILENAME_QUERY_PARAMETER);
> 			String directActionURL = ERXWOContext.directActionUrl(dummyContext, "downloadTaskResults", queryParameters, true /*secure*/, false /*includeSessionID*/);

I think this only works because secure is true and you use the default https port. I use essentially the same code but secure = false and get the port. If I switch to secure = true, I don't get a port either. I can probably get away with this if I can fix a host name issue :-)

It looks like the problem is in ERXRequest._completeURLPrefix. I think we should check for direct connect in that method before appending a port to the url.

If that change is made, links still don't work in development because there's no port number between the app name and the /wa/. I get

The requested application was not found on this server.

It looks like to fix that, we could override ERXWOContext relativeURLWithRequestHandlerKey to replace .woa/ with .woa/-port/ if ERXApp.isDevModeSafe and !isDirectConnectEnabled.

Ramsey

> 			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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.