MSXML.DOMDocument doesn't support any method? - jscript

I'm having a strange trouble with MSXML2.DOMDocument ActiveX Object. Here is my code:
var doc = new ActiveXObject('MSXML2.DOMDocument.6.0');
doc.LoadXML('<test1><test2>Hello!</test2></test1>');
The typeof the doc variable is object and there was no exceptions at the first line of the code. However the second line throws that the object doesn't support the method. I can't really understand why, but it seems that is fails on any method (I tried LoadXML, Load, Async and etc) with the same message.

Your biggest problem is that the method name is loadXML(), not LoadXML(). The method name is case-sensitive.
If you ever get stuck trying to figure out the methods supported by a particular COM object, you can use PowerShell to list the available methods like this:
powershell "new-object -COM MSXML2.DOMDocument.6.0 | gm"
Also, if you find that you're having trouble navigating the DOM with that string, you might need to include <?xml version="1.0"?> before the <test> tag. Some of MS's XML parsers are pedantic about valid, well-formed XML structure. I'm not sure how strict or tolerant MSXML2.DOMDocument.6.0 is about such things.

Related

Does the Windows shell support multiple shell property handlers?

I was just trying out the Windows app sample for the Recipe Property Handler which is available here and I modified it to be used on .doc files instead of .recipe files:
const WCHAR c_szRecipeFileExtension[] = L".doc";
But, this seemed to overwrite the previous Office handler's properties with itself, which begs the question, does the Windows shell support multiple shell property handlers, or can you only use one at a time for a given file type? If its possible, what am I missing from the code or logic in the sample?
I couldn't find a concrete answer on MSDN for this question.
No.
But there is a variant you can use (I dont like it but I dont see any additional variant). Save previous Property handler CLSID when you register your own. And when shell request the property that you cannot process - just create instance of previous handler and pass request to them.
CoCreateInstance(SavedCLSID, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IPropertyStore, PS)
PS.QueryInterface(IInitializeWithStream, IWS)
IWS.Initialize(Stream, Mode)
PS.GetValue(AUnknownKey)

NonProxyHosts usage with Groovy HttpBuilder

If I create my httpBuilder as shown below (assume that a proxyUsername IS set, so setCredentials is called), then calls to httpAddress-es that are passed in properly are routed through the proxy. However, the Application has some http calls that are within the local network. Can http.nonProxyHosts be used to work around this and bypass the Proxy? If so, how? Use System.setProperty? Or something on HttpBuilder?
HTTPBuilder httpBuilder = new HTTPBuilder(httpAddress)
httpBuilder.setProxy(webProxyHost, webProxyPort, webProxyProtocol)
if (proxyUsername) {
httpBuilder.client.getCredentialsProvider().setCredentials(
new AuthScope(webProxyHost, webProxyPort),
new UsernamePasswordCredentials(proxyUsername, proxyPassword))
}
}
In the code above, all of the various named elements (webProxyHost, etc) are declared as String and set accordingly.
In answer to the question in the above comment, our primary 'nonProxyHost' need was for 'localhost' which is there by default. Thus this ceased to be an issue. Did not ever really find out how to accomplish this as it is somewhat version-specific on HttpClient.
You can set the System property:
System.setProperty('http.nonProxyHosts', myNonProxyHosts)
However, if you call 'setProxy' on HttpBuilder, even if you call 'useSystemProperties' it will not. This is in their documentation, just not obvious!
Finally, you might be able to call:
httpBuilder.client.params.setParameter('http.nonProxyHosts', myNonProxyHosts)
But I do not know for sure if that is the property name and documentation of those properties is hard to find. Worse - those 'params' are deprecated - you are supposed to use the better 'config' classes, though once again finding comprehensive documentation on all the parameters for that is not the easiest! Wish I could have been of more help!

node-soap: "Non-whitespace before first tag."

