Exportar arquivo Soap - RESOLVIDO

1 resposta
F

Olá

tenho um web service dummie e queria saber se existe alguma forma de exportar em java a saída Soap (xml) do meu web service quando o método é

invocado.

Exemplo:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:calcularSalarioResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:TesteFabioWs">
         <calcularSalarioReturn href="#id0"/>
      </ns1:calcularSalarioResponse>
      <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:double" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">900.0</multiRef>
   </soapenv:Body>
</soapenv:Envelope>

Queria pegar esse SOAP e exportar em java, o que eu coloquei acima gerei pelo SOAPUI. Queria fazer isso em java quando chamo o web service:

try {
	            //recupera a URL do Serviço       
	            String  url = "http://localhost:8080/implantacao-core/services/TesteFabioWs.wsdl";
	           
	            // Locator é a classe que localiza o serviço...
	           // Nela, se vc procurar, vai achar a URL de chamada do Web Service
	            TesteWebServiceServiceLocator locator = new TesteWebServiceServiceLocator();      
	           
	           // Interface que define o Web Service - "Contrato do Web Service"
	            TesteWebService teste = locator.getTesteWebService((new java.net.URL(url)));
	           
	           // Crio o stub através do servico definido acima
	            TesteWebServiceSoapBindingStub  stub = (TesteWebServiceSoapBindingStub) teste;
	                   
	           
	            //chamo o webservice
	            int resultado = stub.somaValores(a, b);


} catch (java.lang.Exception e) {
	            log.error(e.getMessage());
	            throw new ExecuteException(e.getMessage(),e);
               }

Queria pegar o valor retornado pra variavel resultado, tipo no formato SOAP como mostrado acima gerado pelo SOAPUI.

Isso é possivel?

Obrigado!

1 Resposta

F

Para conhecimento, consegui encontrar uma forma de retornar a mensagem SOAP tanto o de request quanto o de response já convertida em String segue abaixo:

Dentro da Classe *SoapBindingStub e do método do seu Web service colocar o seguinte código.

//Mensagem Request SOAP
 String msgRequest =  _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
 //Mensagem Resposta SOAP
 String msgResposta = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();

Exemplo completo do metodo dentro da classe *SoapBindingStub:

public java.lang.Double calcularSalario(java.lang.Double in0, java.lang.Double in1) throws java.rmi.RemoteException {
        if (super.cachedEndpoint == null) {
            throw new org.apache.axis.NoEndPointException();
        }
        org.apache.axis.client.Call _call = createCall();
        _call.setOperation(_operations[0]);
        _call.setUseSOAPAction(true);
        _call.setSOAPActionURI("");
        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
        _call.setOperationName(new javax.xml.namespace.QName("urn:TesteFabioWs", "calcularSalario"));
        setRequestHeaders(_call);
        setAttachments(_call);
 try {        java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in0, in1});

        if (_resp instanceof java.rmi.RemoteException) {
            throw (java.rmi.RemoteException)_resp;
        }
        else {
            extractAttachments(_call);
            try {
            	//Mensagem Request SOAP
                String msgRequest =  _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
            	//Mensagem Resposta SOAP
                String msgResposta = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();
                System.out.println("Mensagem Request " + msgRequest);
                System.out.println("------------------------------------------");
                System.out.println("Mensagem Resposta " + msgResposta);
                
                return (java.lang.Double) _resp;
            } catch (java.lang.Exception _exception) {
                return (java.lang.Double) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.Double.class);
            }
        }
  } catch (org.apache.axis.AxisFault axisFaultException) {
  throw axisFaultException;
}
    }
Criado 26 de dezembro de 2011
Ultima resposta 26 de dez. de 2011
Respostas 1
Participantes 1