import org.apache.wsif.*;
import java.util.Iterator;

/**
 * User: Dylan Honorez
 * Company: XT-i
 * Date: 22-jul-2004
 * Time: 15:02:28
 */

public class AnotherTest {
    public static void main (String[] args){
        try{
            System.setProperty("proxySet", "true");
            System.getProperties().put("http.proxyHost", "10.1.6.254");
            System.getProperties().put("http.proxyPort", "8080");
            System.getProperties().put("http.nonProxyHosts", "localhost");

            // create a service factory
            WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
            WSIFService service =
                factory.getService(
                    "http://localhost:8080/wsifhello/wsifhello?WSDL",
                        //"c:\\MyWSIFHelloService.wsdl",
                    null, //"urn:Foo",
                    null, //"MyWSIFHelloService",
                    "urn:Foo",
                    "WSIFHelloIF");

            // get the port
            WSIFPort port = service.getPort(); //"WSIFHelloIFPort"
            //System.out.println("Port Context: " + port.getContext());

            // create the operation
            WSIFOperation operation = port.createOperation("sayHello");

            // create the input, output and fault messages associated with this operation
            WSIFMessage input = operation.createInputMessage();
            WSIFMessage output = operation.createOutputMessage();
            WSIFMessage fault = operation.createFaultMessage();
            input.setObjectPart("String_1", "Test");

            // do the invocation
            if (operation.executeRequestResponseOperation(input, output, fault)) {
                // invocation succeeded, extract information from output
                // message
                String info = (String)output.getObjectPart("sayHelloReturn");
                //String info = (String)output.getPartNames().next();
                System.out.println(info);
            } else {
                System.out.println("Invocation failed");
                Iterator it = fault.getParts();
                while (it.hasNext()){
                    System.out.println(it.next().toString());
                }

                //String errors = (String)
                // extract fault message info
            }
        }
        catch (WSIFException e){
            e.printStackTrace();
        }
    }
}