My WSDL is valid, but this error (in title) occurs on soap.createClient. The WSDL is hosted on the server. After inspecting the node-soap source, it looks like if I can disable the "strict" flag in the WSDL class this error will not occur, but I can't seem to figure out how to disable this. I tried passing options to the createClient method like so:
soap.createClient(wsdl, { strict: false }, callback);
But that does not seem to resolve this issue. Unfortunately I can't share the WSDL, but you can be sure that it passes validation, and there is no "non-whitespace" before the opening tag. I'm fairly certain that if I can somehow disable the strict option in the wsdl class that would resolve the issue. Has anyone had this occur before?
The short answer is no, it doesn't appear to be possible given the current code base. I would suggest opening a pull request to add the functionality you need.
The code you've referenced above, soap.createClient ends up using the wsdl.js file which, when it parses the wsdl, ends up in a function _parse. This function creates the sax parser but hard codes passing in true for the strict mode (link to code):
p = sax.parser(true),
The soap module depends on the sax module, which takes in a boolean to determine if strict mode should be enabled (link to code):
sax.parser = function (strict, opt) { return new SAXParser(strict, opt) }
So the options you pass to the createClient are not used in the creation of the sax parser, and instead it's set to strict mode. However, like I said above, a pull request could fix this since it looks like the options are passed all the way to the creation of the WSDL object, so it'd just be a matter of creating the sax parser with that option passed, instead of true.
(Keep in mind the code additionally creates a sax parser within another function, xmlToObject (link to source), but here again hard codes the strict mode)

Error calling method in java-class 'ClassA' 'org.my.ClassB' is incompatible with 'org.my.ClassB'

I have two classes org.my.ClassA and org.my.ClassB both classes are in the same package org.my in the WEB-INF/src in the same database.
ClassA has the method public add(org.my.ClassB newB){...}.
In SSJS I have a code block in which I call ClassA.add(ClassB) which normally works fine. Until some unknown point where the Server can't see that org.my.ClassB === org.my.ClassB and it returns the error (message translated from German maybe looks different in English version):
error calling method 'add(org.my.ClassB)' in java-class 'ClassA'.
'org.my.ClassB' is incompatible with 'org.my.ClassB'.
and it points to my line in the SSJS: ClassA.add(ClassB);
What I tried so far:
First I added the line importPackage(org.my); to my SSJS Code. No luck.
I tried to add another method add(Object newB) and then cast the object to ClassB but same result. The error does not seem to come from the java class its from the SSJS code because it cant find the method with an argument of the type org.my.ClassB. But if I test the object in the SSJS code it returns org.my.ClassB.
Then I tried to add the classpath to all variables in the SSJS block like: var newB:org.my.ClassB = new org.my.ClassB(). But same result after some time the application breaks with the same error.
From my Point of view it got to do something with the caching of compiled classes, or so because if I clear the database everything works just fine again.
Hope someone has a solution on this.
This is a class loader problem.
You can find more details about the issue in the answer from Frantisek Kossuth:
See here more details: Meaning of java.lang.ClassCastException: someClass incompatible with someClass

Remove Single Metaclass Method

I've been starting to learn Groovy and am currently looking at the metaclass functionality. I have seen the examples of adding a new method, and removing all methods, but nothing about removing a single method. For example:
String.metaClass.foo = {delegate.toUpperCase()}
String.metaClass.bar = {delegate.toLowerCase()}
with the obvious side-effects. Now I have seen that you can say
String.metaClass = null
To remove all of the methods. I would expect one could say something along the lines of
String.metaClass.foo = null
to remove String.foo(), but have String.bar() remain, however this statement does not seem to have any effect. Is there a way to say method foo() should no longer be defined, without effecting bar() or any other added methods?
If you search this webpage for "remove method" it says that you should be able to remove a method using the exact syntax you've proposed above. But I tested it, and you're right, it doesn't seem to work.
A workaround is to assign a closure that throws MissingMethodException, which is what happens by default when you call a method that doesn't exist, e.g.
// Add method
String.metaClass.foo = {delegate.toUpperCase()}
// Remove method
def removeMethod = {throw new MissingMethodException()}
String.metaClass.foo = removeMethod
Admittedly, this is not the most pleasing solution.
As a followup, I posted a bug report here:
https://issues.apache.org/jira/browse/GROOVY-4189
And the documentation has been changed now
See the bug report for the reason this was never implemented
Don's answer is the best way around this

Resources