如何获得java web start服务端发布地址

   最近公司产品要加入帮助功能,当触发热键F1时打开浏览器,显示帮助文档页面,触发的过程以及如何调用浏览器不用多说了,当时遇到的问题是:帮助的文档HTML是放在服务端发布的,我们都知道要打开一个浏览器页面需要知道其路径,http://IP:port/...
如何获取应用程序发布路径呢?先来看一个jnlp文件。

<?xml version="1.0" encodoing="utf-8"?>
<jnlp spec="1.0+" codebase="http://IP:port/..." href="...">
...
</jnlp>

 省略部分不是是重点,关键是在codebase那里是一个服务端资源路径,可以利用jnlp相关API(注意,在一般的JDK API文档中找不到API描述,应该从javaws.jar包中获取)解析codebase:

URL url = null;
try {
  BasicService basicService = (BasicService)ServiceManager.lookup     ("javax.jnlp.BasicService");
  if(basicService!=null){
	url = basicService.getCodeBase();
  }
 } catch (UnavailableServiceException e) {
	e.printStackTrace();
}

  

 这个URL就是获得的发布地址,就可以根据各自需要解析域名或是IP端口了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Spring Boot集成Apache Axis2发布Web Service服务端的示例: 1. 首先,需要在pom.xml中添加Axis2和Spring Boot的依赖: ```xml <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-webapp</artifactId> <version>1.7.9</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 2. 创建一个简单的Web Service服务端: ```java package com.example.demo; import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.http.HTTPConstants; import org.springframework.stereotype.Component; @Component public class MyService { public String sayHello() { MessageContext messageContext = MessageContext.getCurrentMessageContext(); String userAgent = (String) messageContext.getProperty(HTTPConstants.HEADER_USER_AGENT); return "Hello, " + userAgent + "!"; } } ``` 3. 创建一个发布Web Service服务端的配置类: ```java package com.example.demo; import org.apache.axis2.AxisFault; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.description.AxisService; import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.transport.http.server.AxisHttpService; import org.apache.axis2.transport.http.server.HttpServiceHandler; import org.apache.axis2.transport.http.server.SimpleHttpServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.net.InetSocketAddress; @Configuration public class WebServiceConfiguration { private SimpleHttpServer server; @Autowired private MyService myService; @PostConstruct public void start() throws Exception { ConfigurationContext configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext(); AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration(); AxisService axisService = new AxisService("MyService"); axisService.addParameter("ServiceClass", MyService.class.getName()); axisService.addMethod("sayHello"); axisConfiguration.addService(axisService); HttpServiceHandler handler = new HttpServiceHandler(configurationContext); AxisHttpService axisHttpService = new AxisHttpService(axisConfiguration, handler); server = new SimpleHttpServer(); server.setBindAddress(new InetSocketAddress(8080)); server.deploy(axisHttpService); server.start(); } @PreDestroy public void stop() throws AxisFault { server.stop(); } @Bean public MyService myService() { return new MyService(); } } ``` 4. 运行Spring Boot应用程序并访问http://localhost:8080/axis2/services/MyService?wsdl,应该能够看到服务的WSDL描述。 现在,您已经成功地使用Spring Boot集成Apache Axis2发布Web Service服务端

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值