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

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

问题描述

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

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.

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

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.

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

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

Locked cross-origin request:源端的条件不允许读取远程资源.您可以通过将资源移动到同一个域或激活 CORS 来解决问题.

如何在 jBoss 中启用 CORS?

How can I enable CORS in jBoss?

推荐答案

您需要处理旧的 Web 服务以解决问题.正如 mccannf 上面所说,您需要在 web.xml 中添加 CORS 过滤器.

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>

行家:

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

如果你使用 apache Tomcat 你可以使用内置的 CorsFilter:

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天全站免登陆