Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 具有代理和自动身份验证的WS-Client_Java_Web Services_Jax Ws_Webservices Client_Jax Ws Customization - Fatal编程技术网

Java 具有代理和自动身份验证的WS-Client

Java 具有代理和自动身份验证的WS-Client,java,web-services,jax-ws,webservices-client,jax-ws-customization,Java,Web Services,Jax Ws,Webservices Client,Jax Ws Customization,我知道这不是问问题的正确方式,但我有一个问题: 我有一个本地存储的wsdl,我需要创建一个Web服务客户端来调用该Web服务。问题是服务位于防火墙后面,我必须通过代理连接到它,然后我必须进行身份验证才能连接到WS 我所做的是使用ApacheCXF2.4.6生成WS-Client,然后设置一个系统范围的代理 System.getProperties().put("proxySet", "true"); System.getProperties().put("https.proxyHost", "1

我知道这不是问问题的正确方式,但我有一个问题:

我有一个本地存储的wsdl,我需要创建一个Web服务客户端来调用该Web服务。问题是服务位于防火墙后面,我必须通过代理连接到它,然后我必须进行身份验证才能连接到WS

我所做的是使用ApacheCXF2.4.6生成WS-Client,然后设置一个系统范围的代理

System.getProperties().put("proxySet", "true");
System.getProperties().put("https.proxyHost", "10.10.10.10");
System.getProperties().put("https.proxyPort", "8080");
我知道这不是一个最佳实践,所以请建议一个更好的解决方案,如果有人能给我一个关于如何设置身份验证的提示,我真的很感激使用apache CXF

HelloService hello = new HelloService();
HelloPortType helloPort = cliente.getHelloPort();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(helloPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getClient().setProxyServer("proxy");
http.getClient().setProxyServerPort(8080);
http.getProxyAuthorization().setUserName("user proxy");
http.getProxyAuthorization().setPassword("password proxy");

您还可以使用java.net.Authenticator类设置代理用户名和密码,但我不确定它是否为“系统范围”设置

看这里:
以下是相应的Spring XML配置:

文件:


如果您使用SpringJava配置,要使用ApacheCXF(3.x.x)配置JAX-WS客户端,以下代码将起作用:

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import de.codecentric.namespace.weatherservice.WeatherService;

@Configuration
public class WeatherServiceConfiguration {

    @Bean
    public WeatherService weatherService() {
        JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
        jaxWsFactory.setServiceClass(WeatherService.class);
        jaxWsFactory.setAddress("http://yourserviceurl.com/WeatherSoapService_1.0");
        return (WeatherService) jaxWsFactory.create();
    }

    @Bean
    public Client client() {
        Client client = ClientProxy.getClient(weatherService());
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.getClient().setProxyServer("yourproxy");
        http.getClient().setProxyServerPort(8080); // your proxy-port
        return client;
    }
}

谢谢。一个真正有用的tipproxy主机=
ProxyServer
属性,port=
ProxyServerPort
属性,似乎我不理解您的问题
<import resource="classpath:META-INF/cxf/cxf.xml"/>
name="{http://example.com/}HelloWorldServicePort.http-conduit"
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import de.codecentric.namespace.weatherservice.WeatherService;

@Configuration
public class WeatherServiceConfiguration {

    @Bean
    public WeatherService weatherService() {
        JaxWsProxyFactoryBean jaxWsFactory = new JaxWsProxyFactoryBean();
        jaxWsFactory.setServiceClass(WeatherService.class);
        jaxWsFactory.setAddress("http://yourserviceurl.com/WeatherSoapService_1.0");
        return (WeatherService) jaxWsFactory.create();
    }

    @Bean
    public Client client() {
        Client client = ClientProxy.getClient(weatherService());
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.getClient().setProxyServer("yourproxy");
        http.getClient().setProxyServerPort(8080); // your proxy-port
        return client;
    }
}