我正在开发一个HTML5应用程序,它必须从遗留Web服务(Jax-Ws)中获取一些值,因此我使用jQuery.soap来查询这些Web服务以获取响应。我已经使用SOAP UI尝试了我的请求的正确性,并且它们正常工作。
从我的HTML5客户端,我无法从服务器接收SOAP响应,因为在响应中没有 Allow-Control-Allow-Origin 标头设置为*。因此,请求的来源被识别为不允许,并且服务器的响应是错误响应。
使用Firebug + Firefox调试我的HTML5项目的错误信息是:
锁定的跨源请求:原点的标准不允许读取远程资源。您可以通过将资源移动到同一域或激活CORS来解决问题。
如何在jBoss中启用CORS?
答案 0 :(得分:3)
您需要处理遗留的网络服务以解决问题。正如上面提到的mccannf,你需要在web.xml中添加CORS过滤器。
您可以使用来自交易公司的解决方案:
的web.xml:
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
行家:
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.5</version>
</dependency>
如果你使用apache Tomcat,你可以使用内置的CorsFilter:
的web.xml:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
的pom.xml:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
答案 1 :(得分:0)
如果您在本地工作,则可以修改standalone.xml文件。
按照以下答案修改您的xml过滤器部分: https://stackoverflow.com/a/39215400/10623693
答案 2 :(得分:0)
我已解决此问题,将WAPDL(Web应用描述语言)禁用为web.xml:
var addressPoints = [
[-37.8839, 175.3745188667, "571"],
[-37.8869090667, 175.3657417333, "486"],
[-37.8894207167, 175.4015351167, "807"],
[-37.8927369333, 175.4087452333, "899"],
[-37.90585105, 175.4453463833, "1273"],
[-37.9064188833, 175.4441556833, "1258"],
[-37.90584715, 175.4463564333, "1279"],
[-37.9033391333, 175.4244005667, "1078"],
[-37.9061991333, 175.4492620333, "1309"],
[-37.9058955167, 175.4445613167, "1261"],
[-37.88888045, 175.39146475, "734"],
[-37.8950811333, 175.41079175, "928"],
[-37.88909235, 175.3922956333, "740"],
[-37.8889259667, 175.3938591667, "759"],
[-37.8876576333, 175.3859563833, "687"],
];
var tiles = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="//openstreetmap.org/copyright">OpenStreetMap</a> contributors, Points © 2012 LINZ'
});
var map = L.map('map', {
center: L.latLng(-36.848461, 174.763336),
zoom: 5,
layers: [tiles]
});
var mcg = L.markerClusterGroup({
chunkedLoading: true,
//singleMarkerMode: true,
spiderfyOnMaxZoom: false
});
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title });
marker.bindPopup(title);
mcg.addLayer(marker);
}
map.addLayer(mcg);