This documentation is for WSO2 Data Services Server 3.2.2. View documentation for the latest release.
Enabling CORS for Data Services - Data Services Server 3.2.2 - WSO2 Documentation
||
Skip to end of metadata
Go to start of metadata

You can enable Cross Origin Resource Sharing for data services deployed in WSO2 DSS. As explained below, you have the option of enabling CORS for selected data services or for all the data services. 

To enable CORS in DSS:

  1. Download the following JARs: "cors-filter-2.4.jar" and "java-property-utils-1.9.1.jar".
  2. Copy the JARs to the <DSS_HOME>/repository/components/lib/ directory.
  3. Add the following configurations to the <DSS_HOME>/repository/conf/tomcat/web.xml file. 

    <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>
  4. Edit the <filter-mapping> section in the above configuration to specify whether CORS should be enabled for all data services or only selected data services.

    • To enable CORS for a selected data service, add the service's url as the url pattern:

      <filter-mapping>
      	<filter-name>CORS</filter-name>
      	<url-pattern>/services/example/*</url-pattern>
      </filter-mapping>
    • To enable CORS for multiple data service, you add the urls in a comma separated list:

      <filter-mapping>
      	<filter-name>CORS</filter-name>
      	<url-pattern>/services/sampleservice1/*,/services/sampleservice2/*</url-pattern>
      </filter-mapping>

      Alternatively, you can add two separate filter mappings:

      <filter-mapping>
      	<filter-name>CORS</filter-name>
      	<url-pattern>/services/sampleservice1/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
      	<filter-name>CORS</filter-name>
      	<url-pattern>/services/sampleservice2/*</url-pattern>
      </filter-mapping>
  5. Restart the server.

  • No labels