Ask is moving to Stack Overflow and! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode


Adding CORS support for my Plugin

asked 2015-01-21 01:25:30 -0800

miclando gravatar image

hi, 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?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2015-02-03 03:21:40 -0800

miclando gravatar image

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:

  1. Go to ./configuration/tomcat-server.xml
  2. 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="" />
        <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"/>
  3. 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.
  <!-- Filters are allowed here, only serving as a template -->

  <Context path="/restconf">
      <!-- init params can be added/overriden if template is used> -->
    <!-- references to templates without <filter> declaration are not allowed -->

edit flag offensive delete publish link more

answered 2016-11-03 02:09:56 -0800

icehong gravatar image

updated 2016-11-14 17:45:31 -0800

I am using Beryllium-SR4 version of odl package, and get filter-valve.jar from the URL : . Then I copied to ./deploy/ directory.

But it seams doesn't work. I got such error from karaf web console Bundles page :

org.apache.catalina,version=[7.0,8) -- Cannot be resolved org.apache.catalina.connector,version=[7.0,8) -- Cannot be resolved org.apache.catalina.valves,version=[7.0,8) -- Cannot be resolved

Then I downloaded catalina jar and copy to deploy directory, then I had to import more jars.

edit flag offensive delete publish link more

answered 2016-11-04 05:21:39 -0800


I've done that in the UniMgr project of ODL. I would suggest looking at this gerrit.

Hope this helps, Alexis

edit flag offensive delete publish link more


Hi Alexis , Thanks. It seems that this patch is merge into beryllium branch, but I still got CORS error when calling a restconf interface form another server . Could you give me a simple guide to open it ?ใ€€ใ€€ใ€€ I have tried miclando's answer but got error in the last comment. Thanks a lot .

icehong ( 2016-11-14 18:01:14 -0800 )edit

@icehong, the patch I've linked is just an example of how to add that functionality. You would have to do the same in your project's configuration. There is an existing wiki page but it's pretty much outdated so I'd rather not linking it here.

adetalhouet ( 2016-11-22 07:07:44 -0800 )edit
Login/Signup to Answer


Asked: 2015-01-21 01:25:30 -0800

Seen: 713 times

Last updated: Nov 14 '16