How to enable CORS in jBoss

19,143

Solution 1

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>

Solution 2

you can modify the standalone.xml file, if you are working locally.

modify your filters part of your xml as in the flollowing answer: https://stackoverflow.com/a/39215400/10623693

Share:
19,143
user140888
Author by

user140888

Updated on June 09, 2022

Comments

  • user140888
    user140888 almost 2 years

    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?