是否可以在Websphere Application Server Liberty Profile V8.5中应用跨域资源共享(CORS) ?
我搜索了红皮书,但找不到IBM提到任何关于它的事情。(http://www.redbooks.ibm.com/abstracts/sg248076.html?Open)
这是不是的可能性,我设置头编程像这样:
Access-Control-Allow-Origin: *
(http://enable-cors.org/server.html)
您必须将以下jar添加到您的WEB-INF/lib
文件夹:
- cors-filter-1.8.jar
- java-property-utils-1.9.jar
在你的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>
从2016年1月的测试版(编辑:现在是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" />
domain属性用于您希望应用此配置的应用程序根,这意味着它不会影响任何其他上下文根。其他7个属性完全遵循官方CORS规范(https://www.w3.org/TR/cors/),因此它们非常不言自明。
链接到测试版:https://developer.ibm.com/wasdev/blog/2016/01/15/beta-websphere-liberty-and-tools-january/
从ArthurDM扩展到CORS:文档页没有给我足够的解释。我的设置是这样的,我想和大家分享一下:
- 使用自由配置文件8.5.5.9。所以CORS添加到自由配置文件不再只是在测试中。
- 使用JavaEE批处理并连接批处理,将其所有数据放入存储库(而不是内存)。
- 我想使用batchManagement-1.0功能的其余api的批,它带来的。
- 角1。
最终,下面的cors设置成功了:
<cors domain="/ibm/api"
allowedOrigins="http://localhost:9080"
allowedMethods="GET, POST, PUT, DELETE"
allowedHeaders="Accept, Accept-Language, Content-Language, Content-Type"
exposeHeaders="Content-Type"
allowCredentials="true"
maxAge="3600" />
祝你好运,希望能有所帮助。
对于那些在使用IBM Websphere Application Server并寻找应用CORS的答案时正在寻找解决方案的人。(你应该这样做编程)我知道op正在寻找一个答案不使用java代码或其他…这可能对其他人有帮助。编写一个过滤器,允许您以编程方式设置响应标头。例如:
public class YourFilter implements javax.servlet.Filter{
@Override
public void doFilter(ServletRequest request,ServletResponse servletResponse , FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse ) servletResponse ;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers","Access-Control-Allow-Origin, X-Requested-With", bla,bla...);
}
}