Jun 19

Enabling ColdFusion Debugging On JBoss 4.2.0

Posted by James Netherton | Tuesday 19 June 2007 8:06 AM | In ColdFusion

After much googling, I haven’t worked out where all of the JVM arguments are set when JBoss is started. I did notice upon server startup this message:

JAVA_OPTS:

Which was followed by what appeared to be the JVM arguments. So I opened up bin/run.sh and sure enough, a string is built up containing various JVM arguments. I simply hacked the required JVM arguments onto the end of the string to make everything work.

Look for the commented line:

# Setup JBoss specific properties

And edit the JAVA_OPTS variable below so that it includes:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

The next time you start JBoss, you’ll be able to perform ColdFusion debugging from Eclipse!

Jun 17

Plant a virtual tree!

Posted by James Netherton | Sunday 17 June 2007 6:06 AM | In Blogging

Dorothy Perkins have a nice viral campaign in order to help get 40,000 new trees planted within the UK. For every 100 virtual trees planted, they, in association with the Woodland Trust will plant one real tree. They’re also launching a clothing range where a percentage of the profits will go to the Woodland Trust.

It’s also a good use of Adobe Flash. Check it out here.

Jun 16

Using Apache reverse proxying with IIS

Posted by James Netherton | Saturday 16 June 2007 7:06 AM | In Apache

Apache and IIS can live quite happily together on the same server, handling requests when they are on configured on different ports. What happens if you want to run both solutions in the same environment on port 80?

To start with IIS will capture all traffic on the port that its configured to run off of, in which case Apache will never receive any traffic.

One solution could be to run websites within IIS off a different port and set Apache to listen on port 80. You could then use a technique called reverse proxying to pass requests for specific URLs, domains and paths to IIS, allowing it to serve up content as if it were running off port 80.

Here’s an example of how you might configure something like this using Apache. The usual caveats on ensuring you backup your Apache configuration file apply.

1. Add the website IP’s that you want Apache to listen out for under the listen directive of the Apache config file.

2. Ensure that the following Apache modules are loaded:

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule rewrite_module modules/mod_rewrite.so

3. Configure the IIS websites you want to use for reverse proxying, so that they run off a port other than port 80 (8080 for example).

4. Back to the Apache config file, enable virtual hosts.

NameVirtualHost *:80

5. Configure virtual hosts for each site where you want to direct requests to IIS.

<VirtualHost *:80>

    ServerName www.domain.com

    RewriteEngine On

    ProxyVia Block

    ProxyPreserveHost On

    RewriteRule ^/(.*)$ http://hostname:8080/$1 [P,L]

</VirtualHost>

What’s happening above is that any requests received under www.domain.com are rewritten to another domain name under port 8080.

6. Restart Apache and IIS.

That should be all there is to the process. Browse to one of the domains that you have configured for reverse proxying to see whether everything has worked. You’ll know for sure that its working if you view the Apache access_log file and see that it is logging requests for sites that are running off IIS.

Jun 06

Saving CFHTTP file content

Posted by James Netherton | Wednesday 06 June 2007 8:06 AM | In ColdFusion

I really should study the ColdFusion documentation more closely….

I never knew you could save the contents returned from CFHTTP to a specified file without having to use CFFILE as there are file and path attributes. Observe…

<cfhttp url="http://www.google.co.uk/intl/en_uk/images/logo.gif" file="googleLogo.gif" path="#expandPath('.')#"/>

Jun 06

HTTP_RAW_POST_DATA with nusoap on PHP 5.2.2

Posted by James Netherton | Wednesday 06 June 2007 8:06 AM | In PHP

I just fixed a weird issue where I had a Flex client invoking a PHP Nusoap SOAP web service.

Whenever the client was making requests to the PHP page, I kept getting the SOAP service overview HTML content being returned. I var_dumped the $HTTP_RAW_POST_DATA and it was returning NULL.

I had to change:

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

to:

$HTTP_RAW_POST_DATA = file_get_contents("php://input");

Everything started working correctly after making this change.

Apparently there is a bug in PHP 5.2.2 with HTTP_RAW_POST_DATA and SOAP.

Jun 04

Error connecting to JVM for debugging at localhost:5005

