zoukankan      html  css  js  c++  java
  • CXF 教程 (二)

    将 Service 布署在远端


    1 Overview

    2 Server

    3 Client


    1 Overview

    上例中我们的 Server 和 Client 都是在本地。下面演示如果布署在远端需如何修改。

    2 Server

    因为在启动 Server 时指定了地址,所以需进行如下修改,启动 Server 时使用参数指定地址

    HelloServer.java

    public class HelloServer {
    
    	public static void main(String[] args) {
    		// Create our service implementation
    		HelloService helloWorldImpl = new HelloServiceImpl();
    		String defaultUrl = "http://localhost:9000/Hello";
    		String url = defaultUrl;
    		
            if (args.length > 0) {
    			url = args[0];
    		}
    
    		// Create our Server
    		ServerFactoryBean svrFactory = new ServerFactoryBean();
    		svrFactory.setServiceClass(HelloService.class);
            svrFactory.setAddress(url);
    		svrFactory.setServiceBean(helloWorldImpl);
    		svrFactory.create();
    	}
    }
    

    值得注意的是,我在 server 上使用 localhost 或 127.0.0.1 后,在浏览器中并不能使用真实的 IP 地址进行访问!

    小技巧:将测试程序复制到远程测试时,可以用如下命令导出所有依赖包。

    mvn clean package dependency:copy-dependencies -DoutputDirectory=target/lib 

    3 Client

    如果是象上例在代码中指定 URL 地址的话,只需要把 URL 改成实际 IP 地址即可

    String wsdlUrl = "http://[ip_address]:[port]/Hello?wsdl";
    URL wsdlURL = new URL(wsdlUrl);
    

    但如果是使用的 WSDL,则需修改 WSDL 文件中的如下部分:

    <wsdl:service name="HelloService">
    	<wsdl:port binding="tns:HelloServiceSoapBinding" name="HelloServicePort">
    		<soap:address location="http://[ip_address]:[port]/Hello" />
    	</wsdl:port>
    </wsdl:service>
    
    

     

  • 相关阅读:
    管道/重定向/环境变量
    用户和组命令
    常用命令
    系统监控及进程
    Centos硬件信息
    Centos系统信息及日志
    linux防火墙
    ipt_connlimit限制并发,ipt_recent限制单位时间内的请求数目
    apache添加mod_limitipconn限制单个ip并发连接数
    php核心技术与最佳实践知识点(下)
  • 原文地址:https://www.cnblogs.com/lldwolf/p/7738315.html
Copyright © 2011-2022 走看看