<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Andrew Schwabe&apos;s Blog - JRun</title>
			<link>http://blog.schwabe.net/index.cfm</link>
			<description>Flex and CF and all things Wack.</description>
			<language>en-us</language>
			<pubDate>Fri, 10 Sep 2010 17:50:34 -0400</pubDate>
			<lastBuildDate>Thu, 11 Jan 2007 02:00:00 -0400</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>aschwabe@schwabe.net</managingEditor>
			<webMaster>aschwabe@schwabe.net</webMaster>
			
			
			
			
			
			<item>
				<title>Server side HTTP Post using JSP</title>
				<link>http://blog.schwabe.net/index.cfm/2007/1/11/Server-side-HTTP-Post-using-JSP</link>
				<description>
				
				&lt;p&gt;Ok, so I&amp;nbsp;use a rapid application development technology (ColdFusion or PHP) most of the time because customers demand such quick turnaround.&amp;nbsp; This time I needed to go back to goold old Java and do some integration.&lt;/p&gt;
&lt;p&gt;Our email list management service (Sound-Off 3) manages people&apos;s email lists and lets them schedule mailings, etc.&amp;nbsp; I needed to integrate a website build on JRun (using Java Server Pages aka jsp) so that when people register, it relays the info to Sound-Off 3.&lt;/p&gt;
&lt;p&gt;In ColdFusion, you can easily do this with a CFHTTP tag.&amp;nbsp; In JSP it is a little more involved.&amp;nbsp; My struggle is your benefit, b/c here is the code that does it in JSP.&lt;/p&gt;
&lt;p&gt;This code will do an HTTP POST from the WEB SERVER to the remote site, all behind the scenes on the server.&amp;nbsp; The &amp;quot;parameters&amp;quot; string contains the form values that will be sent to the remove server.&amp;nbsp; Note the leading/trailing &amp;amp;&apos;s and that the form values must be URL encoded.&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Arial&quot;&gt;&lt;strong&gt;try&lt;br /&gt;
&lt;/strong&gt;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; String stuff = null;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; String pagecontent = &amp;quot;&amp;quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; String parameters = &amp;quot;&amp;amp;message=hello+world&amp;amp;&amp;quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; java.net.URL url = new java.net.URL(http://www.yourhost.com/page.cfm);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setRequestMethod(&amp;quot;POST&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setRequestProperty(&amp;quot;Content-Length&amp;quot;, &amp;quot;&amp;quot; + Integer.toString(parameters.getBytes().length));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setRequestProperty(&amp;quot;Content-Language&amp;quot;, &amp;quot;en-US&amp;quot;); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setRequestProperty(&amp;quot;Content-Type&amp;quot;, &amp;quot;application/x-www-form-urlencoded&amp;quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setDoInput(true); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setDoOutput(true); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setUseCaches(false); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; conn.setAllowUserInteraction(true);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; java.io.DataOutputStream printout = new java.io.DataOutputStream (conn.getOutputStream ());&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printout.writeBytes (parameters);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printout.flush ();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printout.close ();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream())); &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((stuff = in.readLine()) != null)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pagecontent += stuff; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; in.close(); &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Arial&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %&amp;gt;success! &amp;lt;%&lt;br /&gt;
}&lt;br /&gt;
&lt;strong&gt;catch&lt;/strong&gt; (Exception e) &lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; %&amp;gt;error!&amp;lt;%&lt;br /&gt;
}&lt;br /&gt;
%&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Arial&quot;&gt;And thats it!&amp;nbsp;&amp;nbsp; You can (and should) do further error checking by examinging the contents of &amp;quot;pagecontent&amp;quot; which will have the html code returned from remote website.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=&quot;Arial&quot;&gt;Have fun...&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
				
				</description>
						
				
				<category>JRun</category>				
				
				<category>Java</category>				
				
				<pubDate>Thu, 11 Jan 2007 02:00:00 -0400</pubDate>
				<guid>http://blog.schwabe.net/index.cfm/2007/1/11/Server-side-HTTP-Post-using-JSP</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>ColdFusion MX and JRun 4</title>
				<link>http://blog.schwabe.net/index.cfm/2005/10/19/ColdFusion-MX-and-JRun-4</link>
				<description>
				
				&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;Ok, is anybody else frustrated that between JRun 3 and JRun4, the ability to let users log into the JMC and see only their own JVMs was lost ?&amp;nbsp; Back in the good ole&apos; days, you could assign a JCM to a JMC user and all was happy...&lt;/p&gt;
&lt;p&gt;Anyway, i sought an answer to this for quite a while and never found a solution out there and Macromedia seems to be skirting the issue, so i said screw it, and came up with my own solution.&amp;nbsp; Note: This solution is for LINUX, not windows.&amp;nbsp; Sorry windows folks, you will have to try to adapt this solution.&amp;nbsp; Hope it works out.&lt;/p&gt;
&lt;p&gt;Requirements:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Some experience with ColdFusion and JRun (4 preferably) &lt;/li&gt;
    &lt;li&gt;ColdFusion (any version, including CFMX running on JRun4) &lt;/li&gt;
    &lt;li&gt;JRun 4 - remember this is a tool for letting people restart JVMs on JRun &lt;/li&gt;
    &lt;li&gt;sudo installed on your Linux server (if you don&apos;t know what sudo is, leave right now -- im serious) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the smart people using Linux, here is the general concept:&lt;/p&gt;
