如何为我的REST API启用CORS支持。如何将CORS支持添加到WAS Liberty中的REST API中
我在这里发现了一个泽西特定的例子,但是我如何在Liberty/ApacheWink中做到这一点? CORS Java server side implementation
如何为我的REST API启用CORS支持。如何将CORS支持添加到WAS Liberty中的REST API中
我在这里发现了一个泽西特定的例子,但是我如何在Liberty/ApacheWink中做到这一点? CORS Java server side implementation
注入HttpServletResponse并发出所需的响应标头。该容器不知道您的资源的CORS要求。
从2016年1月Beta版开始,WebSphere Liberty本身就支持CORS。你只要配置你想要的CORS选项server.xml中,这里有一个例子:
<cors domain="/sampleApp/path"
allowedOrigins="https://alice.com:8090"
allowedMethods="GET, DELETE, POST"
allowedHeaders="Accept, MyRequestHeader1"
exposeHeaders="MyResponseHeader1"
allowallowCredentials="true"
maxAge="3600" />
域名属性是您希望这个配置应用到应用程序根目录,这意味着它不会影响任何其他上下文根源。其他7个属性完全遵循官方的CORS规范(https://www.w3.org/TR/cors/),所以它们非常自我解释。
链接到最新的测试版:https://developer.ibm.com/wasdev/downloads/liberty-profile-beta/