Note that there are some explanatory texts on larger screens.

plurals
  1. POSOAP service invocation on JavaScript works in Safari but it does not in Chrome or Firefox
    primarykey
    data
    text
    <p>I'm far to be a JavaScript expert and I have to maintain a JS code that invokes a SOAP service. The invocation is performed by means of the cxf-utils.js script. It works fine in Safari, but it does not in Firefox or Chrome. Following, I give the application intuition, the sketch of the involved scripts and code details. </p> <p><strong>Application intuition</strong></p> <p>The application allows to track continuously the location of "friends" in a map by retrieving synthetic friends locations from a soap service accessible through the url:</p> <pre><code>http://127.0.0.1:9884/hqoutput? </code></pre> <p>Such a service provides a collection of friends locations in JSON format. </p> <p><strong>Implementation sketch</strong></p> <p>The application consists of three JS's:</p> <ul> <li><p><em>map.js</em>: handles the map view, draws markers of friends in the map, and controls the requests to the model (<em>i.e.</em> HQOutputImplService.js). </p></li> <li><p><em>HQOutputImplService.js</em>: prepares the service invocation and handles the responses from the service (<em>i.e.</em> (de)serialization, onsuccess and onerror functions).</p></li> <li><p><em>cxf-utils.js</em>: provides some browser compatibility and XML management (<em>cf.</em> <a href="http://cxf.apache.org/docs/javascript-client-code.html" rel="nofollow noreferrer">http://cxf.apache.org/docs/javascript-client-code.html</a>)</p></li> </ul> <p><strong>Code details</strong></p> <p><em>index.html</em></p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;My first map&lt;/title&gt; &lt;link type="text/css" href="css/style.css" rel="stylesheet" media="all" /&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt; &lt;/script&gt; &lt;script type="text/javascript" src="js/map.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/cxf-utils.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/HQOutputImplService.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="map"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><em>map.js</em></p> <pre><code>(function() { window.onload = function() { var outputServ = new hybridqp_hadas_lig_org__HQOutput(); outputServ.url = "http://127.0.0.1:9884/hqoutput?"; // Creating a reference to the mapDiv var mapDiv = document.getElementById('map'); var myPosLat = 48.85889; var myPosLon = 2.29583; // Creating a latLng for the center of the map var latlng = new google.maps.LatLng(myPosLat, myPosLon); // Creating an object literal containing the properties // we want to pass to the map var options = { center: latlng, zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP }; // Creating the map var map = new google.maps.Map(mapDiv, options); // Adding a marker to the map var marker = new google.maps.Marker({ position: new google.maps.LatLng(myPosLat, myPosLon), map: map, title: 'My Position', icon: 'http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png' }); var circleOptions = { center: latlng, radius: 2000, map: map }; // Creating the map var circle = new google.maps.Circle(circleOptions); // Colors used to display friends' markers var colors = new Array('green', 'orange', 'pink', 'red'); // Color to assign to the next friend, rotates modulo the length of the array var icolor = 0; // Associates a tuple_id with its marker, used to remove them when negative tuples arrive: tuple_id -&gt; marker var markers = new Array(); // Counts the number of markers on screen for a particular user: nickname -&gt; n_markers var markerCounter = new Array(); // Color assigned to a friend currently on screen: nickname -&gt; color var friendColor = new Array(); //This is the function called upon success. function processResponse(response) { var jsonStr = response.getReturn(); var jsonArray = eval('(' + jsonStr + ')'); if( jsonArray != null ) { for(var i = 0; i &lt; jsonArray.length; i++) { addOrRemoveFriendMarker(jsonArray[i]); } } } //This is the function called for an error. --&gt; function reportError(error) { alert('error ' + error); } function invokeHQOutput() { outputServ.data(processResponse, reportError); } // Adds a marker to the screen and has side effects on additional variables function addOrRemoveFriendMarker(friend) { // Check whether the tuple is positive or negative if( friend.tuple_sign == 1 ) { //Determine the color to use, depends whether the user has currently an assigned color if( friendColor[friend.nickname] == undefined ) { friendColor[friend.nickname] = colors[icolor]; icolor = (icolor + 1) % colors.length; } var marker = new google.maps.Marker({ position: new google.maps.LatLng(friend.lat, friend.lon), map: map, title: friend.nickname, icon: 'http://gmaps-samples.googlecode.com/svn/trunk/markers/' + friendColor[friend.nickname] + '/blank.png'}); // Add the marker to the array using the tuple_id markers[friend.tuple_id] = marker; // Increment the marker count for the user, check if the value is undefined first if( markerCounter[friend.nickname] == undefined ) markerCounter[friend.nickname] = 1; else markerCounter[friend.nickname]++; } else if( friend.tuple_sign == -1 ){ // Remove the marker from the screen and from the markers array //map.removeOverlay(markers[friend.tuple_id]); markers[friend.tuple_id].setMap(null); delete markers[friend.tuple_id]; // Decrement the counter for this friend's markers, if it has reached 0, delte the friend from the corresponding arrays markerCounter[friend.nickname]--; if( markerCounter[friend.nickname] == 0 ) { delete markerCounter[friend.nickname]; delete friendColor[friend.nickname]; } } } window.setInterval(invokeHQOutput, 5000); } })(); </code></pre> <p><em>HQOutputImplService.js</em> </p> <pre><code>// Definitions for schema: http://hybridqp.hadas.lig.org/ // http://127.0.0.1:9884/hqoutput?xsd=1 // // // Constructor for XML Schema item {http://hybridqp.hadas.lig.org/}data // function hybridqp_hadas_lig_org__data () { this.typeMarker = 'hybridqp_hadas_lig_org__data'; } // // Serialize {http://hybridqp.hadas.lig.org/}data // function hybridqp_hadas_lig_org__data_serialize(cxfjsutils, elementName, extraNamespaces) { var xml = ''; if (elementName != null) { xml = xml + '&lt;'; xml = xml + elementName; if (extraNamespaces) { xml = xml + ' ' + extraNamespaces; } xml = xml + '&gt;'; } if (elementName != null) { xml = xml + '&lt;/'; xml = xml + elementName; xml = xml + '&gt;'; } return xml; } hybridqp_hadas_lig_org__data.prototype.serialize = hybridqp_hadas_lig_org__data_serialize; function hybridqp_hadas_lig_org__data_deserialize (cxfjsutils, element) { var newobject = new hybridqp_hadas_lig_org__data(); cxfjsutils.trace('element: ' + cxfjsutils.traceElementName(element)); var curElement = cxfjsutils.getFirstElementChild(element); var item; return newobject; } // // Constructor for XML Schema item {http://hybridqp.hadas.lig.org/}dataResponse // function hybridqp_hadas_lig_org__dataResponse () { this.typeMarker = 'hybridqp_hadas_lig_org__dataResponse'; this._return = null; } // // accessor is hybridqp_hadas_lig_org__dataResponse.prototype.getReturn // element get for return // - element type is {http://www.w3.org/2001/XMLSchema}string // - optional element // // element set for return // setter function is is hybridqp_hadas_lig_org__dataResponse.prototype.setReturn // function hybridqp_hadas_lig_org__dataResponse_getReturn() { return this._return;} hybridqp_hadas_lig_org__dataResponse.prototype.getReturn = hybridqp_hadas_lig_org__dataResponse_getReturn; function hybridqp_hadas_lig_org__dataResponse_setReturn(value) { this._return = value;} hybridqp_hadas_lig_org__dataResponse.prototype.setReturn = hybridqp_hadas_lig_org__dataResponse_setReturn; // // Serialize {http://hybridqp.hadas.lig.org/}dataResponse // function hybridqp_hadas_lig_org__dataResponse_serialize(cxfjsutils, elementName, extraNamespaces) { var xml = ''; if (elementName != null) { xml = xml + '&lt;'; xml = xml + elementName; if (extraNamespaces) { xml = xml + ' ' + extraNamespaces; } xml = xml + '&gt;'; } // block for local variables { if (this._return != null) { xml = xml + '&lt;return&gt;'; xml = xml + cxfjsutils.escapeXmlEntities(this._return); xml = xml + '&lt;/return&gt;'; } } if (elementName != null) { xml = xml + '&lt;/'; xml = xml + elementName; xml = xml + '&gt;'; } return xml; } hybridqp_hadas_lig_org__dataResponse.prototype.serialize = hybridqp_hadas_lig_org__dataResponse_serialize; function hybridqp_hadas_lig_org__dataResponse_deserialize (cxfjsutils, element) { var newobject = new hybridqp_hadas_lig_org__dataResponse(); cxfjsutils.trace('element: ' + cxfjsutils.traceElementName(element)); var curElement = cxfjsutils.getFirstElementChild(element); var item; cxfjsutils.trace('curElement: ' + cxfjsutils.traceElementName(curElement)); cxfjsutils.trace('processing return'); if (curElement != null &amp;&amp; cxfjsutils.isNodeNamedNS(curElement, '', 'return')) { var value = null; if (!cxfjsutils.isElementNil(curElement)) { value = cxfjsutils.getNodeText(curElement); item = value; } newobject.setReturn(item); var item = null; if (curElement != null) { curElement = cxfjsutils.getNextElementSibling(curElement); } } return newobject; } // // Definitions for service: {http://hybridqp.hadas.lig.org/}HQOutputImplService // // Javascript for {http://hybridqp.hadas.lig.org/}HQOutput function hybridqp_hadas_lig_org__HQOutput () { this.jsutils = new CxfApacheOrgUtil(); this.jsutils.interfaceObject = this; this.synchronous = true; this.url = null; this.client = null; this.response = null; this.globalElementSerializers = []; this.globalElementDeserializers = []; this.globalElementSerializers['{http://hybridqp.hadas.lig.org/}data'] = hybridqp_hadas_lig_org__data_serialize; this.globalElementDeserializers['{http://hybridqp.hadas.lig.org/}data'] = hybridqp_hadas_lig_org__data_deserialize; this.globalElementSerializers['{http://hybridqp.hadas.lig.org/}dataResponse'] = hybridqp_hadas_lig_org__dataResponse_serialize; this.globalElementDeserializers['{http://hybridqp.hadas.lig.org/}dataResponse'] = hybridqp_hadas_lig_org__dataResponse_deserialize; this.globalElementSerializers['{http://hybridqp.hadas.lig.org/}data'] = hybridqp_hadas_lig_org__data_serialize; this.globalElementDeserializers['{http://hybridqp.hadas.lig.org/}data'] = hybridqp_hadas_lig_org__data_deserialize; this.globalElementSerializers['{http://hybridqp.hadas.lig.org/}dataResponse'] = hybridqp_hadas_lig_org__dataResponse_serialize; this.globalElementDeserializers['{http://hybridqp.hadas.lig.org/}dataResponse'] = hybridqp_hadas_lig_org__dataResponse_deserialize; } function hybridqp_hadas_lig_org__data_op_onsuccess(client, responseXml) { console.log('(hybridqp_hadas_lig_org__data_op_onsuccess)'); if (client.user_onsuccess) { var responseObject = null; var element = responseXml.documentElement; this.jsutils.trace('responseXml: ' + this.jsutils.traceElementName(element)); element = this.jsutils.getFirstElementChild(element); this.jsutils.trace('first element child: ' + this.jsutils.traceElementName(element)); while (!this.jsutils.isNodeNamedNS(element, 'http://schemas.xmlsoap.org/soap/envelope/', 'Body')) { element = this.jsutils.getNextElementSibling(element); if (element == null) { throw 'No env:Body in message.' } } element = this.jsutils.getFirstElementChild(element); this.jsutils.trace('part element: ' + this.jsutils.traceElementName(element)); this.jsutils.trace('calling hybridqp_hadas_lig_org__dataResponse_deserializeResponse'); responseObject = hybridqp_hadas_lig_org__dataResponse_deserializeResponse(this.jsutils, element); client.user_onsuccess(responseObject); } } hybridqp_hadas_lig_org__HQOutput.prototype.data_onsuccess = hybridqp_hadas_lig_org__data_op_onsuccess; function hybridqp_hadas_lig_org__data_op_onerror(client) { console.log('(hybridqp_hadas_lig_org__data_op_onerror)'); if (client.user_onerror) { var httpStatus; var httpStatusText; try { httpStatus = client.req.status; httpStatusText = client.req.statusText; } catch(e) { httpStatus = -1; httpStatusText = 'Error opening connection to server'; } client.user_onerror(httpStatus, httpStatusText); } } hybridqp_hadas_lig_org__HQOutput.prototype.data_onerror = hybridqp_hadas_lig_org__data_op_onerror; // // Operation {http://hybridqp.hadas.lig.org/}data // Wrapped operation. // function hybridqp_hadas_lig_org__data_op(successCallback, errorCallback) { this.client = new CxfApacheOrgClient(this.jsutils); var xml = null; var args = new Array(0); xml = this.data_serializeInput(this.jsutils, args); this.client.user_onsuccess = successCallback; this.client.user_onerror = errorCallback; var closureThis = this; this.client.onsuccess = function(client, responseXml) { closureThis.data_onsuccess(client, responseXml); }; this.client.onerror = function(client) { closureThis.data_onerror(client); }; var requestHeaders = []; requestHeaders['SOAPAction'] = ''; this.jsutils.trace('synchronous = ' + this.synchronous); this.client.request(this.url, xml, null, this.synchronous, requestHeaders); } hybridqp_hadas_lig_org__HQOutput.prototype.data = hybridqp_hadas_lig_org__data_op; function hybridqp_hadas_lig_org__data_serializeInput(cxfjsutils, args) { var wrapperObj = new hybridqp_hadas_lig_org__data(); var xml; xml = cxfjsutils.beginSoap11Message("xmlns:jns0='http://hybridqp.hadas.lig.org/' "); // block for local variables { xml = xml + wrapperObj.serialize(cxfjsutils, 'jns0:data', null); } xml = xml + cxfjsutils.endSoap11Message(); return xml; } hybridqp_hadas_lig_org__HQOutput.prototype.data_serializeInput = hybridqp_hadas_lig_org__data_serializeInput; function hybridqp_hadas_lig_org__dataResponse_deserializeResponse(cxfjsutils, partElement) { var returnObject = hybridqp_hadas_lig_org__dataResponse_deserialize (cxfjsutils, partElement); return returnObject; } function hybridqp_hadas_lig_org__HQOutput_hybridqp_hadas_lig_org__HQOutputImplPort () { this.url = 'http://127.0.0.1:9884/hqoutput'; } hybridqp_hadas_lig_org__HQOutput_hybridqp_hadas_lig_org__HQOutputImplPort.prototype = new hybridqp_hadas_lig_org__HQOutput; </code></pre> <p><em>cxf-utils.js</em></p> <p><a href="http://code.google.com/p/gh-lebensmittel/source/browse/src/cxf-utils.js?r=22" rel="nofollow noreferrer">Here the code</a></p> <p><strong>Problem</strong></p> <p>As shown above in HQOutputImplService.js, there is an onsuccess and an onerror code. When scripts run in Safari, it always reaches the onsuccess code (<em>i.e.</em> hybridqp_hadas_lig_org__data_op_onsuccess) while in Firefox and Chrome they always get to the onerror code (<em>i.e.</em> hybridqp_hadas_lig_org__data_op_onerror).</p> <p>Here the screenshots for each browser.</p> <p><em>Safari</em> <img src="https://i.stack.imgur.com/QthE9.png" alt="Safari"></p> <p><em>Firefox</em> <img src="https://i.stack.imgur.com/CiBdh.png" alt="Firefox"></p> <p><em>Chrome</em> <img src="https://i.stack.imgur.com/q3E55.png" alt="Chrome"></p> <p><strong>Questions</strong></p> <p>Actually, I have no idea how to formulate the good questions. So…</p> <p>-Could you please give some clue?</p> <p>-What should I check?</p> <p>-Which further information should I provide here?</p> <p><strong>Update 1</strong></p> <p>By tracing the execution of the JS's, both Chrome and Firefox get the http response code '0'. Additionaly, the developer console of Firefox reports a <a href="http://helpful.knobs-dials.com/index.php/0x80004005_%28NS_ERROR_FAILURE%29_and_other_firefox_errors" rel="nofollow noreferrer">NS_ERROR_FAILURE</a> error whose one of the possible reasons is the attempt to receive data from different origins and thus the <a href="http://www.w3.org/Security/wiki/Same_Origin_Policy" rel="nofollow noreferrer">Same-origine policy</a> is violated. Apparently, it is due to the SOAP request with is done to the localhost (port 9884) and the envelop, serializers, namespace are requested to <a href="http://hybridqp.hadas.lig.org/" rel="nofollow noreferrer">http://hybridqp.hadas.lig.org/</a>. The new questions may be:</p> <ul> <li>Is there a way to enable multiple-origin responses?</li> <li>Should I define <a href="http://hybridqp.hadas.lig.org/" rel="nofollow noreferrer">http://hybridqp.hadas.lig.org/</a> as a localhost alias in my etc/hosts file?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload