7

So che questo non è esattamente il modo corretto di fare una domanda, ma sto avendo un problema:client WS con proxy e Autentification

Ho un WSDL memorizzato localmente, e ho bisogno di creare un Web Servizio Client per chiamare quel servizio Web. Il problema è che il servizio è dietro un firewall e devo collegarmi ad esso tramite un proxy e successivamente devo autenticare per connettermi al WS.

Quello che ho fatto è generare il client WS con Apache CXF 2.4.6 quindi impostare una vasta proxy di sistema

System.getProperties().put("proxySet", "true"); 
System.getProperties().put("https.proxyHost", "10.10.10.10"); 
System.getProperties().put("https.proxyPort", "8080"); 

So che questa non è una pratica migliore, quindi si prega di suggerire una soluzione migliore, anche se qualcuno mi può dare un consiglio su come impostare l'autenticazione I'dd really appreciate it

risposta

16

con 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"); 
+0

Grazie mille. Un suggerimento davvero utile –

0

è anche possibile impostare il nome utente proxy e password utilizzando java.net.Authent classe Icator, ma non sono sicuro che non sia impostato su "system wide".

Guardate qui: Authenticated HTTP proxy with Java

4

Ecco la corrispondente configurazione XML Primavera:

Documentazione: http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" 
    xmlns:sec="http://cxf.apache.org/configuration/security" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans.xsd 
         http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd 
         http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd"> 

<http-conf:conduit name="*.http-conduit"> 
    <http-conf:client ProxyServer="proxy" ProxyServerPort="8080"/> 

    <http-conf:proxyAuthorization> 
     <sec:UserName>proxy_user</sec:UserName> 
     <sec:Password>proxy_pass</sec:Password> 
    </http-conf:proxyAuthorization> 
</http-conf:conduit> 

Affinché questo funzioni è necessario importare cxf.xml:

<import resource="classpath:META-INF/cxf/cxf.xml"/> 

Si noti che questo HTTPConduit sarà abilitato per tutti i client CXF (se diversi).

È necessario configurare il proprio nome condotto per abbinare solo il vostro servizio Conduit:

name="{http://example.com/}HelloWorldServicePort.http-conduit" 
+1

host proxy = proprietà '' ProxyServer', porta = 'ProxyServerPort', sembra che non capisco la tua domanda – yunandtidus

4

Se stai usando configurazione di Spring Java, per configurare un client JAX-WS con Apache CXF (3.xx), il il seguente codice funzionerà:

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; 
    } 
} 
+0

funziona anche per me! grazie! – ncowboy

Problemi correlati