Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Wednesday, January 28, 2009

Killer WDDX - Beware!

I came across a rather interesting 'feature' tonight while working on some logging and alerting processes. We have data in a structure that holds raw information about various processes that have occurred. In one of the structure keys there is an XMLObject (coldfusion parsed xml object). See the code snippet below and DO NOT run this on production equipment!!

<cfset stcStruct = StructNew()/>

<cfset xmlDoc = "<myxml><name>Kevin Penny</name></myxml>">
<cfset stcStruct.xml = xmlParse(xmlDoc)/>
<cfset stcStruct.id = 1>

<cfwddx action="cfml2wddx" input="#stcStruct#" output="tmp"/>


This takes a Structure, adds a key of 'xml' and places a parsed xml object in it's position. I'm then serializing the data into wddx via cfwddx as cfml2wddx.

I originally thought it was the date fields that I had in the structure, so I removed those, but the problem was the xml object's serialization.

Here's the error I get along with a partial dump:
java.lang.StackOverflowError

....
at java.beans.Introspector.instantiate(Introspector.java:1438)
at java.beans.Introspector.findExplicitBeanInfo(Introspector.java:410)
at java.beans.Introspector.(Introspector.java:359)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.(Introspector.java:368)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.(Introspector.java:368)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.(Introspector.java:368)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.(Introspector.java:368)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.(Introspector.java:368)
at java.beans.Introspector.getBeanInfo(Introspector.java:222)
at java.beans.Introspector.getBeanInfo(Introspector.java:208)
at coldfusion.wddx.BeanSerializer.writeObject(BeanSerializer.java:48)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)
at coldfusion.wddx.BeanSerializer.writeObject(BeanSerializer.java:120)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)
at coldfusion.wddx.BeanSerializer.writeObject(BeanSerializer.java:120)
at coldfusion.wddx.WddxOutputStream.writeObject(WddxOutputStream.java:310)

I've submitted this as a bug to Adobe #75230.

Thursday, July 24, 2008

XML - XSL Stylesheet references another URL Access Denied

I just ran accross an interesting issue.

When generating an XML file in ColdFusion with an associated xsl style sheet reference in the xml head -= in Internet Explorer 7 I was getting this Error:
<link href="http://careers.jobs2web.com/view/xsl/job.xsl" type="text/xsl" rel="stylesheet">

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


Access is denied.

The href attribute was pointing to a generic URL that was not the same URL as the file was being served up from. IE did not like this.

Once I changed this to be cgi.server_name instead - it worked as expected.

Firefox didn't care one way or the other - it rendered the file just fine, regardless of whether the xsl was on a different URL that the XML file was being served up on.

Wonder if this is deemed as some security breach?? Strange indeed.

Wednesday, May 21, 2008

Merging 2 + XML Documents with different Encoding Types

Problem:
I have the task of merging 2 XML documents together that differ in their encoding types. One is declared as a UTF-8 (8bit UCS Transformation format) doc, the other the ISO-8859-1 format type (Latin Alpha No. 1). I wanted to do it w/o parsing the xml as well, as that's an expensive operation and with large documents can be problematic. Well, I figured, this is easy! I'll do the following:
  • Create a String Buffer to hold the new Large XML
  • Strip the Root Nodes and any xml header (doctype/?xml etc)
  • Write each xml doc to the String Buffer
  • Append the Root Node Back to the Main String
  • Close the String Buffer
  • Have a snack
XML Doc 1:
<?xml version="1.0" encoding="UTF-8"?>
<jobs>
<job>
<jobtitle>Job 1</jobtitle> ...
</job>
</jobs>
XML Doc 2:
<?xml version="1.0" encoding="iso-8859-1"?>
<jobs>
<job>
<jobtitle>Job 2</jobtitle> ...
</job>
</jobs>


Turns out, that only works well if the XML documents you're attempting to merge are of the same encoding type. Any ideas on a work around?

Solution:
What I did, is I specified an encoding type for a FileWriter object, and followed the same process, but had to write the file to disk specifying a unified encoding type, then read the file back.

This worked ok, but I am looking at alternatives like going to Binary and back to String again, but for now, this is my best available option.