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

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)

Related

Cant figure out what these errors happening on my webstore? Anyone help, posting the error content

enter image description here
No idea whats going with these errors code, i dont understand why is it saying anonymous and its giving me security concerns
Strictly speaking, those are warnings (not errors). Nothing is broken, but some things may be running sub-optimally. The alerts are noting that the code on your site is preloading a number of assets but not using them right away. This may indicate that your site is unnecessarily using priority resources to bring those resources in.
Beneath the warning message, you are seeing what is known as a "call stack" - it's the chain of functions that have been called to get to the point that resulted in that warning message. There are two kinds of functions in Javascript: named functions and anonymous functions.
Named functions are what you might normally think of as a function. You declare it with something like:
function doSomething(parameter){
// Some awesome code here
}
And later call it as:
doSomething(some_input);
However, in Javascript we can also create un-named, aka anonymous, functions in-line. This is often done for 'callback' functions, or functions that serve as a part B to the main function's part A, especially when part A does something asynchronously.
For example, if we want to fetch a file and then do something with it once it loads, we would make an asynchronous file call and then run our callback function once it loads. If we're using a library like jQuery as a helper to make that call, our code might look something like this:
function getPageAndDoStuff(url, callback){
jQuery.get(url, callback)
}
// We can declare a named function to do our stuff...
function justLogIt(html){
console.log(html);
}
getPageAndDoStuff('/cart', justLogIt);
Alternatively:
// We can just declare an inline anonymous function to do that
getPageAndDoStuff('/cart', function(html){
console.log(html);
})
The latter is a common design pattern for many types of tasks, but you'll note that the function we pass around doesn't have a name. When something happens and we look at the call stack to see the order of functions that have been called to get us to that point, what name would we print? Each unnamed function in our chain is simply called "(anonymous)"
Going back to your posted image, there is nothing in what you're showing that indicates a cause for serious concern. The script file 'rocket-loader' is possibly pre-loading a few assets that it doesn't need to, so you may be able to boost your site's performance by tweaking whatever parameters 'rocket-loader' uses to be more selective in what you are pre-loading.

Haskell: How to test a Spock app that uses wreq?

I've written a very simple app in Haskell using Spock and wreq. I want to write some tests, but I'm not sure how to do it.
All the app does is make an HTTP request to another server and translate the JSON response into a human-friendly message. Here is the code if it helps. I want to write a test that asserts the human-friendly message is correct given a certain JSON response.
In Ruby, I would mock out the HTTP client, in this case wreq, to control the JSON response I get, but I'm not sure how, or even if, to do that in Haskell.
From what I've gathered out of my research, it sounds like type-class-constrained type variables are the way to go, which looks like dependency injection to me, but I'm unsure how to do this within the context of Spock and wreq.
The Spock testing tutorial describes how to test Spock at the IO Application level which sounds great. The part I'm unsure about is how to "inject" a mock HTTP client to control the JSON response.
Any help is appreciated!
If we want to support different methods of making request, we must abstract over them. You could make your handlers accept as argument a function that performs HTTP requests, and then pass different functions for testing and production. If you have more than one related function, put them in a record (the handle pattern).
If we are using cabal-install > 2.0 (with the new-* commands) another possible option is to use a module signature to switch implementations between the test suite and the final executable app. This solution also makes heavy use of the internal convenience libraries feature of Cabal.
The basic idea is this: we put our Spock application in its own library, but do not make it depend on wreq directly. Instead, we declare in the same library a signature Requests.hsig like this:
signature SomeSpockApp.Requests where
import Data.Aeson (FromJSON)
data Token
doGET :: FromJSON a => String -> Token -> IO a
It defines a high-level interface for performing HTTP requests. The code in the library will import this signature. For the rest of the code in the library, SomeSpockApp.Requests is just another module.
Next, we define a convenience library that will provide an actual module SomeSpockApp.Requests (same name as the signature, except that now it is a hs file). It will contain the "mock" code. Of course the definition of doGET must be compatible with the signature.
We also define another convenience library with another SomeSpockApp.Requests module. This one should depend on wreq and fulfill the methods of our signature using wreq's functions.
In the test suite, we should depend on both our Spock app library and the mock library. The names of the signature and of the mock implementation module line up perfectly, so nothing more needs to be done. (If the names dont' match, we can use a mixins stanza in the cabal file to rename the module).
In the app executable, we should depend on both our Spock app library and the wreq-using library.

MSXML.DOMDocument doesn't support any method?

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.

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!

JsConfig<MyClass>.ExcludePropertyNames example, not working for me

Trying to exclude properties from a model from being included during serialization.
I am using the following syntax:
JsConfig<MyTestClass>.ExcludePropertyNames = new[] { "ShortDescription" };
Just after that I have the following:
return (from o in __someProvider.GetAll() select (new
{
o.Name,
o.ShortDescription
o.InsertDate
}).TranslateTo<MyTestClass>()).ToList()
However once result is returned from the method, it still contains "ShortDescription" field in the Json. Am I doing something wrong?
JsConfig<T>.ExcludePropertyNames appears to be checked only once for each type, in a static constructor for TypeConfig<T>. Thus, if you are configuring ExcludePropertyNames in your service class, just before returning your response, it might be too late -- the TypeConfig properties may already be set up and cached for MyTestClass. I was able to reproduce this.
A more reliable alternative is to move all of your JsConfig<T> configuration to your AppHost setup code.
If you really do need to do this in your service class, e.g. if you are only conditionally excluding property names, then an alternative approach would be to ensure that JsConfig.IncludeNullValues is false (I believe it is by default) and in your service code set ShortDescription to null when appropriate.

Resources