Deepal,
 
Here is my java code which performs the parse of file and formulates it to a SOAPMessage.
 
John

>>> [EMAIL PROTECTED] 07/11/06 12:09 PM >>>
Did you use same OMelement for both the method invocations ?

if not so , any possibility of seeing the client side code ?

John Ferron wrote:

> Good Morning,

> Has anyone seen this exception when trying to perform a sendRecieve()
> on the ServiceClient object??  It would be greatly appreciated if I
> could get this resolved.

> John

>
> 06 Jul 2006 15:54:40 [ProcessSOAPMessage$jsp] ERROR soap  - Can not
> output XML declaration, after other output has already been done.;
> nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.; nested exception is:
>  org.apache.axis2.AxisFault: Can not output XML declaration, after
> other output has already been done.; nested exception is:
>  javax.xml.stream.XMLStreamException: Can not output XML declaration,
> after other output has already been done.


--
Thanks,
Deepal
................................................................
~Future is Open~




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

package com.alliantenergy.soap;

import java.io.File;
import java.io.FileInputStream;
import java.io.StringWriter;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamReader;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.axis2.description.AxisService;
import org.apache.log4j.Logger;

public class SoapClient {

        Logger log = Logger.getLogger("soap");
        static final int BUF_SIZE = 2048;

        /** 
*************************************************************************** */
        public String postSoapMessage(String operation, String namespace, 
String url,
                        boolean isHTTPS, boolean isClientAuth, String keystore,
                        String keystorePWD, File filename, String soapVersion) 
throws Exception {

                initProperties(isHTTPS, keystore, keystorePWD);
                return sendSoapMsg(filename, operation, namespace, url, 
soapVersion);

        }

        /** 
*************************************************************************** */
        private void initProperties(boolean isHTTPS, String keystore,
                        String keystorePWD) {
                // the following code should be uncommented if HTTPS is used. 
There should
                // also be a trust store that contains the signed server 
certificate for the
                // web server that is being used.
                if (isHTTPS) {
                        System.setProperty("javax.net.ssl.trustStore", 
"/opt/eai/security/"
                                        + keystore);
                        System.setProperty("javax.net.ssl.trustStorePassword", 
keystorePWD);
                }
        }

        /** 
*************************************************************************** */
        private String sendSoapMsg(File file, String operation, String 
namespace,
                        String url, String soapVersion) throws Exception {
                // create the parser
                XMLStreamReader parser = XMLInputFactory.newInstance()
                                .createXMLStreamReader(new 
FileInputStream(file));

                // create the builder
                StAXOMBuilder builder = new StAXOMBuilder(parser);

                // get the root element (in this case the envelope)
                OMElement documentElement = builder.getDocumentElement();
                SOAPFactory omfactory;
                if (soapVersion.equals("1.2")) {
                        omfactory = OMAbstractFactory.getSOAP12Factory();
                        log.debug("Setting up SOAP1.2 message........");
                } else {
                        omfactory = OMAbstractFactory.getSOAP11Factory();
                        log.debug("Setting up SOAP1.1 message........");
                }
                SOAPEnvelope envelope = omfactory.createSOAPEnvelope();
                OMElement action = omfactory.createOMElement(operation, 
namespace, "");
                SOAPBody body = omfactory.createSOAPBody(envelope);
                action.addChild(documentElement);
                body.addChild(action);

                return sendRecieve(url, envelope);
        
        }

        /** 
*************************************************************************** */
        private String sendRecieve(String urlStr, OMElement requestElement)
                        throws Exception {
                URL url = null;
                OMElement responseElement = null;
                url = new URL(urlStr);
                log.info("URL: " + urlStr);

                Options options = new Options();
                options.setTo(new EndpointReference(url.toString()));
                options.setProperty(MessageContextConstants.CHUNKED, 
Constants.VALUE_FALSE);
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

                ServiceClient sender = new ServiceClient();
                sender.setOptions(options);
                log.info("Sending: ");
                log.info(requestElement.toStringWithConsume());
                OMElement om;
                om = requestElement.getFirstElement();
                
                log.info("getNamespace: " + 
requestElement.getNamespace().getName());
                log.info("getLocalName: " +     requestElement.getLocalName() );
                log.info("getPrefix: " + 
requestElement.getNamespace().getPrefix());
                
                // Blocking invocation
                QName q = new QName(requestElement.getNamespace().getName(),
                                requestElement.getLocalName() , 
requestElement.getNamespace().getPrefix());
                AxisService as = sender.getAxisService();
                sender.engageModule(q);
                responseElement = sender.sendReceive(requestElement);
                sender.disEngageModule(new 
QName(requestElement.getNamespace().getName(),
                                requestElement.getLocalName() , 
requestElement.getNamespace().getPrefix()));
                StringWriter writer = new StringWriter();
                
responseElement.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(
                                writer));
                writer.flush();

                log.info("Response: " + writer.toString());

                sender.finalizeInvoke();
                if (responseElement == null) {
                        log.info("Null response");
                        return "Null response";
                } else {
                        log.info(responseElement.toString());
                        return responseElement.toString();
                }
        }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to