[Resolvido]Endereço do web service sendo mudado para localhost

1 resposta
java
A

Tenho uma aplicação que é cliente de um web service, desenvolvido por mim. O web service fica em um servidor e o client fica em outro. Quando chamo o cliente, tanto no local host, quanto no servidor, o endereço dá chamada é mudado para localhost e não consigo chamar o método. O erro que ocorre é um 404. No entanto, eu garanti que minhas classes não chamassem localhost, mas sim o servidor onde o web service de fato está hospedado.

Já tentei realizar o procedimento abaixo, porém não funcionou.

http://stackoverflow.com/questions/26476675/jboss-not-reaching-web-services-on-remote-ip

Seguem as classes relevantes:

Classe client:

package br.com.samsung.scheduler.ws;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service;

/**
 * This class was generated by Apache CXF 2.4.6
 * 2016-10-24T12:07:40.872-02:00
 * Generated source version: 2.4.6
 * 
 */
@WebServiceClient(name = "DownloadArquivoService", 
                  wsdlLocation = "http://105.103.5.69:8080/SchedulerWeb/DownloadArquivo?wsdl",
                  targetNamespace = "http://ws.scheduler.samsung.com.br/") 
public class DownloadArquivoService extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("http://ws.scheduler.samsung.com.br/", "DownloadArquivoService");
    public final static QName DownloadArquivoPort = new QName("http://ws.scheduler.samsung.com.br/", "DownloadArquivoPort");
    static {
        URL url = null;
        try {
            url = new URL("http://105.103.5.69:8080/SchedulerWeb/DownloadArquivo?wsdl");
        } catch (MalformedURLException e) {
            java.util.logging.Logger.getLogger(DownloadArquivoService.class.getName())
                .log(java.util.logging.Level.INFO, 
                     "Can not initialize the default wsdl from {0}", "http://105.103.5.69:8080/SchedulerWeb/DownloadArquivo?wsdl");
        }
        WSDL_LOCATION = url;
    }

    public DownloadArquivoService(URL wsdlLocation) {
        super(wsdlLocation, SERVICE);
    }

    public DownloadArquivoService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public DownloadArquivoService() {
        super(WSDL_LOCATION, SERVICE);
    }
    
    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public DownloadArquivoService(WebServiceFeature ... features) {
        super(WSDL_LOCATION, SERVICE, features);
    }

    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public DownloadArquivoService(URL wsdlLocation, WebServiceFeature ... features) {
        super(wsdlLocation, SERVICE, features);
    }

    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
    //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
    //compliant code instead.
    public DownloadArquivoService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     *
     * @return
     *     returns DownloadArquivo
     */
    @WebEndpoint(name = "DownloadArquivoPort")
    public DownloadArquivo getDownloadArquivoPort() {
        return super.getPort(DownloadArquivoPort, DownloadArquivo.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns DownloadArquivo
     */
    @WebEndpoint(name = "DownloadArquivoPort")
    public DownloadArquivo getDownloadArquivoPort(WebServiceFeature... features) {
        return super.getPort(DownloadArquivoPort, DownloadArquivo.class, features);
    }

}

Chamada do client:

DownloadArquivoService service = new DownloadArquivoService();
DownloadArquivo download = service.getDownloadArquivoPort();
String nomeArquivo = "NFe" + chave + ".xml";

byte[] xmlNF = download.downloadXMLPorNomeArquivo(nomeArquivo);

O erro ocorre na chamada do método downloadXMLPorNomeArquivo, e estou usando JBoss 7.1.1, usei o wsimport, nativo do java para criar meu client.

Observação: Pelo soap UI, roda normal.

1 Resposta

A

Foi necessário colocar a linha:

BindingProvider bp = (BindingProvider) download ; bp.getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://105.103.5.69/myservice/DownloadArquivo");

Desta Forma funcionou.

Criado 14 de novembro de 2016
Ultima resposta 14 de nov. de 2016
Respostas 1
Participantes 1