weixin_33735676 2014-10-28 14:18 采纳率: 0%
浏览 104

如何在jBoss中启用CORS

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?

  • 写回答

3条回答 默认 最新

  • bug^君 2016-06-02 12:38
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)