为我的插件添加CORS支持
我有一个使用AD sal开发的插件。为我的插件添加CORS支持,cors,opendaylight,Cors,Opendaylight,我有一个使用AD sal开发的插件。 该插件公开了许多rest API。 这些api是从部署在另一个域上的web应用程序访问的。 因此,我的访问权限是跨域的。 目前我正在使用jsonp进行这种访问。 我正在尝试的是在我的opendaylight hydrogen上启用CORS支持。 从我设法发现的。我需要将API添加到cors config.xml中。 但那没用。 我还尝试在插件web xml中定义过滤器,但同样没有成功,是否有人设法让它工作?经过长时间搜索,a找到了答案。 如果您希望在氢气释放
该插件公开了许多rest API。
这些api是从部署在另一个域上的web应用程序访问的。
因此,我的访问权限是跨域的。
目前我正在使用jsonp进行这种访问。
我正在尝试的是在我的opendaylight hydrogen上启用CORS支持。
从我设法发现的。我需要将API添加到cors config.xml中。
但那没用。
我还尝试在插件web xml中定义过滤器,但同样没有成功,是否有人设法让它工作?经过长时间搜索,a找到了答案。 如果您希望在氢气释放时启用cors支持: 在ODL web容器(Tomcat)上启用CORS: 1.将以下jar复制到ODL中的插件目录中 org.opendaylight.controller.filter-valve-1.4.2-SNAPSHOT.jar 下载链接:
<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>
克斯菲尔特
org.apache.catalina.filters.CorsFilter
科尔斯
*
cors.methods
获取、发布、标题、选项、放置、删除
cors.allowed.headers
内容类型、X请求、接受、授权、,
来源,来源,访问控制请求方法,访问控制请求头
cors.exposed.headers
访问控制允许来源,访问控制允许凭据
cors.support.credentials
符合事实的
cors.preflight.maxage
10
克斯菲尔特
克斯菲尔特
/*
<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>