On Monday, November 24, 2014 12:24:25 PM UTC-8, Pengfei Yu wrote:
>
> Hi Dave, 
>
> Thanks very much for your reply! Could you give a more detailed example 
> for an implementation for Java client? A block of java codes from your Java 
> client talking to web2py service will be perfect. Even with the most simple 
> example from the web2py's SOAP service document is good enough.
>
>>
>>
The usage looks something like this:
    try {
        String url = "http://"; + ServerIP + "/" +
                    AppID + "/default/call/soap";
        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.
newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.
createConnection();

        // Send SOAP Message to SOAP Server
        SOAPMessage soapResponse = soapConnection.call(
        createSOAPRequest(tdName, tdiskStatus),
        url);

        // Process the SOAP Response
        printSOAPResponse(soapResponse);

        soapConnection.close();
    } catch (SOAPException ex) {
        System.out.println("main: soap " + ex.getMessage());
        Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, 
null, ex);
    } catch (UnsupportedOperationException ex) {   
        System.out.println("main: uns" + ex.getMessage());
        Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, 
null, ex);
    } catch (Exception ex) {
        System.out.println("main: oops  " + ex.getMessage());
        Logger.getLogger(LogTDSClient.class.getName()).log(Level.SEVERE, 
null, ex);
    }


 and the interesting part:

    private static SOAPMessage createSOAPRequest(String tName, String 
tStatus) throws Exception {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://your-url:here";;
        String authHack = "ZGxv-usual-base64stuff";

        
        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
       // your-url:here corresponds to serverIP above    
        envelope.addNamespaceDeclaration("ns0", 
"http://your-url:here/AppID/default/call/soap";);
        


        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("YourSoapFunc", 
"ns0");
        SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(
"YourSoapParam");
        soapBodyElem1.addTextNode("YourSoapParamString");
        
        
        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPACTION", "");
        headers.addHeader("Authorization", "Basic " + authHack);
        Iterator outHeaders = headers.getAllHeaders();
        while (false & outHeaders.hasNext()) {
        MimeHeader outH = (MimeHeader) outHeaders.next();
        // System.out.println(outH.getName() + " -- " +outH.getValue());
        }

        soapMessage.saveChanges();

        /* Print the request message */
        if (Boolean.FALSE) {
            System.out.print("Request SOAP Message = ");
            soapMessage.writeTo(System.out);
            System.out.println();
        }

        return soapMessage;
    }


It's pretty simple.  You might need to tweak the return value handling, 
because that part wasn't very important to my usage.

(Grrr -- the GG message editor gets funky when I put in a code block, at 
least in this browser.)


Good luck.

/dps




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to