You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Bob DuCharme <bo...@udico.com> on 2001/03/06 19:03:33 UTC

Simple SOAP Client only works locally

I got an Apache SOAP server up and running following the directions in
Graham Glass's excellent articles at
http://www-106.ibm.com/developerworks/library/ws-peer2/ (and /ws-peer3/) and
I got his sample client up and running successfully. To understand SOAP
clients better, I wrote a general purpose client more geared to XML geeks
like myself that reads in a file with the XML of a SOAP request envelope,
sends it off to the SOAP server, and then reads back and outputs the SOAP
response envelope, all without using the Apache SOAP libraries.

It works when I run it against the Apache SOAP server from the machine where
the server is running and from a different machine on the same intranet, but
it doesn't work against a client like the XMethods' weather-temperature one
at http://www.xmethods.com/detail.html?id=8. I have successfully run the
sample client from that same page against XMethods' temperature SOAP server,
so I know I can access that endpoint, but when I use my SimpleSOAPClient
below to send the sample request envelope from that page to the SOAP
endpoint URL shown, I don't get any response. It gets stuck at the
connection.getInputStream() line.

Any suggestions as to what I'm doing wrong?

Bob DuCharme          www.snee.com/bob           <bob@
snee.com>  "The elements be kind to thee, and make thy
spirits all of comfort!" Anthony and Cleopatra, III ii

/////  start of SimpleSOAPClient.java //////

import java.io.*;
import java.net.*;

// Read the SOAP envelope file passed as the second parameter, pass it to
the
// SOAP endpoint passed as the first parameter, and print out the SOAP
// envelope passed as a response.

public class SimpleSOAPClient {
    public static void main(String[] args) throws Exception {

        if (args.length != 2) {
            System.err.println("Usage:  java SimpleSOAPClient " +
                               "http://soapURL soapEnvelopefile.xml");
            System.exit(1);
        }

        String SOAPUrl      = args[0];
        String xmlFile2Send = args[1];

        FileInputStream fin = new FileInputStream(xmlFile2Send);
        URL url = new URL(SOAPUrl);

        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestProperty("Content-Type","text/xml;
charset=utf-8");
        DataOutputStream out =
            new DataOutputStream(connection.getOutputStream());

        // Copy the SOAP file to the open connection.
        copy(fin, out);
        fin.close();
        out.close();

        // Read the response and write it to standard out.

        DataInputStream dis =
            new DataInputStream(connection.getInputStream());
        InputStreamReader isr = new InputStreamReader(dis);
        BufferedReader in = new BufferedReader(isr);


        //  BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));

        String inputLine;

        while ((inputLine = in.readLine()) != null)
            System.out.println(inputLine);

        in.close();
    }


    public static void copy(InputStream in, OutputStream out)
        throws IOException {
        // From ER Harold's "Java I/O" book

        // do not allow other threads to read from the
        // input or write to the output while copying is
        // taking place

        synchronized (in) {
            synchronized (out) {

                byte[] buffer = new byte[256];
                while (true) {
                    int bytesRead = in.read(buffer);
                    if (bytesRead == -1) break;
                    out.write(buffer, 0, bytesRead);
                }
            }
        }
    }

}

/// end of SimpleSOAPClient.java //////



Apache SOAP structures and WSDL

Posted by Joel Riedesel <jr...@jnana.com>.
To send a structured element to an Apache SOAP server, it must
be correctly typed.

Where oh where might one find that information from a WSDL file?

(Not the top level 'input' namespace data, but if an input message
part is a complex type...)

Thanks,

Joel



Apache SOAP structures and WSDL

Posted by Joel Riedesel <jr...@jnana.com>.
To send a structured element to an Apache SOAP server, it must
be correctly typed.

Where oh where might one find that information from a WSDL file?

(Not the top level 'input' namespace data, but if an input message
part is a complex type...)

Thanks,

Joel