Examining the GraphML which is sent between client and server can give valuable hints for troubleshooting. This article explains how to retrieve the GraphML.
Get the GraphML which is sent from the client to the server
The simplest method to get the GraphML which is sent from the client is to write it to the console before sending the
graph:
trace(roundtripHandler.outputIOHandler.write(graphCanvas.graph));
roundtipHandler.run();
|
At the server, it is possible to write the GraphML to a file.
Java server: To write the graph which is sent
in the request, place the following lines at the beginning of the
doGet() or
doPost() method:
InputStream inputStream = new GraphDecoder().getGraphInputStream(request, GraphRoundtripSupport.PARAM_GRAPH);
OutputStream outputStream = new FileOutputStream("filename.graphml");
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) >= 0) {
if (len > 0) {
outputStream.write(buffer, 0, len);
}
}
inputStream.close();
outputStream.close();
|
.NET server: To write the graph which is sent in the request, place the following lines at the beginning of the
ProcessRequest method:
string encoded = context.Request.Params[GraphRoundtripSupport.ParamGraph];
if (null != encoded)
{
string encodingStr = context.Request.Form["graphEncoding"];
string graphXml = new GraphDecoder().decodeGraph(encoded, encodingStr);
Stream inStream = new MemoryStream(Encoding.UTF8.GetBytes(graphXml));
if (null != inStream)
{
Stream outStream = new FileStream("filename.graphml", FileMode.Create);
byte[] buffer = new byte[1024];
int len;
while ((len = inStream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, len);
}
outStream.Close();
inStream.Close();
}
}
|
Get the GraphML which is sent from the server to the client
Again, the easiest method to get the GraphML is to write it to the Flex Builder's console. The GraphML can be retrieved via the xml property of the
RoundtripEvent.XML_LOADED event. Before calling run, add an event handler to the
RoundtripHandler:
roundtripHandler.addEventListener(RoundtripEvent.XML_LOADED, function(evt:RoundtripEvent):void {
trace(evt.xml);
}); |
Writing the GraphML at the server is simple, too.
GraphRoundtripSupport offers a
sendGraph (Java) or
SendGraph method which can take a
FileOutputStream or
FileStream, respectively.
support.sendGraph(g, new FileOutputStream("filename.graphml"), "UTF-8");
|
How to interpret the GraphML
Examining the GraphML can be very useful in troubleshooting when some data or styles get lost during a roundtrip. The following section explains how to find the most common data.
Attribute Mappers
If an attribute mapper is missing, you'll first have to look at the key section at the top of the GraphML for a line like:
xmlns:xalan="http://xml.apache.org/xslt"><key id="d5" for="node" attr.name="mappername" attr.type="string"/> |
Where mappername is the name you have registered that attribute with. If such a key is missing, the attribute is not registered. To find the contents of that mapper, you'll have to browse the GraphML for data elments whose
key attribute corresponds to the
id of the key element above:
xmlns:xalan="http://xml.apache.org/xslt"><data key="d5">content</data> |
Styles
In Flex/.NET compatible GraphML Styles and labels are also stored in attribute mappers:
<key id="d1" for="node" attr.name="style" attr.type="complex"/>
<key id="d2" for="node" attr.name="labels" attr.type="complex"/>
<key id="d6" for="edge" attr.name="style" attr.type="complex"/>
<key id="d7" for="edge" attr.name="labels" attr.type="complex"/>
<key id="d11" for="port" attr.name="style" attr.type="complex"/> |
Realizers
In Java compatible GraphML, the realizers are also stored in attribute mappers. Labels are part of the realizers:
<key id="d0" for="node" yfiles.type="nodegraphics"/>
<key id="d1" for="edge" yfiles.type="edgegraphics"/> |