如何在Websphere Application Server Liberty Profile V8.5中定义CORS

Nie*_*ael 14 cors websphere-liberty

是否可以在Websphere Application Server Liberty Profile V8.5中应用跨源资源共享(CORS)?

我搜索了红皮书但却找不到IBM提及它的任何内容.(http://www.redbooks.ibm.com/abstracts/sg248076.html?Open)

不可能像下面这样以编程方式设置标头:

Access-Control-Allow-Origin: *
Run Code Online (Sandbox Code Playgroud)

(http://enable-cors.org/server.html)

Guy*_*uyT 9

您必须将以下jar添加到您的WEB-INF/lib文件夹:

在您web.xml必须添加以下规则:

<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
        <filter-name>CORS</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)


小智 6

从2016年1月的Beta版开始(编辑:现在在Liberty 8559中),WebSphere Liberty本身支持CORS.您只需使用所需的CORS选项配置server.xml,这是一个示例:

<cors domain="/sampleApp/path"
   allowedOrigins="https://alice.com:8090"
   allowedMethods="GET, DELETE, POST"
   allowedHeaders="Accept, MyRequestHeader1"
   exposeHeaders="MyResponseHeader1"
   allowCredentials="true"
   maxAge="3600" />
Run Code Online (Sandbox Code Playgroud)

domain属性适用于您希望此配置应用于的应用程序根目录,这意味着它不会影响任何其他上下文根.其他7个属性完全遵循官方CORS规范(https://www.w3.org/TR/cors/),因此它们非常自我解释.

链接到测试版:https://developer.ibm.com/wasdev/blog/2016/01/15/beta-websphere-liberty-and-tools-january/