Search code examples
wso2corswso2-das

DAS is not sending CORS header


I am using DAS of wso2. I have a event receiver with input adapter type http. In html using jquery i am sending json to this event by post method. The code is very simple:

<script src="jquery.js"></script>
<script>
$( document ).ready(function() {

  $("#senddata").click(function(){
		$.post("http://localhost:9763/endpoints/ex", '{"event": {"payloadData": {"name": "gggg", "age": 37}}}')
			.done(function( data ) {
				console.log( data );
			});
	});
});
</script>

<body>
<input type="button" value="send" id="senddata"></input>
</body>

The DAS is running in https://localhost:9443 and the app with html and jquery in http://localhost/s. When I execute the app and click in button, the console show a error type "Access-Control-Allow-Origin".

The DAS documentation have a session "CORS Settings for the Analytics REST API" (https://docs.wso2.com/display/DAS300/CORS+Settings+for+the+Analytics+REST+API). I follow this instruction but any result. The error persist.

This is my configuration of web.xml

<filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
        <param-name>cors.allowed.origins</param-name>
        <param-value>*</param-value>
    </init-param>
    <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE,PATCH</param-value>
    </init-param>
    <init-param>
        <param-name>cors.exposed.headers</param-name>
        <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Other hand, when i use RESTClient of firefox the result is correct.

enter image description here


Solution

  • You need to update de web.xml inside: [DAS_HOME]\repository\conf\tomcat\ with the same configuration. This is not happen in previous DAS snapshots but in the 3.0.0 version that´s the config file to update.