I almost got it !!! (Axis is great to use !... I love it when API's
are so intuitive)
I just miss a small part to send the answer message I've built back to
the client. Here is the new cocoonWS function I came up with (with
plenty of debugging code in the middle :-P)

function webservice(){
    var module = cocoon.parameters["module"];
    clog("module is:" + module + "\n");

        //getting the envelope out of the request (can be done only once)
        var soapEnvelope = new java.io.ByteArrayOutputStream();
        cocoon.processPipelineTo("soapEnvelope", null, soapEnvelope);
        clog("Request was:\n" + soapEnvelope + "\n");
        
        var message = new org.apache.axis.Message(soapEnvelope.toString());
        clog("Message length was: " + message.getContentLength() + "\n");
        var soapPart = message.getSOAPPart();
        clog("soapPart was :\n" + soapPart + "\n");
        var envelope = soapPart.getEnvelope();
        clog("envelope was :\n" + envelope + "\n");
        var body = envelope.getBody();
        clog("body was :\n" + body + "\n");
        var it = body.getChildElements();
        var messageContent = it.next();
        clog("messageContent was :\n" + messageContent + "\n");
    var soapMethod = messageContent.getElementName().getLocalName();
    clog("soapMethod was : " + soapMethod + "\n");

    /*
     * Now that we have the method, we generate the according parameters and 
     * execute the code for the called method   
     */
        if(soapMethod == "echo"){
                clog("echo called");

        //generate the parameter
        var soapParameter = messageContent.getValue();
        clog("soapParameter: " + soapParameter);
                
        //process the method (echo in this case)
                /*
                 * Here we compute something e.g. some businessprocess
                 * can be executed (sendMail, ftpUpload,...)
                 * for the echo Method it would be:
                 * //var answer = parameter;
                 * but we put this right in the answer.
                 */
                 
                var answerEnvelope = new SOAPEnvelope(); 
                var answerContent = new SOAPBodyElement(new
PrefixedQName("cocoonWS","result","cws"));
                answerContent.addTextNode(soapParameter);
                answerEnvelope.addBodyElement(answerContent);
                clog("answerEnvelope was :\n" + answerEnvelope + "\n");

        //send the answer
        //AND THE PROBLEM IS HERE CAUSE I DON'T KNOW HOW TO SEND
        //THE CONTENT OF answerContent BACK TO THE USER

        clog("done.");
        return;
        } 
        else { /* here you can add more methods */

            //setting the answer if no method matched
            //TODO in this case we should generate a SOAP-FAULT
            var answer = "The method you have called is not understood by
this server. " +
                                        "Sorry!";         
                cocoon.sendPage("soapAnswer", {"answer":answer});
                clog("no method matched, sending error-statment");
            return;
    }
}

Any ideas out there to replace my "uppercase desperate call" with
something that actually works ?

BTW this works perfectly and it's much cleaner than the previous
approach (no more JXTemplate and XSLT to extract SOAP data) but I
still lose HTTP headers from the initial request because I build a
message from the received SOAP envelope instead of getting a
MessageContent built from the servlet request. So does anyone have an
idea for that... ?

-- 
Sebastien ARBOGAST

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

Reply via email to