JavaScript上的SOAP服务调用在Safari中有效,但在Chrome或Firefox中不起作用
我远不是JavaScript专家,我必须维护调用SOAP服务的JS代码。调用通过cxf-utils.js脚本执行。它在Safari中运行良好,但在Firefox或Chrome中不起作用。接下来,我给出了应用程序的直觉、相关脚本的草图和代码细节 应用直觉 该应用程序允许通过从可通过url访问的soap服务检索合成朋友位置,从而连续跟踪地图中“朋友”的位置:JavaScript上的SOAP服务调用在Safari中有效,但在Chrome或Firefox中不起作用,javascript,google-chrome,firefox,soap,cors,Javascript,Google Chrome,Firefox,Soap,Cors,我远不是JavaScript专家,我必须维护调用SOAP服务的JS代码。调用通过cxf-utils.js脚本执行。它在Safari中运行良好,但在Firefox或Chrome中不起作用。接下来,我给出了应用程序的直觉、相关脚本的草图和代码细节 应用直觉 该应用程序允许通过从可通过url访问的soap服务检索合成朋友位置,从而连续跟踪地图中“朋友”的位置: http://127.0.0.1:9884/hqoutput? 这样的服务以JSON格式提供朋友位置的集合 实施草图 该应用程序由三个JS
http://127.0.0.1:9884/hqoutput?
这样的服务以JSON格式提供朋友位置的集合
实施草图
该应用程序由三个JS组成:
- map.js:处理地图视图,在地图中绘制好友标记,并控制对模型的请求(即hqoutputinmplservice.js)
- HQOutputImplService.js:准备服务调用并处理来自服务的响应(即(反)序列化、onsuccess和onerror函数)
- cxf-utils.js:提供一些浏览器兼容性和XML管理(cf.)
我的第一张地图
map.js
(函数(){
window.onload=函数(){
var outputServ=新的hybridqp_hadas_lig_org_uuhqoutput();
outputServ.url=”http://127.0.0.1:9884/hqoutput?";
//创建对mapDiv的引用
var mapDiv=document.getElementById('map');
var myPosLat=48.85889;
var myPosLon=2.29583;
//创建地图中心的板条
var latlng=新的google.maps.latlng(myPosLat,myPosLon);
//创建包含属性的对象文字
//我们想通过地图
变量选项={
中心:拉特林,
缩放:15,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
//创建地图
var map=new google.maps.map(mapDiv,options);
//向地图添加标记
var marker=new google.maps.marker({
职位:新google.maps.LatLng(myPosLat,myPosLon),
地图:地图,
标题:“我的位置”,
图标:'http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png'
});
变量循环次数={
中心:拉特林,
半径:2000,
地图:地图
};
//创建地图
var circle=新的google.maps.circle(circleOptions);
//用于显示好友标记的颜色
var colors=新数组(“绿色”、“橙色”、“粉色”、“红色”);
//要指定给下一个朋友的颜色,按数组长度进行旋转
var-icolor=0;
//将tuple_id与其标记关联,用于在负元组到达时删除它们:tuple_id->marker
var markers=新数组();
//统计特定用户屏幕上的标记数:昵称->n_标记
var markerCounter=新数组();
//屏幕上当前分配给朋友的颜色:昵称->颜色
var friendColor=新数组();
//这是成功的功用。
函数processResponse(响应){
var jsonStr=response.getReturn();
var jsonArray=eval(“(“+jsonStr+”)”);
if(jsonArray!=null){
for(var i=0;i
函数报告错误(错误){
警报(“错误”+错误);
}
函数invokeHQOutput(){
outputServ.data(processResponse,reportError);
}
//在屏幕上添加一个标记,并对其他变量产生副作用
函数addOrRemoveFriendMarker(朋友){
//检查元组是正元组还是负元组
if(friend.tuple_sign==1){
//确定要使用的颜色,取决于用户当前是否具有指定的颜色
if(friendColor[friend.昵称]==未定义){
friendColor[friend.昵称]=颜色[icolor];
icolor=(icolor+1)%colors.length;
}
var marker=new google.maps.marker({
位置:新建google.maps.LatLng(friend.lat,friend.lon),
地图:地图,
标题:friend.昵称,
图标:'http://gmaps-samples.googlecode.com/svn/trunk/markers/“+friendColor[friend.昵称]+”/blank.png'});
//使用tuple_id将标记添加到数组中
markers[friend.tuple_id]=标记;
//增加用户的标记计数,首先检查值是否未定义
if(markerCounter[friend.昵称]==未定义)
markerCounter[friend.昵称]=1;
其他的
markerCounter[朋友.昵称]++;
}
else if(friend.tuple\u符号==-1){
//从屏幕和标记阵列中删除标记
//map.removeOverlay(标记[朋友]。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My first map</title>
<link type="text/css" href="css/style.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript" src="js/map.js"></script>
<script type="text/javascript" src="js/cxf-utils.js"></script>
<script type="text/javascript" src="js/HQOutputImplService.js"></script>
</head>
<body>
<div id="map"></div>
</body>
</html>
(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 -> marker
var markers = new Array();
// Counts the number of markers on screen for a particular user: nickname -> n_markers
var markerCounter = new Array();
// Color assigned to a friend currently on screen: nickname -> 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 < jsonArray.length; i++) {
addOrRemoveFriendMarker(jsonArray[i]);
}
}
}
//This is the function called for an error. -->
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);
}
})();
// 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 + '<';
xml = xml + elementName;
if (extraNamespaces) {
xml = xml + ' ' + extraNamespaces;
}
xml = xml + '>';
}
if (elementName != null) {
xml = xml + '</';
xml = xml + elementName;
xml = xml + '>';
}
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 + '<';
xml = xml + elementName;
if (extraNamespaces) {
xml = xml + ' ' + extraNamespaces;
}
xml = xml + '>';
}
// block for local variables
{
if (this._return != null) {
xml = xml + '<return>';
xml = xml + cxfjsutils.escapeXmlEntities(this._return);
xml = xml + '</return>';
}
}
if (elementName != null) {
xml = xml + '</';
xml = xml + elementName;
xml = xml + '>';
}
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 && 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;