[RESOLVIDO - Apache CXF] HTTP response '407: Proxy Authentication Required'

2 respostas
J

Preciso consumir um Webservice através do Apache CXF e estou tendo problemas na autenticação do proxy.

Criei uma classe simples e estou recebendo a mensagem de proxy authentication required.

org.apache.cxf.transport.http.HTTPException: HTTP response '407: Proxy Authentication Required'

Segue meu código de teste:

private static String domain = "DOMINIO"; 
	private static String userName = "usuario";
	private static String password = "senha";	

public static void main(String args[]) throws Exception {
    	
		Authenticator.setDefault(new Authenticator() {
	        @Override
	        public PasswordAuthentication getPasswordAuthentication() {
	            return new PasswordAuthentication(domain + "\\" + userName, password.toCharArray());
	        }
	    });			
		
		System.setProperty("proxySet", "true" );
		System.setProperty("http.proxyHost", "172.17.3.22");
		System.setProperty("http.proxyPort", "3128");
		System.setProperty("http.proxyUser", domain + "\\" + userName);
		System.setProperty("http.proxyPassword ", password);
		
    	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    	factory.getInInterceptors().add(new LoggingInInterceptor());
    	factory.getOutInterceptors().add(new LoggingOutInterceptor());
    	factory.setServiceClass(XXXServiceSoap.class);
    	factory.setAddress("http:/xxx.com.br/XXX/XXX.asmx");

    	XXXServiceSoap client = (XXXServiceSoap) factory.create();

    	LeitorObjWS[] dados = client.obterRespostas(new GregorianCalendar());
    	System.out.println("Resposta 1: " + dados[0]);
    	System.exit(0); 

    }

Alguém tem alguma dica para fazer a autenticação do proxy de outra forma ?

PS: Houveram alterações recentes no proxy no modo de autenticação. O proxy é squid mas é integrado ao AD.

Obrigado

2 Respostas

J

Consegui evoluir e passar pelo proxy de outra forma (e nem precisou informar usuário e senha… não sei se ele pegou da sessão iniciada)!

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(XXXServiceSoap.class);
factory.setAddress("http://localhost/XXX/XXX.asmx");
    	
XXXServiceSoap cliente = (XXXServiceSoap) factory.create();
    	
Client endpointClient = ClientProxy.getClient(cliente);
HTTPConduit http = (HTTPConduit) endpointClient.getConduit();
		
HTTPClientPolicy httpClientPolicy = http.getClient();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setProxyServer("172.17.3.22");
httpClientPolicy.setProxyServerPort(3128);
httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
httpClientPolicy.setAutoRedirect(false);
httpClientPolicy.setConnection(ConnectionType.KEEP_ALIVE);
	
LeitorObjWS[] dados = cliente.obterRespostas(new GregorianCalendar());
System.out.println("Resposta 1: " + dados[0]);  
System.exit(0);

Fica a dica para quem precisar…

A

Tive o mesmo problema e pra mim também serviu… vlw abs.

Criado 14 de agosto de 2012
Ultima resposta 11 de set. de 2012
Respostas 2
Participantes 2