&lt;ol dir=&quot;ltr&quot;&gt;
    &lt;li&gt;
    &lt;div&gt;Provide some place for your users to log in (this is your responsibility).&amp;nbsp; This is where you will provide the links for these users to restart their JVMs.&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Provide them with ColdFusion (cfml) pages that do a &amp;lt;cfexecute&amp;gt; to stop/start the specified JVMs&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;Configure sudo on your server to allow the coldfusion user to run Jrun commands as root&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div&gt;When a user chooses to stop/restart a server, sudo makes sure it is run with the proper permissions&lt;/div&gt;
    &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;NOTE:&amp;nbsp; This is not an exercise in security.&amp;nbsp; Use this technique as you want, but this comes with no warranty expressed or implied.&amp;nbsp; If you get burned, I don&apos;t want to know about it.&amp;nbsp; Use with care, as this is what worked on OUR servers, not YOURS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;3&quot;&gt;Step 1: Configure sudo on your Linux Server&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ok, this step will allow the request to &amp;quot;restart&amp;quot; a JVM to run from somebody&apos;s web browser.&amp;nbsp; First, find out what user the ColdFusion server is running as.&amp;nbsp; If you have access to telnet or ssh for the server (you better, if you are doing this), then do a ps -ef and you should be able to easily figure out what user the ColdFusion server is running as:&lt;/p&gt;
&lt;blockquote dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;
&lt;p&gt;&lt;strong&gt;nobody&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3853&amp;nbsp; 2484&amp;nbsp; 0 15:17 ?&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 00:00:00 /opt/coldfusionmx/bin/cfusion -start default&lt;br /&gt;
^^^^^^^^&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In this case, it is the user &amp;quot;nobody.&amp;quot;&lt;/p&gt;
&lt;p&gt;Ok, now edit the /etc/sudoers file and allow user &amp;quot;nobody&amp;quot; to execute the jrun admin program:&lt;/p&gt;
&lt;blockquote dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;
&lt;p&gt;Cmnd_Alias&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JRUN=/opt/jrun4/bin/jrun&lt;br /&gt;
nobody&amp;nbsp; ALL = NOPASSWD: JRUN&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is not a lesson in how to use sudo or configure the sudoers file.&amp;nbsp; If you want that, &lt;a href=&quot;http://www.courtesan.com/sudo/man/sudoers.html&quot;&gt;go here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Ok, now the user &amp;quot;nobody&amp;quot; can run the command /opt/jrun4/bin/jrun as root without being asked for a pssword. yum.&lt;/p&gt;
&lt;p&gt;Obviously if your jrun4 is installed somewhere else, don&apos;t be silly, change the path to where yours is installed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;font size=&quot;3&quot;&gt;Step 2: Write some nifty CFML Code&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;Here are&amp;nbsp;several code segments.&amp;nbsp; Use them as you see fit.&amp;nbsp; This isn&apos;t a complete application -- it will require you to figure out how to assemble them to meet your needs.&amp;nbsp; The variable #servername# is the name of the JVM you want to start/stop/etc.&lt;/p&gt;
&lt;blockquote dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&lt;strong&gt;Check to see if a JVM is running or not:&lt;/strong&gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&amp;lt;cfset servername = &amp;quot;jvm_server&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;cfexecute&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name=&amp;quot;/usr/bin/sudo&amp;quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arguments=&amp;quot;-u root /opt/jrun4/bin/jrun -status #servername#&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; variable=&amp;quot;status_info&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; timeout=&amp;quot;20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/cfexecute&amp;gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&lt;strong&gt;Stop the JVM:&lt;/strong&gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&amp;lt;cfset servername = &amp;quot;jvm_server&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;cfexecute&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name=&amp;quot;/usr/bin/sudo&amp;quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arguments=&amp;quot;-u root /opt/jrun4/bin/jrun -stop #servername#&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; variable=&amp;quot;status_info&amp;quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; timeout=&amp;quot;20&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/cfexecute&amp;gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&lt;strong&gt;Start the JVM:&lt;/strong&gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;&amp;lt;cfset servername = &amp;quot;jvm_server&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;cfexecute&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name=&amp;quot;/usr/bin/sudo&amp;quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arguments=&amp;quot;-u root /opt/jrun4/bin/jrun -nohup&amp;nbsp;-start #servername#&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/cfexecute&amp;gt;&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;Notice: When starting a JVM, we use the &amp;quot;-nohup&amp;quot; argument - this makes it not keep open a shell connection.&amp;nbsp; It also means we can&apos;t get back useful info about the JVM starting up.&amp;nbsp; The others have something useful returned in the &amp;quot;status_info&amp;quot; variable.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;Well thats about it.&amp;nbsp; Have fun.&amp;nbsp; I have to run off and fix somebody else&apos;s universe now.&lt;/p&gt;
&lt;p dir=&quot;ltr&quot; style=&quot;MARGIN-RIGHT: 0px&quot;&gt;ciao&lt;/p&gt;
&lt;/div&gt;
				
				</description>
						
				
				<category>JRun</category>				
				
				<category>ColdFusion</category>				
				
				<pubDate>Wed, 19 Oct 2005 02:00:00 -0400</pubDate>
				<guid>http://blog.schwabe.net/index.cfm/2005/10/19/ColdFusion-MX-and-JRun-4</guid>
				
			</item>
			
		 	
			</channel></rss>