Posted by James Netherton | Monday 04 June 2007 17:06 PM | In ColdFusion

I finally got the ColdFusion 8 debugger working from Eclipse. Kola, in my previous post, suggested tinkering with the JVM.config file and he was right. I installed ColdFusion in multiserver mode on top of JRun and it seems the necessary entries are not added to the JVM.config file in order for the ColdFusion debugger to operate.

So I stole and amended some of the parmeters that are used for the other ColdFusion debugger – FusionDebug. Here’s what I needed to add into the JVM.config file:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

The address parameter should match the port that the ColdFusion debugger is listening on.

Now I can set breakpoints in my code and step through it at runtime!

Jun 03

A new chart type for ColdFusion

Posted by James Netherton | Sunday 03 June 2007 15:06 PM | In ColdFusion

Following up on my previous post about customizing CFCHART, I bring news of hidden charts that are not available via the standard ColdFusion CFCHART tag.

Note: The following example will only work with ColdFusion 8.

Fire up the WebCharts Java application (see my previous post on how to do this) and you’ll notice that some charts types available are not supported via the CFCHART tag:

  • Gauge Charts
  • Gantt Charts
  • Heatmaps

I spent some time looking at how I could use ColdFusion to generate one of these chart types. The following example shows how to create a simple gauge chart. So without further ado, I introduce the gaugeChart custom tag:

WebCharts expects XML descriptions of the chart styles and the chart data models in order for the chart engine to output the chart image, swf etc…

<!--- Create the xml chart style structure --->
<cfsavecontent variable="style">
<cfoutput><gauge font="#attributes.font#-#attributes.fontSize#-bold">
	<knobStyle clipKnob="false" clipHand="false" size="#attributes.knobSize#">
		<paint shadowColor="##FFDDAA" minColor="#attributes.knobColor#"/>
	</knobStyle>
	<handStyle type="#attributes.dialType#" placement="Text" width="3">
		<paint shadowOffsetX="0" shadowOffsetY="0" outlineColor="#attributes.dialOutlineColor#" minColor="##AA0000" maxColor="red" angle="90"/>
	</handStyle>
	<dialStyle startAngle="#attributes.dialStartAngle#">
		<paint minColor="white" maxColor="##333333" isRadial="true"/>
	</dialStyle> 

	<axisStyle scaleMax="#attributes.dialMaxScale#" angleMargin="40" outerMargin="5" limitPlacement="#attributes.dialLimitPlacement#" limitMargin="0" minorTickPlacement="Outer"> <labelStyle isMultiline="false" color="##E2FFFF"/>
		<majorTick width="4" length="12"> <paint shadowColor="black"/></majorTick>
		<minorTick width="2" length="6"/>
		<title angle="-90" ratio="90">#attributes.dialTitle#</title>
		<limits index="0" minValue="#attributes.dialLimitStart#" maxValue="#attributes.dialLimitEnd#" minWidth="12" maxWidth="12">
			<paint minColor="##AA0000" maxColor="##AA0000"/>
		</limits>
	</axisStyle>
	<edgeStyle outerSide="1" innerSize="2" innerSide="10">
		<outer minColor="##666666" angle="-135"/>
		<inner minColor="##333333" maxColor="##CCCCC" angle="45"/>
	</edgeStyle>
</gauge></cfoutput>
</cfsavecontent>

I didn’t manually hack out all of that styling markup. I cheated and used WebCharts to generate it for me. It is then a simple case of replacing the styles that we need control over, with ColdFusion variables.

The next step is to define the data model. Again I used WebCharts to generate the outline for me:

<!--- Create the chart data model --->
<cfsavecontent variable="model">
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<XML type="default">
	<COL>1000</COL>
	<ROW col0="#attributes.dialValue#">Sample 0:</ROW>
</XML></cfoutput>
</cfsavecontent>

Now we are ready to output the chart to our web page:

<!--- Output the chart --->
<cfscript>
    context  = getPageContext();

    chart = createObject("java","com.gp.api.jsp.MxServerComponent");

    svr = chart.getDefaultInstance(context.getServletContext());

    myChart        = svr.newImageSpec();
    myChart.width  = attributes.chartWidth;
    myChart.height = attributes.chartHeight;
    myChart.type   = attributes.chartFormat;
    myChart.style  = style;
    myChart.model  = model;

    chartTag = svr.getImageTag(myChart,"/CFIDE/GraphData.cfm?graphCache=wc50&graphID=");
</cfscript>

<cfoutput>#chartTag#</cfoutput>

As ColdFusion uses the WebCharts Java API via the CFCHART tag, this API is naturally available to any ColdFusion template. We take advantage of this and instantiate an MxServerComponent object.

As you can see, the next stage builds up our chart definition via the myChart variable. You can see that the chart dimensions are being defined and we are assigning our style and data models.

To create the chart we call:

svr.getImageTag(myChart,”/CFIDE/GraphData.cfm?graphCache=wc50&graphID=”);

When we do this, the chart image is written to the default chart cache directory, as defined within the ColdFusion administrator.

Finally we write out the HTML markup needed to view the chart:

<cfoutput>#chartTag#</cfoutput>

What’s with the “/CFIDE/GraphData.cfm?graphCache=wc50&graphID=” path specified on the getImageTag method invocation , I hear you cry!

Again, I have cheated here to make life easier. If you view the HTML source on a web page that a CFCHART image has been embedded into, you will see that the chart image links to /CFIDE/GraphData.cfm. This URL pulls the appropriate chart data into the calling web page.

As a matter of interest, you won’t find any template named GraphData.cfm within the CFIDE directory. /CFIDE/GraphData.cfm is simply a mapping to the ColdFusion charting servlet.

Now for an example of the custom tag calling code. I’m going to use the new ColdFusion 8 server monitoring API to get the amount of used JVM memory:

<cfset adminObj = createObject("component","cfide.adminapi.administrator")/>
<cfset adminObj.login("password")/>

<cfset serverMonitor = createObject("component","cfide.adminapi.servermonitoring")/>

<cfset memstats = serverMonitor.getJvmMemoryStats()/>

<cfset megabyte = 1024 * 1024/>

<cfset used = memstats.usedmemory / megabyte>

<cf_gaugeChart	chartFormat="png"
		chartWidth=200
		chartHeight=200
		dialLimitStart=450
		dialLimitEnd=500
		dialMaxScale=500
		dialTitle="JVM Memory Used"
		dialValue=#getToken(used,'1','.')#>

I won’t explain all of the tag attributes here as they’re all documented within the tag template file. Hopefully the tag call above is fairly self explanatory in terms of how everything works. You set the chart dimensions, some values for the chart upper and lower readout boundaries, a chart title and the format that the chart should be output in. I pipe in the amount of memory used via the dialValue attribute.

Acceptable chart formats are: PNG, SWF, SVG, PDF, EPS, JPG, GIF and TIF.

Here’s an example of what the resulting chart looks like:

Guage Chart

I’ll try and get some examples of creating Gantt, heatmap and treemap charts shortly. Until then, here’s the custom tag.

gaugeChart.zip

Jun 02

Quercus: PHP on ColdFusion 8!!!

Posted by James Netherton | Saturday 02 June 2007 14:06 PM | In ColdFusion

As a short follow up to my PHP on Java post. Sean Corfield has posted an example of scripting PHP within ColdFusion!

Read all about it here.

Jun 02

Jetty in ColdFusion 8?

Posted by James Netherton | Saturday 02 June 2007 10:06 AM | In ColdFusion

I’m currently struggling to get the new ColdFusion Eclipse code debugger working. I have what I think are all of the correct settings within Eclipse and the ColdFusion administrator.

While trying to figure out why things aren’t working, I came across this within the cfusion-out log file:

ColdFusion debugger is listening at port 1511

Curious, I browsed to localhost:1511 and was greeted with a HTTP 404 page with a note saying “Powered by Jetty”. Jetty is a free and open source Java web server and servlet container. As Jetty is small and lightweight, it is commonly used to provide services in Java applications. I wonder what part it plays in the ColdFusion debugging tool.

And if anyone knows why I keep getting “Error connecting to JVM for debugging at localhost:5005″, whenever I try and launch the ColdFusion debugger from Eclipse, please let me know!