i have a plugin i developed using AD sal.
the plugin exposes a number of rest API's.
these api's are accessed from a web application deployed on another domain.
because of this my access are cross domain.
currently i am using jsonp for this sort of access.
what i am trying to do is to enable CORS support on my opendaylight hydrogen.
from what i managed to uncover. i need to to add my apis to cors-config.xml.
but that didn't work.
i also tried defining the filter in the plugin web xml but again with no success has anyone manged to get this to work?
Asked
Active
Viewed 182 times
0

Raven
- 713
- 2
- 10
- 21
1 Answers
0
after a long search a found the answer. in case you want to enable cors support on Hydrogen release: enable the CORS on the ODL web container (Tomcat) : 1. Copy the following jar to your plugin dir in the ODL org.opendaylight.controller.filter-valve-1.4.2-SNAPSHOT.jar donload link: https://nexus.opendaylight.org/service/local/repositories/opendaylight.snapshot/content/org/opendaylight/controller/filter-valve/1.4.2-SNAPSHOT/filter-valve-1.4.2-20141001.225558-591.jar
- Go to ./configuration/tomcat-server.xml
In the file add the following marked line:
<Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="" unpackWARs="false" autoDeploy="false" deployOnStartup="false" createDirs="false"> <Realm className="org.opendaylight.controller.security.ControllerCustomRealm" /> <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="web_access_log_" suffix=".txt" resolveHosts="false" rotatable="true" fileDateFormat="yyyy-MM" pattern="%{yyyy-MM-dd HH:mm:ss.SSS z}t - [%a] - %r"/> <!--add this line!--> <Valve className="org.opendaylight.controller.filtervalve.cors.FilterValve" configurationFile="configuration/cors-config.xml"/> </Host> </Engine>
- Create cors-config.xml file in configuration dir under ODL. The file contains filter definitions for tomcat. here you can define your path and add the CORS filters to it as was done for restconf api.
<Host> <!-- Filters are allowed here, only serving as a template --> <filter-template> <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</param-value> </init-param> <init-param> <param-name>cors.allowed.headers</param-name> <param-value>Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers </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> <init-param> <param-name>cors.support.credentials</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>cors.preflight.maxage</param-name> <param-value>10</param-value> </init-param> </filter-template> <Context path="/restconf"> <filter> <filter-name>CorsFilter</filter-name> <!-- init params can be added/overriden if template is used> --> </filter> <!-- references to templates without <filter> declaration are not allowed --> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </Context> </Host>

Raven
- 713
- 2
- 10
- 21