Como recuperar XML do Envelop SOAP com Axis2

E ai galera beleza?

Hoje descobri que tem uma maneira muito simples de recuperar o xml
que vem dentro do envelope SOAP (tanto de entrada como de saida) no Axis2

segue um exemplo de como fazê-lo:

import org.apache.axis2.*;
import org.apache.axis2.context.*;
public class ExampleStub {
   private InterfaceExampleStub stub = null;
   public ExampleStub(String url) throws Exception {
        try {
            stub = new InterfaceExampleStub(url);
        } catch (AxisFault e) {
            throw new Exception("Error creating a ExampleStub: "+e.getMessage(), e);
        }
    }

    public void operation() throws Exception {
        try {
            stub.operation(/* parameters */);
        } catch(Throwable t) {
            throw new Exception("Got throwable: ["+ t.getMessage(), t);
        } finally {
            try {
                OperationContext operationContext = stub._getServiceClient().getLastOperationContext();
                if (operationContext != null) {
                    MessageContext outMessageContext = operationContext.getMessageContext("Out");
                    if (outMessageContext != null) {
                        System.out.println("OUT SOAP: "+outMessageContext.getEnvelope().toString());
                    }
                    MessageContext inMessageContext = operationContext.getMessageContext("In");
                    if (inMessageContext != null) {
                        System.out.println("IN SOAP: "+ inMessageContext.getEnvelope().toString());
                    }
                }
            } catch(Throwable e) {
                System.out.println("Cannot log soap messages: "+e.getMessage());
            }
        }
    }
}

OBS.: Caso tome o seguinte erro ao tentar executar:

com.ctc.wstx.exc.WstxIOException: Attempted read on closed stream

Siga este tutorial de como resolver este prolema…

Fonte: AppDesign – Ivan K

About Gustavo Amaro

+ MBA em Desenvolvimento de Aplicações JAVA – SOA + Formado em Tecnologia e Análise de Sistemas

Posted on 12 de Setembro de 2013, in Axis2, Integração, Java, SOAP, Web Service and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink. 2 comentários.

  1. Ola Gustavo, vi alguns tutorias seus, e gostei mto, parabens..
    agora preciso de uma força, tenho que publicar um web services de maneira segura, garantindo confiança e confiabilidade no serviço, utilizando SSL..
    nao tenho ideia de como fazer isso, se puder da uma forçao, podemos negociar.

Deixe uma resposta para Johnjohn Cancelar resposta