Arquivos de sites
Como recuperar XML do Envelop SOAP com Axis2
Posted by Gustavo Amaro
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
Publicado em Axis2, Integração, Java, SOAP, Web Service
Etiquetas: AppDesign, Attempted, axis, axis 2, axis2, closed, com.ctc.wstx.exc.WstxIOException, convert, entrada, env, envelope, erro, getEnvelope, in, java, MessageContext, on, OperationContext, out, print, read, saida, show, soap, stream, String, stub, sysout, text, toString, WstxIOException, xml
Axis 2 – com.ctc.wstx.exc.WstxIOException: Attempted read on closed stream
Posted by Gustavo Amaro
Hoje eu descobri que existe um modo de recuperar o envelope SOAP em String,
utilizando o stub do Axis2, porém estava tomando o seguinte erro:
com.ctc.wstx.exc.WstxIOException: Attempted read on closed stream
então, procurando na internet descobri que é necessário adicionar uma linha no arquivo
stub gerado pelo Axis2, para poder acessar o envelope fora do contexto do stub…
procure pela linha:
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext.getEnvelope();
e adicione isso embaixo dela:
_returnEnv.build();
simples não?
Caso você esteja procurando como recuperar o Envelope SOAP tanto de saida como de entrada do Axis2
clique aqui!!! 😀
Abraços.
Fonte: apache.org – TAM Tenfold5
Publicado em Axis2, Integração, Java, SOAP, Web Service
Etiquetas: apache, apache.org, AppDesign, Attempted, axis, axis 2, axis2, build, closed, com.ctc.wstx.exc.WstxIOException, convert, entrada, env, envelope, erro, getEnvelope, in, java, MessageContext, on, OperationContext, out, print, read, returnEnv, saida, show, soap, SOAPEnvelope, stream, String, stub, sysout, text, toString, WstxIOException, xml, _returnEnv