Dear Upul,

This is mys service:


    public SOAPEnvelope fatorial(SOAPEnvelope elemento)
                                throws XMLStreamException {
            
                // Obtém o endereço IP de cada cliente que acesso o serviço
                MessageContext msgCtx = 
MessageContext.getCurrentMessageContext();
                String remoteAddress = 
(String)msgCtx.getProperty("REMOTE_ADDR");

                // Obtém o timeout estabelecido entre cliente/servidor
                String default_timeout =
Integer.toString(Options.DEFAULT_TIMEOUT_MILLISECONDS);
                                
                // Verifica o tipo de conteúdo da mensagem enviada via HTTP
                HttpServletRequest request =
(HttpServletRequest)msgCtx.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
                String contentType =
request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE); 
            
                elemento.build();
                elemento.detach();
        
                String rootName = elemento.getLocalName();
                System.out.println("Reading "+rootName+" element");
            
                OMElement elementoFilho = elemento.getFirstElement();
            
                String valorxml = elementoFilho.getText();
                long valrecebido = Long.parseLong(valorxml);  
            

                String resultado = Fatorial.retornaFatorial(valrecebido); 

                // Construct the Envelope + Header + Body
                SOAPFactory soap11Factory =
OMAbstractFactory.getSOAP11Factory();
                SOAPEnvelope newEnvelope = soap11Factory.getDefaultEnvelope();
                OMNamespace soapnamespace =
soap11Factory.createOMNamespace("http://teste.org";, "teste");
        
                OMFactory fac = OMAbstractFactory.getOMFactory();
                OMNamespace omNs =
fac.createOMNamespace("http://exemplo1.org/exemplo1";, "exemplo");
                OMElement metodo =
fac.createOMElement("fatorialResposta",omNs);
                OMElement valor = fac.createOMElement("resposta", null);
                valor.addChild(fac.createOMText(valor, "Resultado do Fatorial:
"+resultado));
                metodo.addChild(valor);
                
                SOAPHeaderBlock newSOAPHeaderBlock =
soap11Factory.createSOAPHeaderBlock("http://legal.org";, soapnamespace);
                newEnvelope.getHeader().addChild(newSOAPHeaderBlock);
                newEnvelope.getBody().addChild(metodo);
                                                  
                return newEnvelope;
     }
    

This is my client:

        public static SOAPEnvelope CalculaFatorial(String numero) { 

            // Construct the Envelope + Header + Body
            SOAPFactory soap11Factory =
OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope newEnvelope = soap11Factory.getDefaultEnvelope();
            OMNamespace soapnamespace =
soap11Factory.createOMNamespace("http://teste.org";, "teste");
                
            OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs =
fac.createOMNamespace("http://exemplo.org/exemplo";, "exemplo");
            OMElement metodo = fac.createOMElement("fatorial", omNs);
            OMElement valor = fac.createOMElement("numero", omNs);
            valor.addChild(fac.createOMText(valor, numero));
            metodo.addChild(valor);

            SOAPHeaderBlock newSOAPHeaderBlock =
soap11Factory.createSOAPHeaderBlock("http://legal.org";, soapnamespace);
            newEnvelope.getHeader().addChild(newSOAPHeaderBlock);
            newEnvelope.getBody().addChild(metodo);
                                                  
            return newEnvelope;

        }


When a try execute, I have the following error:

[INFO] Unable to sendViaPost to
url[http://localhost:8080/axis2/services/ServicoFatorial]
org.apache.axis2.AxisFault: Can not output XML declaration, after other
output has already been done.
        at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417)
        at
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:72)
        at
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
        at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:495)
        at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1973)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:993)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
        at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:520)
        at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:191)
        at
org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:77)
        at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:327)
        at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:206)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:396)
        at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:374)
        at
org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:414)
        at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
        at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
        at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.stream.XMLStreamException: Can not output XML
declaration, after other output has already been done.
        at
com.ctc.wstx.sw.BaseStreamWriter.throwOutputError(BaseStreamWriter.java:1473)
        at
com.ctc.wstx.sw.BaseStreamWriter.reportNwfStructure(BaseStreamWriter.java:1502)
        at
com.ctc.wstx.sw.BaseStreamWriter.doWriteStartDocument(BaseStreamWriter.java:699)
        at
com.ctc.wstx.sw.BaseStreamWriter.writeStartDocument(BaseStreamWriter.java:687)
        at
org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:193)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:814)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:785)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:814)
        at
org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.serializeInternally(SOAPEnvelopeImpl.java:237)
        at
org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:225)
        at
org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:814)
        at
org.apache.axiom.om.impl.llom.OMNodeImpl.serializeAndConsume(OMNodeImpl.java:421)
        at
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:68)
        ... 19 more

What could be it?

Julio
-- 
View this message in context: 
http://www.nabble.com/How-to-create-a-soap-envelope-using-AXIOM--tf4840398.html#a13855564
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to