<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DaveTurner.info</title>
	<atom:link href="http://www.daveturner.info/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveturner.info/blog</link>
	<description>uhh... Housten... we have a problem..</description>
	<lastBuildDate>Sun, 10 Apr 2011 17:10:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Custom Java Exceptions, BlazeDS and Flex</title>
		<link>http://www.daveturner.info/blog/custom_java_blazeds_flex/</link>
		<comments>http://www.daveturner.info/blog/custom_java_blazeds_flex/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 16:54:56 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=113</guid>
		<description><![CDATA[Here is a quick and dirty way to get flex to play well with Custom Java Exceptions Custom Java exception A Simple Java exception that adds a new field called customDetails (via a Bean Property) public class myCustomException extends RuntimeException { private static final long serialVersionUID = 1L; private String details; public CampaignSaveException(String arg0) { [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick and dirty way to get flex to play well with Custom Java Exceptions</p>
<p>Custom Java exception<br />
A Simple Java exception that adds a new field called customDetails (via a Bean Property)</p>
<pre>public class myCustomException extends RuntimeException {

  private static final long serialVersionUID = 1L;
  private String details;
  public CampaignSaveException(String arg0) {
    super(arg0);
    details = arg0;
  }

  public String getCustomDetails(){
    return details;
  }
}</pre>
<p>When Java throws this exception during a remote call (i.e..)</p>
<pre>  throw new myCustomException ("Details for the error message");</pre>
<p>I can use this method to identify that this is in fact a myCustomException exception by looking for properties relevant to that class. This gives me an option to do some conditional logic when handling exceptions.</p>
<p>Note the usage of the &#8220;Bean property&#8221; where getCustomDetails() is set in the Java class but referenced in the front end as errorMessage.rootCause.customDetails.</p>
<pre>private function onSaveError(event:FaultEvent):void
{
  var errorMessage:ErrorMessage = event.message as ErrorMessage;
  if(errorMessage.rootCause.customDetails != null)
    Alert.show(errorMessage.rootCause.customDetails, "", Alert.OK);
  else{
    Alert.show("Generic Error Message", "", Alert.OK);
  }
}</pre>
<p>I believe there are more advanced methods than looking for a &#8220;bean property&#8221; (maybe casting?) but as the title suggests this is a quick and dirty example. Looking over the BlazeDS documentation</p>
<p>http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_2.html.</p>
<p>&nbsp;</p>
<p>It doesn’t look like BlazeDS will map Custom Java Exceptions to Flex Exceptions .. So i think there’s always going to be a little bit of hackery to any implementation of passing and handling exceptions between Java and Flex.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/custom_java_blazeds_flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ant mxmlc java heap space error</title>
		<link>http://www.daveturner.info/blog/ant-mxmlc-java-heap-space-error/</link>
		<comments>http://www.daveturner.info/blog/ant-mxmlc-java-heap-space-error/#comments</comments>
		<pubDate>Mon, 10 May 2010 22:09:16 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=110</guid>
		<description><![CDATA[Fix for ant mxmlc java heap space error When compiling large Flex apps via ant on crappy machines (like the one my job provides me) You may get a Java out of memory heap error. I got past this by doing the following In Eclipse 1. Open up the ant &#8220;run as&#8221; dialog box 2. [...]]]></description>
			<content:encoded><![CDATA[<p>Fix for ant mxmlc java heap space error</p>
<p>When compiling large Flex apps via ant on crappy machines (like the one my job provides me) You may get a Java out of memory heap error.</p>
<p>I got past this by doing the following</p>
<p>In Eclipse<br />
1. Open up the ant &#8220;run as&#8221; dialog box<br />
2. go the JVM tab and add the following argument to the JVM arguments section &#8220;-Xmx512M&#8221;</p>
<p>In Ant from the command line<br />
1. set ANT_OPTS= -Xmx512M</p>
<pre>set ANT_OPTS=-Xmx512M; export ANT_OPTS</pre>
<p>Hope this helps</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/ant-mxmlc-java-heap-space-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>handling java exceptions in Flex</title>
		<link>http://www.daveturner.info/blog/handling-java-exceptions-in-flex-app/</link>
		<comments>http://www.daveturner.info/blog/handling-java-exceptions-in-flex-app/#comments</comments>
		<pubDate>Fri, 07 May 2010 15:45:52 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=105</guid>
		<description><![CDATA[Gracefully handling Java Exceptions in a BlazeDS Flex App. When a Java method throws an exception (see example) public static boolean someMethod(boolean myVar) throws Exception { if(myVar) throw new Exception("A Simple Exception"); else return true; } To handle the Exception gracefully (i.e. strip out the stack trace and display just the Error message) import mx.messaging.messages.ErrorMessage; [...]]]></description>
			<content:encoded><![CDATA[<p>Gracefully handling Java Exceptions in a BlazeDS Flex App.</p>
<p>When a Java method throws an exception (see example)</p>
<pre>public static boolean someMethod(boolean myVar) throws Exception
{
  if(myVar)
    throw new Exception("A Simple Exception");
  else
   return true;
}
</pre>
<p>To handle the Exception gracefully (i.e. strip out the stack trace and display just the Error message)</p>
<pre>import mx.messaging.messages.ErrorMessage;
....
private function onDBErrorError(event:FaultEvent):void
{
  var msg:ErrorMessage = event.message as ErrorMessage;
  Alert.show(msg.rootCause.message);
}
</pre>
<p>Hope this helps..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/handling-java-exceptions-in-flex-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting Apache to Tomcat utilizing Mod_JK</title>
		<link>http://www.daveturner.info/blog/apache-tomcat-with-mod_jk/</link>
		<comments>http://www.daveturner.info/blog/apache-tomcat-with-mod_jk/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 17:03:32 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=92</guid>
		<description><![CDATA[Mod JK is the Apache  to Tomcat Connector.  It allows one to serve Tomcat webapps from Apache Http server. Steps to install. Note: This is based off my machines setup Apache 2.2.14, Tomcat 6, Windows 7 64 Bit, Mod JK 1.2.28 1. Download Apache webserver, Install it and verify it is running see &#8220;http://httpd.apache.org/&#8221; for [...]]]></description>
			<content:encoded><![CDATA[<p>Mod JK is the Apache  to Tomcat Connector.  It allows one to serve Tomcat webapps from Apache Http server.</p>
<p>Steps to install.<br />
Note: This is based off my machines setup Apache 2.2.14, Tomcat 6, Windows 7 64 Bit, Mod JK 1.2.28</p>
<p>1. Download Apache webserver, Install it and verify it is running see &#8220;http://httpd.apache.org/&#8221; for more information.</p>
<p>2. Download Tomcat, Install it and verify it is running.  See &#8220;http://tomcat.apache.org/&#8221; for more information</p>
<p>3. Download the Apache Tomcat Connector and copy it to [APACHE_ROOT]/modules. See <a href="http://tomcat.apache.org/connectors-do" target="_blank">http://tomcat.apache.org/connectors-do</a>c for more information.</p>
<p>I was able to download the MOD_JK here <a href="http://apache.multihomed.net/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/" target="_blank">http://apache.multihomed.net/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/</a></p>
<p>4. Create a &#8220;workers.properties&#8221; file and place it at [TOMCAT_ROOT]/conf/jk</p>
<p>AJP13 worker is the preferred worker type that JK uses for communication between web server and Tomcat. Here is a simple implementation of the workers.properties file</p>
<pre>worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009</pre>
<p>5. Edit the Apache Configuration file [APACHE_ROOT]/conf/httpd.conf in the following way</p>
<pre>LoadModule jk_module /modules/mod_jk-1.2.28-httpd-2.2.3.so
Include "[PATH_TO_TOMCAT]/conf/auto/mod_jk.conf"</pre>
<p>6. Edit Server.xml in [TOMCAT_ROOT]/conf in the following manner.</p>
<p>Under the  &lt;Server&gt; node add this</p>
<pre>&lt;Listener className = "org.apache.jk.config.ApacheConfig"
workersConfig="conf/workers.properties"
mod_Jk="[PATH_TO_APACHE]/modules/mod_jk.so"
jkLog="logs/mod_jk.log" jkDebug="info" noRoot="false"/&gt;</pre>
<p>Under the &lt;Engine&gt;  node add this</p>
<p>Restart Tomcat.. You should see a new file [TOMCAT_ROOT]/conf/auto/mod_jk.conf</p>
<p>Restart Apache.. you should be good</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/apache-tomcat-with-mod_jk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In regards to the Flex 3 LinkButton backgroundColor</title>
		<link>http://www.daveturner.info/blog/flex_linkbutton_backgroundcolor/</link>
		<comments>http://www.daveturner.info/blog/flex_linkbutton_backgroundcolor/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 19:35:59 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=88</guid>
		<description><![CDATA[The background color of Flex 3&#8242;s LinkButton is transparent and that setting doesnt seem to be updateable so visually the LinkButton has no backgroundColor property. Which means the following code snippet does nothing.. (event.target as LinkButton).setStyle("backgroundColor", "#ff0000"); In my case the LinkButton took up the entire space of a GridItem so I was able to [...]]]></description>
			<content:encoded><![CDATA[<p>The background color of Flex 3&#8242;s LinkButton is transparent and that setting doesnt seem to be updateable so visually the LinkButton has no backgroundColor property.</p>
<p>Which means the following code snippet does nothing..</p>
<pre>(event.target as LinkButton).setStyle("backgroundColor", "#ff0000");</pre>
<p>In my case the LinkButton took up the entire space of a GridItem so I was able to set the backgroundColor of the parent and that worked fine for me.</p>
<pre>var gridItemRef:GridItem = (event.target as LinkButton).parent as GridItem;
gridItemRef.setStyle("backgroundColor", "#ff0000");</pre>
<p>Another method to support a background Color for a LinkButton would be to wrap it in a canvas, but I do not like the added overhead for the canvas.  Skinning may also provide a solution but it just wasn’t necessary in my case.</p>
<p>I wonder what was Adobe&#8217;s thought process behind not allowing the background color to be edited?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/flex_linkbutton_backgroundcolor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE 6..  how i despise thee..</title>
		<link>http://www.daveturner.info/blog/ie-6-how-i-despise-thee/</link>
		<comments>http://www.daveturner.info/blog/ie-6-how-i-despise-thee/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:55:06 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=82</guid>
		<description><![CDATA[Time for the semi-annual &#8220;Get caught by an IE6 bug/feature&#8221; exercise. Placing &#8220;javascript:void(0)&#8221; in the href portion of the a tag just doesn’t work for Internet explorer version 6.. A common scripting technique that works fine in almost every other browser looks like the following &#60;a href=&#8221;javascript:void(0)&#8221; onclick=&#8221;myFunction()&#8221;&#62;some link&#60;/a&#62; Internet Explorer 6 doesnt support this.. [...]]]></description>
			<content:encoded><![CDATA[<p>Time for the semi-annual &#8220;Get caught by an IE6 bug/feature&#8221; exercise.</p>
<p>Placing &#8220;javascript:void(0)&#8221; in the <strong>href</strong> portion of the a tag just doesn’t work for Internet explorer version 6.. A common scripting technique that works fine in almost every other browser looks like the following</p>
<p>&lt;a href=&#8221;javascript:void(0)&#8221; onclick=&#8221;myFunction()&#8221;&gt;some link&lt;/a&gt;</p>
<p>Internet Explorer 6 doesnt support this..  instead try this.</p>
<pre><a onclick="myFunction();return false;" href="#"></a>&lt;a href="#" onclick="myFunction();return false;"&gt;some link&lt;/a&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/ie-6-how-i-despise-thee/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Googles Nexus One</title>
		<link>http://www.daveturner.info/blog/googles-nexus-one/</link>
		<comments>http://www.daveturner.info/blog/googles-nexus-one/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 22:13:21 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[newProducts]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=74</guid>
		<description><![CDATA[Googles nexus One.. This is going to be interesting to see how this plays out. Google announces a &#8220;Test&#8221; phone for development purposes that will be released to employees only. Some people like Motley Fool take this announcement for what it is, and believe there will NOT be a GPhone available to the public in [...]]]></description>
			<content:encoded><![CDATA[<p>Googles nexus One.. This is going to be interesting to see how this plays out.</p>
<p>Google announces a <a href="http://googlemobile.blogspot.com/2009/12/android-dogfood-diet-for-holidays.html" target="_new">&#8220;Test&#8221; phone for development purposes</a> that will be released to employees only.</p>
<p>Some people like <a href="http://www.fool.com/investing/high-growth/2009/12/14/no-google-phone-for-you.aspx" target="_new">Motley Fool</a> take this announcement for what it is, and believe there will <strong>NOT</strong> be a GPhone available to the public in the near future.  Others, like the <a href="http://online.wsj.com/article/SB10001424052748703757404574592530591075444.html" target="_new">Wall Street Journal, are announcing</a> it will be available to the public very soon.</p>
<p>I am hoping for the latter and that the <a href="http://androidandme.com/2009/12/news/android-rumor-report-nexus-one-to-cost-199/" target="_new">$200 Nexus One unconfirmed rumor is true</a>. Rumored specs seem to indicate a powerful processor (Qualcomm Snapdragon 1 GHz ARM CPU)  in the device so I am going to guess that the price tag wont be that low. Another article refers to a <a href="http://www.billshrink.com/blog/nexus-one-google-phone-confirmed-details/" target="_new">$500 price tag</a>, which is more likely (if the release is even true).</p>
<p>But one thing is for sure there is <strong>alot</strong> of buzz out there about this.</p>
<p>A $200 GPhone with no cell service is a pretty tempting offer for someone like me to treat as a development product.  A $500 one.. probably not&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/googles-nexus-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple alternative to the Java String replaceAll function</title>
		<link>http://www.daveturner.info/blog/alt-java-string-replaceall/</link>
		<comments>http://www.daveturner.info/blog/alt-java-string-replaceall/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 15:31:03 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=67</guid>
		<description><![CDATA[I ran into some troubles performing a Java String.replaceAll method call involving double quotes. I tried a few suggested work arounds utilizing Pattern and Matcher from java.util.regex but it didn&#8217;t work correctly for me on the first few tries. The quick fix for me was to download the Apache commons Lang library, add it to [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into some troubles performing a Java String.replaceAll method call involving double quotes.</p>
<p>I tried a few suggested work arounds utilizing Pattern and Matcher from java.util.regex but it didn&#8217;t work correctly for me on the first few tries. The quick fix for me was to download the <a href="http://commons.apache.org/lang/" target="_new">Apache commons Lang library</a>, add it to my project and utilize the StringUtils class to perform the string replacement.</p>
<p>here is a quick code blurb demonstrating the StringUtils.replace method.</p>
<pre>import org.apache.commons.lang.StringUtils;
..
String XMLDeclaration = "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;";
soapResp = call.getResponseMessage().getSOAPPartAsString(); // recieving a SoapMessage and I want to remove the XML version declaration
soapResp = org.apache.commons.lang.StringUtils.replace(soapResp, XMLDeclaration, "");
out.println(XMLDeclaration);
out.println("");
out.print(soapResp);
out.println("");</pre>
<p>The Apache commons Lang library contains a ton of useful utilities <a href="http://commons.apache.org/lang/userguide.html">click here for the User guide</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/alt-java-string-replaceall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Daughter Mary</title>
		<link>http://www.daveturner.info/blog/my-daughter-mary/</link>
		<comments>http://www.daveturner.info/blog/my-daughter-mary/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 00:37:42 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=64</guid>
		<description><![CDATA[My Daughter Mary Penelope Turner was born 11/25/2009. She is absolutely beautiful. A new adventure in my life is about to begin.. I am looking forward to it. http://picasaweb.google.com/davetii/TheBirthOfMaryPenelopeTurner]]></description>
			<content:encoded><![CDATA[<p>My Daughter Mary Penelope Turner was born 11/25/2009. She is absolutely beautiful. A new adventure in my life is about to begin.. I am looking forward to it.</p>
<p><a href="http://picasaweb.google.com/davetii/TheBirthOfMaryPenelopeTurner" target="_blank">http://picasaweb.google.com/davetii/TheBirthOfMaryPenelopeTurner</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/my-daughter-mary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with the ThreadLocal class in Java..</title>
		<link>http://www.daveturner.info/blog/fun-with-the-threadlocal-class-in-java/</link>
		<comments>http://www.daveturner.info/blog/fun-with-the-threadlocal-class-in-java/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 17:31:51 +0000</pubDate>
		<dc:creator>Dave Turner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.daveturner.info/blog/?p=59</guid>
		<description><![CDATA[This is an interesting class, one that is probably a building block to many Java based architecture implementations that perform &#8220;state&#8221; management. Recently I came across a scenario where I needed a reference to an HTTPServletRequest object but it was not readily available due to prior architectural decisions. When I say “architectural decisions” I use [...]]]></description>
			<content:encoded><![CDATA[<p>This is an interesting class, one that is probably a building block to many Java based architecture implementations that perform &#8220;state&#8221; management.</p>
<p>Recently I came across a scenario where I needed a reference to an HTTPServletRequest object but it was not readily available due to prior architectural decisions. When I say “architectural decisions” I use the term loosely the architecture I was supporting was pretty much a disaster with too many contributing factors to mention but the application has survived for years and is still in use today.</p>
<p>The application is a Flex 1.5 app (yes there are some still out in the Wild) there were pieces of code that required a reference to the HttpServletRequest instance. Often this reference was required from within a Remote Object call so the HttpServletRequest object was not readily available.</p>
<p>The following code sample provided a reference to the existing HttpServletRequest. This app contained code that made back end calls from Flex 1.5 as well as Flex 3 so it handled  both instances.</p>
<pre>... class named RequestManager
public static HttpServletRequest getHttpRequest() throws Exception
  {
    Class cls;
    try{
      cls = Class.forName("flex.messaging.FlexContext");
    }catch(Exception e){
      cls = Class.forName("flashgateway.Gateway");
    }
     Method meth = cls.getMethod("getHttpRequest", new Class[0]);
     Object retobj = meth.invoke(null);
     if ( retobj == null )
     {
       cls = Class.forName("flashgateway.Gateway");
       meth = cls.getMethod("getHttpRequest", new Class[0]);
       retobj = meth.invoke(null);
     }
     HttpServletRequest req = (HttpServletRequest) retobj;
     return req;
  }</pre>
<p>Specifically what this was used for was the management of Session variables. A session Manager class was utilizing the above-mentioned method to get a reference to the existing Servlet Request object. The code in the SessionManager class that utilized this method looked like this.</p>
<pre>...
HttpServletRequest req = RequestManager.getHttpRequest();
return req.getSession().getAttribute("MYSessionKey").toString();</pre>
<p>This technique worked fine when making Flex Remote Calls but when a Servlet was introduced that needed to utilize the same method calls there was a problem gaining a reference to the HttpServletRequest. Intermediary method calls that existed elsewhere in the code did not contain an argument of HttpServletRequest they utilized the RequestManager to gain this access. This posed a problem when the Servlet wanted to make the method calls that the Remote Object calls relied upon.</p>
<p>So how can the methods called by the Servlet get a reference to the HttpServletRequest?</p>
<p>There where a few possibilities</p>
<li>Overload methods to accept an HttpServletRequest, in this case there where too many methods.</li>
<li>Create a process that utilized a Static class that synchronized a request to guarantee one got a reference to the correct HttpServletRequest.. Its an option but an ugly one.</li>
<li>Utilize the same method Adobe had written to grab a reference to the HttpServletRequest</li>
<p>I was able to reference the source for Adobe&#8217;s <a href="http://opensource.adobe.com/svn/opensource/blazeds/trunk/modules/core/src/flex/messaging/FlexContext.java" target="_new">FlexContext class</a> to see how they did it.</p>
<p>The solution was surprisingly simple.. utilizing the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html" target="_new">ThreadLocal class</a>.</p>
<p>Here is a quick run down of what i did</p>
<p><strong>1. Define a static class that represents a reference to the HttpServletRequest.</strong> This class will be populated by the Servlet.</p>
<pre>package dtii.util;
import javax.servlet.http.HttpServletRequest;
public class MyRequest
{
  private static ThreadLocal requests = new ThreadLocal();
  public static void setRequest(HttpServletRequest req) {
     requests.set(req);
  }

  public static HttpServletRequest getRequest() {
    return requests.get();
  }

  public static void removeRequest(){
    requests.remove();
  }
}</pre>
<p><strong>2. Edit the RequestManager to look for this class</strong>. Feel free to implement in a safer way..</p>
<pre>... RequestManager
public static HttpServletRequest getHttpRequest() throws Exception
{
  Class cls;
  try{
    cls = Class.forName("flex.messaging.FlexContext");
  }catch(Exception e){
    cls = Class.forName("flashgateway.Gateway");
  }

  Method meth = cls.getMethod("getHttpRequest", new Class[0]);
  Object retobj = meth.invoke(null);
	if ( retobj == null )
  {
    cls = Class.forName("flashgateway.Gateway");
    meth = cls.getMethod("getHttpRequest", new Class[0]);
    retobj = meth.invoke(null);
  }
  if ( retobj == null )
  {
    retobj = (HttpServletRequest) MyRequest.getRequest();
  }
   HttpServletRequest req = (HttpServletRequest) retobj;
   return req;
}</pre>
<p><strong>3. In the Executing Servlet define the Class at the begining and than remove it at the end</strong></p>
<pre>import dtii.util.MyRequest;
.. some servlet

public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
	MyRequest.setRequest(req);
	SomeMethod(.. );
	MyRequest.removeRequest();
}</pre>
<p>This technique worked well for what i needed.. its not pretty but it worked.</p>
<p>Would love to hear a suggestion on a better method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daveturner.info/blog/fun-with-the-threadlocal-class-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

