简体   繁体   English

使Glassfish响应OPTIONS HTTP方法调用

[英]Making Glassfish respond to OPTIONS HTTP-method call

I'm trying to develop an HTML-page with Javascript/JQuery code that interacts with a SOAP web service running on Glassfish. 我正在尝试使用Javascript / JQuery代码开发一个HTML页面,该页面可与Glassfish上运行的SOAP Web服务进行交互。

I'm trying to do the web service call as a POST HTTP-method request using AJAX. 我正在尝试使用AJAX将Web服务作为POST HTTP方法请求进行。 The problem is that the web service is running on a different server than where the page is served from, which, because of the cross-domain policy, results in my browser (Firefox) first doing an OPTIONS HTTP request to determine if the web service will allow the POST request. 问题在于,Web服务在与提供页面的服务器不同的服务器上运行,由于跨域策略,导致我的浏览器(Firefox)首先执行OPTIONS HTTP请求,以确定该Web服务是否将允许POST请求。 The web service running on Glassfish won't respond to this OPTIONS request. 在Glassfish上运行的Web服务将不会响应此OPTIONS请求。

I've seen that this can be configured in other application servers, by setting Access-Control-Allow-Origin to a pattern that recognizes all origins that should be accepted (for instance '*' to accept any request). 我已经看到可以通过将Access-Control-Allow-Origin设置为可识别应接受的所有来源(例如,接受任何请求的“ *”)的模式来在其他应用程序服务器中进行配置。 How do I make Glassfish respond to the OPTIONS request? 如何使Glassfish响应OPTIONS的请求?

Glasfish answeres to that OPTIONS request with: Glasfish通过以下方式回答了该OPTIONS请求:

   Response Header:
      X-Powered-By[Servlet/3.0]
      Server[GlassFish Server Open Source Edition 3.0.1]
      Allow[GET, HEAD, POST, TRACE, OPTIONS]
      Content-Length[0]
      Date[Wed, 30 Mar 2011 14:57:39 GMT]

So the question is: Where to add that additional HTTP-Header? 所以问题是:在哪里添加该额外的HTTP标头? I've absolutely no idea! 我绝对不知道! Maybe someone else can help? 也许有人可以帮忙吗?

I've decided for now to avoid doing a cross-domain call (which should avoid the OPTIONS request from being sent) by deploying a proxy web service on the server on which the web page is hosted. 我现在已经决定通过在托管网页的服务器上部署代理Web服务来避免进行跨域调用(应避免发送OPTIONS请求)。

I don't have access to the server yet and I don't yet know a lot about it, so I hope that this will be possible to do. 我还没有访问服务器的权限,对此我也不了解,所以我希望可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM