Monday, August 10, 2009
Good books on EAI and Agile Programming
Ajax: Xpath-enabled Json queries
requestList( "class=TibjmsAdmin&method=getTopics&xpath=/*/*/name", "name", isAsync, topicList );2) Java Method call: On the Server-side, this request will execute the method TibjmsAdmin.getTopics() and create a Java object with some code similar to this:
if( className.equals("TibjmsAdmin") ) { // TODO: use ClassLoader (security?) Object invokee = jmsAdmin; } ... others ... // get specified method on specified class className = invokee.getClass().getName(); Class c = Class.forName(className); // className is TibjmsAdmin Method m = c.getMethod(method,argClasses); // method is getTopics, argClasses is null // invoke method and get return object returnObj = m.invoke(invokee, argObs);3) Java to XML: the next step is now to serialize this Java object to XML. I like to use XStream for this purpose because its extremly simple and straight-forward.
XStream xstream = new XStream(); String xml = xstream.toXML(returnObj);If the returned object does not produce the required results, you can do some magic by plugging in an XStream 'Converter' (not shown here). 4) Apply Xpath: Now that that we have the XML, we can apply the specified XPath to fiddle out the data that is really interesting for us. The following code will create a list of selected XML nodes.
NodeList nl = XmlUtils.selectNodeList(docBuilder,xmlString,xpath);
StringBuffer sb = new StringBuffer("");
for( int i=0;i<nl.getLength();i++ ) {
Node node = nl.item(i);
sb.append("<" + node.getNodeName() + ">" );
sb.append( node.getTextContent() );
sb.append("" );
}
sb.append("\n
");
5) Return Json result: finally return the Json object back to the Browser using the Json tools.
JSONObject json = XML.toJSONObject(xml);
response.setContentType("text/plain");
if( out.equals("pretty") ) // pretty JSON
response.getWriter().print( json.toString(2) );
else // or not
response.getWriter().print( json.toString() );
Windows NT Service configuration
To debug current Windows Service configuration, try 'sc' on a command console.
For example 'sc query' pretty much shows the same configuration information as the registry tree which defines Windows services:
My Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
There's an interesting Windows Resource Kist that includes service configuration tools.
For example instsrv.exe to run ANY other .exe application as Windows service
Consistent Subversion icons in Windows and Eclipse
Debugging Visual C++ applications
Sometimes, the simplest trick is the best. I'm sure you all know this, but to debug a Windows application (for exampe a Windows NT Service), call 'DebugBreak'. In many situations this can be more handy than setting a breakpoint.
DebugBreak();
How to spawn a command shell under windows 'system' user
This trick can be useful if you want to debug user permission issues with a Windows NT service that logs on under "Local System account" (the default).
First, figure out your current system time:
C:\>time
The current time is: 6:15:18.57
Second, use the 'at' command to start an interactive command shell when the next minute starts:
C:\>at 6:16 /interactive cmd
Now inside this new command shell, try your command which is run under this new user.
Windows DLL load order
- The directories listed in the App Path registry key (if any)
- The directory where the executable module for the current process is located.
- The current directory.
- The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
- The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
- The directories listed in the PATH environment variable.
KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\test.exeAdd a sub-key named Path, set it's value to the full path of the DLL, for example:
