如何在jBoss中启用CORS [英] How to enable CORS in jBoss

查看:198
本文介绍了如何在jBoss中启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个HTML5应用程序,它必须从传统的Web服务(Jax-Ws)获得一些值,所以我使用 jQuery.soap 查询这些Web服务以获取响应。我已经通过SOAP UI尝试了我的请求的正确性,并且它们正常工作。

从我的HTML5客户端,我无法从服务器接收SOAP响应,因为在响应中不是 Allow-Control-Allow-Origin 标头设置为*。因此,请求的来源被识别为不允许,并且服务器的响应是错误响应。



错误消息,使用Firebug + Firefox调试我的HTML5项目,是:

锁定的跨源请求:原始标准不允许读取远程资源。您可以通过将资源移至相同的域或激活CORS来解决问题。


$ b

如何在jBoss中启用CORS?

$ b

解决方案

您需要处理遗留的Web服务来解决问题。如上所述,您需要在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>

maven:

 <依赖性> 
< 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:

 <依赖性> 
< groupId> org.apache.tomcat< / groupId>
< artifactId> tomcat-catalina< / artifactId>
< version> 7.0.42< / version>
< scope>提供< / scope>
< / dependency>


I am developing an HTML5 application that has to obtain some values from legacy web-services (Jax-Ws) so I use jQuery.soap to query these web services to obtain responses. I have tried the correctness of my requests with SOAP UI, and they work properly.

From my HTML5 client I cannot receive SOAP responses from the server, because in the response there is not the Allow-Control-Allow-Origin header set to *. So, the origin of the request is recognized as not allowed, and the response of the server is an error response.

The message of the error, debugging my HTML5 project with Firebug + Firefox, is:

Locked cross- origin request: the criterion at the origin does not allow the reading of the remote resource. You can solve the problem by moving the resource to the same domain or activating CORS.

How can I enable CORS in jBoss?

解决方案

You need to deal with your legacy web-services to fix the issue. As mccannf said above you need to add CORS filter in web.xml.

You can use a solution from thetransactioncompany:

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>

maven:

<dependency>
    <groupId>com.thetransactioncompany</groupId>
    <artifactId>cors-filter</artifactId>
    <version>2.5</version>
</dependency>

If you use apache Tomcat you can use built-in 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>

这篇关于如何在jBoss中启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