如何找到我的Web服务的URL? [英] How do I find the URL of my web service?

查看:692
本文介绍了如何找到我的Web服务的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这似乎是一个愚蠢的问题,但我无法找到有关此问题的任何信息。
我有一个java Web服务(使用NetBeans生成),在Web服务类中,我想知道部署Web服务的URL。
例如,如果我在本地glassFish服务器上部署Web服务,则Web服务位于http:// localhost:8080 / MyService /,其中MyService是我的服务名称。
我需要知道此URL的原因是因为我的Web服务生成了一些我需要在此URL上提供的文件。例如,Web服务调用返回一个URLhttp:// localhost:8080 / MyService / report.html
我找到了一些关于WebServiceContext的链接但是我无法获得我的URL Web服务正在运行。

I know this might seem a stupid question but I am just not able to find any information regarding this question. I have a java web service (generated using NetBeans) and inside the web service class I would like to know the URL at which the web service was deployed. For example, if I am deploying the web service on my local glassFish server, the web service is available at "http://localhost:8080/MyService/" where "MyService" is the name of my service. The reason I need to know this URL is because my web service generates some files that I need to make available at this URL. For example, the web service call returns a URL "http://localhost:8080/MyService/report.html" I have found some links about "WebServiceContext" but I am not able to get the URL at which my web service is running.

已编辑

澄清:在MyWebService.java类内部我想查找我的网址部署了服务(在这种情况下,我的Web服务运行在http:// localhost:8080 / MyService /,但是一旦它部署在生产服务器上,此URL就会更改)

To clarify: Inside MyWebService.java class I want to find out the URL at which my web service was deployed (in this case, my web service is running at "http://localhost:8080/MyService/", but once it is deployed on a production server, this URL will change)

推荐答案

如果您在询问如何找到您的servlet容器正在侦听的主机名(例如localhost或www.example.com),那么您有一个几个选项:

If you are asking how to find the hostname (e.g. 'localhost' or 'www.example.com') that your servlet container is listening to you have a few options:


  • 添加在部署时设置的配置点(例如配置文件,系统属性)

  • 查看您的servlet容器是否通过JMX公开任何虚拟主机配置或读取其配置文件(例如 tomcat hosts

  • 查找服务器的IP地址并执行DNS查找以获取其配置的主机名

  • 检查传入的HttpServletRequest的'Host'标头

  • Add a configuration point that is set at deployment time (e.g. config file, system property)
  • Look into if your servlet container exposes any 'virtual host' configuration via JMX or read its config files (e.g. tomcat hosts)
  • Find the IP Address of the server and do a DNS lookup to get its configured hostname
  • Inspect the 'Host' header of the incoming HttpServletRequest

String hostname = request.getRequestHeader(Host);

这篇关于如何找到我的Web服务的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