0

AD sal を使用して開発したプラグインがあります。
プラグインは多くの残りの API を公開します。
これらの API は、別のドメインにデプロイされた Web アプリケーションからアクセスされます。
このため、私のアクセスはクロスドメインです。
現在、この種のアクセスにjsonpを使用しています。
私がやろうとしているのは、opendaylight Hydrogen で CORS サポートを有効にすることです。
私がなんとか発見したことから。API を cors-config.xml に追加する必要があります。
しかし、それはうまくいきませんでした。
また、プラグイン Web xml でフィルターを定義しようとしましたが、これも成功しませんでした。

4

1 に答える 1

0

長い検索の後、答えが見つかりました。Hydrogen リリースで CORS サポートを有効にする場合: ODL Web コンテナー (Tomcat) で CORS を有効にします。 1. 次の jar を ODL org.opendaylight.controller.filter-valve-1.4.2 のプラグイン ディレクトリにコピーします。 -SNAPSHOT.jar ドンロード リンク: 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

  1. ./configuration/tomcat-server.xml に移動します。
  2. ファイルに、次のマークされた行を追加します。

    <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>
    
  3. ODLの下の構成ディレクトリにcors-config.xmlファイルを作成します。このファイルには、tomcat のフィルター定義が含まれています。ここでパスを定義し、restconf api で行ったように CORS フィルターを追加できます。
<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>
于 2015-02-03T11:23:04.333 に答える