

package sandeshaMio;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.sandesha.Constants;
import javax.xml.rpc.ParameterMode;
import org.apache.sandesha.RMReport;
import org.apache.sandesha.SandeshaContext;

//package x log4j
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author Valerio
 */

public class ServizioClient {

    static Logger logger;
    
    /** Creates a new instance of ServizioClient */
    public ServizioClient() {
        logger = Logger.getLogger("ServizioClient");
        //PropertyConfigurator.configure("/home/valerio/apache-tomcat-5.5.17/webapps/axis/WEB-INF/classes/log4j.properties");
        PropertyConfigurator.configure("C:/Programmi/Apache Software Foundation/Tomcat 5.5/webapps/axis/WEB-INF/classes/log4j.properties");
    }
    
    public void start() {
        
        System.setProperty("http.proxyHost", "localhost");
	System.setProperty("http.proxyPort", "8008");
        
        //ServizioServer endpoint
        String endpoint = new String("http://10.10.20.31:8080/axis/services/ServizioServer");
        
        
        try {

            Service service = new Service();
            Call call = (Call) service.createCall();

            SandeshaContext ctx = new SandeshaContext(true);
            
            ctx.setAcksToURL("http://192.168.201.143:8080/axis/services/RMService");
            ctx.setReplyToURL("http://192.168.201.143:8080/axis/services/RMService");
            ctx.setSourceURL("http://192.168.201.143:8080/axis/services/RMService");
            
            ctx.initCall(call, endpoint, "urn:wsrm:echo", Constants.ClientProperties.IN_ONLY);
            

            call.setOperationName("echo");
            call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
            
            logger.info("inizio a inviare messaggi");
            
            call.invoke(new Object[]{"Chiamata 1"});
            
            logger.info("seconda chiamata");
            call.invoke(new Object[]{"Chiamata 2"});
            
            logger.info("terza chiamata");
            ctx.setLastMessage(call);
            call.invoke(new Object[]{"Chiamata 3"});

            RMReport report = ctx.endSequence();
            
            if (report != null) {
                logger.info("Is all messages acked     - " + report.isAllAcked());
            }

        } catch (Exception e) {
            logger.error(e);
            e.printStackTrace();
        }

        
    }
    
}
