user140888
user140888

Reputation: 609

How to enable CORS in jBoss

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?

Upvotes: 3

Views: 25104

Answers (3)

Omar Cardona
Omar Cardona

Reputation: 1

I have solved this issue, disabling the WAPDL (Web Application Description Language) into the web.xml:

<servlet>
...
        <init-param>
            <param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
            <param-value>true</param-value>
        </init-param>
...
</servlet>

Upvotes: 0

Mo Hamid
Mo Hamid

Reputation: 501

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

Upvotes: 2

scythiang
scythiang

Reputation: 146

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>

Upvotes: 8

Related Questions