在 Silverlight 应用程序的 java servlet 上启用跨域调用
我有一个带有 OData4j 库的 java servlet,我想对其进行配置,以便可以从 Silverlight 应用程序发出 HTTP POST 请求。
我的 web.xml 文件如下所示:
<servlet>
<servlet-name>OData</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>org.odata4j.producer.resources.ODataResourceConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>OData</servlet-name>
<url-pattern>/myService/*</url-pattern>
</servlet-mapping>
我尝试将其添加到我的 web.xml 文件中:
<servlet>
<servlet-name>CrossDomain</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>org.odata4j.producer.resources.CrossDomainResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CrossDomain</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
但它不起作用。我还尝试将“crossdomain.xml”和“clientaccesspolicy.xml”文件添加到我的资源目录中,但这也不起作用。使用 Silverlight 应用程序发送 HTTP POST 请求时,我仍然收到 SecurityException。
任何提示将不胜感激。
谢谢
I have a java servlet with the OData4j library and I want to configure it so I can make HTTP POST request from a Silverlight application.
My web.xml file looks like this:
<servlet>
<servlet-name>OData</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>org.odata4j.producer.resources.ODataResourceConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>OData</servlet-name>
<url-pattern>/myService/*</url-pattern>
</servlet-mapping>
I've tried adding this to my web.xml file:
<servlet>
<servlet-name>CrossDomain</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>org.odata4j.producer.resources.CrossDomainResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CrossDomain</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But it doesn't work. I also tried adding the "crossdomain.xml" and "clientaccesspolicy.xml" files to my resources directory but that also doesn't work. I still get a SecurityException when sending a HTTP POST request with my Silverlight application.
Any hints would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,实例化 CrossDomainResourceConfig 确实启用了“crossdomain.xml”和“clientaccesspolicy.xml”文件。问题是它们可以通过以下 URL 获得:
/myService/crossdomain.xml
和/myService/clientaccesspolicy.xml
。但是,Silverlight 运行时会在服务器根目录中查找这些文件(例如:
/clientaccesspolicy.xml
),通过在服务器根目录中手动添加这两个文件,它解决了该问题。
Turns out that instantiating CrossDomainResourceConfig does enable the "crossdomain.xml" and "clientaccesspolicy.xml" files. The thing is that they are available at the URL:
/myService/crossdomain.xml
and/myService/clientaccesspolicy.xml
.However, the Silverlight runtime looks for those files at the server root (eg:
/clientaccesspolicy.xml
)By adding both of those files manually in the server root, it fixed the problem.