You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ch...@apache.org on 2005/05/10 18:16:57 UTC

cvs commit: ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient InteropBean.java InteropCallback.java InteropStub.java ResponseWriter.java TestRunnerThread.java

chamikara    2005/05/10 09:16:57

  Added:       sandesha/interop/org/apache/sandesha/samples/interop/testclient
                        InteropBean.java InteropCallback.java
                        InteropStub.java ResponseWriter.java
                        TestRunnerThread.java
  Log:
  These classes will be used by interop test client.
  
  Revision  Changes    Path
  1.1                  ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient/InteropBean.java
  
  Index: InteropBean.java
  ===================================================================
  package org.apache.sandesha.samples.interop.testclient;
  
  import java.io.Serializable;
  
  
  public class InteropBean implements Serializable {
  	
  	private String target;
  	private String operation;
  	private String from;
  	private String replyto;
  	private int noOfMsgs;
  	private String terminate;
  	private String acks;
  	
  	
  	
  
  	/**
  	 * @return
  	 */
  	public String getAcks() {
  		return acks;
  	}
  
  	/**
  	 * @return
  	 */
  	public String getFrom() {
  		return from;
  	}
  
  	/**
  	 * @return
  	 */
  	public int getNoOfMsgs() {
  		return noOfMsgs;
  	}
  
  	/**
  	 * @return
  	 */
  	public String getOperation() {
  		return operation;
  	}
  
  	/**
  	 * @return
  	 */
  	public String getReplyto() {
  		return replyto;
  	}
  
  	/**
  	 * @return
  	 */
  	public String getTarget() {
  		return target;
  	}
  
  	/**
  	 * @return
  	 */
  	public String getTerminate() {
  		return terminate;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setAcks(String string) {
  		acks = string;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setFrom(String string) {
  		from = string;
  	}
  
  	/**
  	 * @param i
  	 */
  	public void setNoOfMsgs(int i) {
  		noOfMsgs = i;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setOperation(String string) {
  		operation = string;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setReplyto(String string) {
  		replyto = string;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setTarget(String string) {
  		target = string;
  	}
  
  	/**
  	 * @param string
  	 */
  	public void setTerminate(String string) {
  		terminate = string;
  	}
  
  }
  
  
  
  1.1                  ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient/InteropCallback.java
  
  Index: InteropCallback.java
  ===================================================================
  /*
   * Created on Apr 15, 2005
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.sandesha.samples.interop.testclient;
  
  import java.io.IOException;
  import java.util.ArrayList;
  
  import javax.swing.JOptionPane;
  
  import org.apache.sandesha.Constants;
  import org.apache.sandesha.storage.Callback;
  import org.apache.sandesha.storage.CallbackData;
  
  /**
   * @author root
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class InteropCallback extends Callback {
  
  	private ResponseWriter writer = null;
  	private boolean testFinished = false;
  	
  	public synchronized void setTestFinished(boolean finished){
  		this.testFinished = finished;	
  	}
  	
  	public synchronized boolean isTestFinished(){
  		return testFinished;
  	}
  	
  	public InteropCallback (ResponseWriter  writer){
  		this.writer = writer;
  	}
  	
  	public synchronized void onIncomingMessage(CallbackData result) {
  		
  	    	String action = result.getAction();
  	    	String msgType = action;
  	    	if(action!=null) {
  	    		if(action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE))
  	    	   	 	msgType = "create sequence";
  	    		else if(action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE_RESPONSE))   
  	    	    	msgType = "create sequence response";
  	    		else if(action.equals(Constants.WSRM.ACTION_TERMINATE_SEQUENCE))  
  	    	    	msgType = "terminate sequence";
  	    		else if(action.equals(Constants.WSRM.SEQUENCE_ACKNOWLEDGEMENT_ACTION))
  	    	    	msgType = "acknowledgement";
  	    	}else{
  	    		msgType = "service response";
  	    	}
  	    	
  			String entry = "<br /><font color='red'> Got " + msgType +" message. ID : " + result.getMessageId() + "</font>";  // + result.getSequenceId() + " </font>";
  			
  			boolean b = writer.write(entry);
  			if(!b)
  				setTestFinished(true);
  	}
  
  	public synchronized void onOutgoingMessage(CallbackData result) {
  		
  	    int type = result.getMessageType();
      	String msgType = null;
      	
      	if(type==Constants.MSG_TYPE_CREATE_SEQUENCE_REQUEST)
      	    msgType = "create sequence";
      	else if(type==Constants.MSG_TYPE_CREATE_SEQUENCE_RESPONSE)   
      	    msgType = "create sequence response";
      	else if(type==Constants.MSG_TYPE_TERMINATE_SEQUENCE)  
      	    msgType = "terminate sequence";
      	else if(type==Constants.MSG_TYPE_ACKNOWLEDGEMENT)
      	    msgType = "acknowledgement";
      	else if(type==Constants.MSG_TYPE_SERVICE_REQUEST)
      	    msgType = "service request";    	
      	else if(type==Constants.MSG_TYPE_SERVICE_RESPONSE)
      	    msgType = "service response";  
      	
      	String entry = "<br /><font color='blue'> Sent " + msgType +" message. ID : " + result.getMessageId() + "</font>";// + result.getSequenceId() + " </font>";
  		
  		boolean b = writer.write(entry);
  		if(!b)
  			setTestFinished(true);
  			
  		if(result.getMessageType()==6)
  			setTestFinished(true);
  		
  	}
  
  }
  
  
  
  1.1                  ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient/InteropStub.java
  
  Index: InteropStub.java
  ===================================================================
  /*
   * Created on Apr 15, 2005
   *
   * To change the template for this generated file go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  package org.apache.sandesha.samples.interop.testclient;
  
  
  
  import javax.xml.namespace.QName;
  import javax.xml.rpc.ParameterMode;
  
  import org.apache.axis.client.Call;
  import org.apache.axis.client.Service;
  import org.apache.axis.encoding.XMLType;
  import org.apache.axis.utils.XMLUtils;
  import org.apache.sandesha.Constants;
  import org.apache.sandesha.RMInitiator;
  import org.apache.sandesha.RMTransport;
  
  
  
  /**
   * @author root
   *
   * To change the template for this generated type comment go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  public class InteropStub {
  	
  	public void runPingSync(InteropBean bean){
  		String target = bean.getTarget();
  		String from = bean.getFrom();
  		String replyTo = bean.getReplyto();
  		String acks = bean.getAcks();
  		String terminate = bean.getTerminate();
  		String operation = bean.getOperation();
  		int messages = bean.getNoOfMsgs();
  			
  		//String targetURL = "http://127.0.0.1:"+"8070"+"/axis/services/RMInteropService?wsdl";
  
  		try {
  
  			System.out.println("********Running ping sync");
  			RMInitiator.initClient(true);
  
  			Service service = new Service();
  			Call call = (Call) service.createCall();
  
  			call.setProperty(Constants.ClientProperties.SYNC, new Boolean(true));
  			call.setProperty(Constants.ClientProperties.ACTION, "sandesha:ping");
  
  			//These two are additional
  			//call.setProperty("from","http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous");
  			//call.setProperty("replyTo","http://10.10.0.4:8080/axis/services/MyService");
  			//http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous
  
  			call.setProperty(Constants.ClientProperties.FROM,org.apache.axis.message.addressing.Constants.NS_URI_ANONYMOUS);
  			
  			call.setTargetEndpointAddress(target);
  			call.setOperationName(new QName("RMInteropService", operation));
  			call.setTransport(new RMTransport(target, ""));
  
  			call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
  
  			for(int i=1;i<=messages;i++){
  				call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long((i)));
  				String msg = "Ping Message Number " + i;
  				call.invoke(new Object[]{msg});
  				
  				if(i==messages){
  					call.setProperty(Constants.ClientProperties.LAST_MESSAGE, new Boolean(true));
  				}
  			}
  			//First Message
  			/*call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long(1));
  			call.invoke(new Object[]{"Ping Message Number One"});
  
  			//Second Message
  			call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long(2));
  			call.invoke(new Object[]{"Ping Message Number Two"});
  
  			//Third Message
  			call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long(3));
  			call.setProperty(Constants.ClientProperties.LAST_MESSAGE, new Boolean(true)); //For last message.
  			call.invoke(new Object[]{"Ping Message Number Three"});*/
  
  			RMInitiator.stopClient();
  
  			} catch (Exception e) {
  				//System.err.println(e.toString());
  				e.printStackTrace();
  			}	
  			
  	}
  	
  	public void runPingAsync(InteropBean bean){
  	      try {
  
  			String target = bean.getTarget();
  			String from = bean.getFrom();
  			String replyTo = bean.getReplyto();
  			String acks = bean.getAcks();
  			String terminate = bean.getTerminate();
  			String operation = bean.getOperation();
  			int messages = bean.getNoOfMsgs();
  			
  			
  	          RMInitiator.initClient(false);
  
  	          Service service = new Service();
  	          Call call = (Call) service.createCall();
  
  	          call.setProperty(Constants.ClientProperties.SYNC, new Boolean(false));
  	          call.setProperty(Constants.ClientProperties.ACTION, "sandesha:ping");
  
  	          //These two are additional
  	          call.setProperty("from","http://127.0.0.1:" + "9070" + "/axis/services/RMService");
  	          //call.setProperty("replyTo","http://127.0.0.1:"+defaultClientPort+"/axis/services/RMService");
  	          //http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous
  
  	          call.setTargetEndpointAddress(target);
  	          call.setOperationName(new QName("RMInteropService", "ping"));
  	          call.setTransport(new RMTransport(target, ""));
  
  	          call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
  	          	
  				for(int i=1;i<=messages;i++){
  					call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long((i)));
  					String msg = "Ping Message Number " + i;
  					
  					if(i==messages){
  						call.setProperty(Constants.ClientProperties.LAST_MESSAGE, new Boolean(true));
  					}
  					
  					call.invoke(new Object[]{msg});
  				}
  
  	          RMInitiator.stopClient();
  
  	      } catch (Exception e) {
  	          //System.err.println(e.toString());
  	          e.printStackTrace();
  	      }	    
  	}
  	
  	public void runEchoStringSync(InteropBean bean){
  	       try {
  	           
  			String target = bean.getTarget();
  			String from = bean.getFrom();
  			String replyTo = bean.getReplyto();
  			String acks = bean.getAcks();
  			String terminate = bean.getTerminate();
  			String operation = bean.getOperation();
  			int messages = bean.getNoOfMsgs();
  		        
  		        //A separate listner will be started if the value of the input parameter for the mehthod
  	            // initClient is "false". If the service is of type request/response the parameter value shoule be "false"
  	            RMInitiator.initClient(false);
  
  	            //UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); //Can use this for continuous testing.
  	            //String str = uuidGen.nextUUID();
  
  
  	            Service service = new Service();
  	            Call call = (Call) service.createCall();
  
  	            //Action is required.
  	            call.setProperty(Constants.ClientProperties.SYNC, new Boolean(false));
  	            call.setProperty(Constants.ClientProperties.ACTION, "sandesha:echo");
  
  	            //These two are additional, We need them since we need to monitor the messages using TCPMonitor.
  	            call.setProperty(Constants.ClientProperties.FROM,org.apache.axis.message.addressing.Constants.NS_URI_ANONYMOUS);
  	            call.setProperty(Constants.ClientProperties.REPLY_TO,"http://127.0.0.1:" + "9070" + "/axis/services/RMService");
  				
  				
  	            call.setTargetEndpointAddress(target);
  	            call.setOperationName(new QName("RMInteropService", "echoString"));
  	            call.setTransport(new RMTransport(target, ""));
  
  	            call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
  	            call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
  	            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
  
  				for(int i=1;i<=messages;i++){
  					call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long((i)));
  					String msg = "ECHO " + i;
  					
  
  					if(i==messages){
  						call.setProperty(Constants.ClientProperties.LAST_MESSAGE, new Boolean(true));
  					}
  					
  					String ret = (String) call.invoke(new Object[]{msg,"abcdef"});
  					System.out.println("Got response from server " + ret);
  				}
  
  	            RMInitiator.stopClient();
  	        } catch (Exception e) {
  	            e.printStackTrace();
  	        }		
  	}	
  	
  	public void runEchoStringAsync(InteropBean bean){
          try {
              
              System.out.println("********* Running ECHO STRING Async");
              
              System.out.println("e11111");
  			String target = bean.getTarget();
  			String from = bean.getFrom();
  			String replyTo = bean.getReplyto();
  			String acks = bean.getAcks();
  			String terminate = bean.getTerminate();
  			String operation = bean.getOperation();
  			int messages = bean.getNoOfMsgs();
  	        
              //A separate listner will be started if the value of the input parameter for the mehthod
              // initClient is "false". If the service is of type request/response the parameter value shoule be "false"
              RMInitiator.initClient(false);
  
              //UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); //Can use this for continuous testing.
              //String str = uuidGen.nextUUID();
  
  
              Service service = new Service();
              Call call = (Call) service.createCall();
              System.out.println("e22222");
              //To obtain the
              call.setProperty(Constants.ClientProperties.SYNC, new Boolean(false));
              call.setProperty(Constants.ClientProperties.ACTION, "sandesha:echo");
  
              //These two are additional
              //call.setProperty("from","http://schemas.xmlsoap.org/ws/2003/03/addressing/role/anonymous");
              call.setProperty(Constants.ClientProperties.FROM,"http://127.0.0.1:" + "9070" + "/axis/services/RMService");
              call.setProperty(Constants.ClientProperties.REPLY_TO,"http://127.0.0.1:" + "9070" + "/axis/services/RMService");
  
              call.setTargetEndpointAddress(target);
              call.setOperationName(new QName("RMInteropService", "echoString"));
              call.setTransport(new RMTransport(target, ""));
  
              call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);
              call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN);
              call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
              System.out.println("e3333");
  			for(int i=1;i<=messages;i++){
  				call.setProperty(Constants.ClientProperties.MSG_NUMBER, new Long((i)));
  				String msg = "ECHO " + i;
  				
  
  				if(i==messages){
  					call.setProperty(Constants.ClientProperties.LAST_MESSAGE, new Boolean(true));
  				}
  				
  				String ret = (String) call.invoke(new Object[]{msg,"abcdef"});
  				System.out.println("Got response from server " + ret);
  				System.out.println("e44444");
  			}
  			System.out.println("e55555");
              RMInitiator.stopClient();
              System.out.println("e66666");
          } catch (Exception e) {
              e.printStackTrace();
          }		
  	}
  	
  }
  
  
  
  1.1                  ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient/ResponseWriter.java
  
  Index: ResponseWriter.java
  ===================================================================
  /*
   * Created on Apr 17, 2005
   *
   * To change the template for this generated file go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  package org.apache.sandesha.samples.interop.testclient;
  
  import java.io.PrintWriter;
  
  
  /**
   * @author root
   *
   * To change the template for this generated type comment go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  public class ResponseWriter {
  	
  	private PrintWriter writer;
  	
  	public ResponseWriter(PrintWriter writer){
  			this.writer = writer;
  	}
  	
  	public synchronized boolean write(String s){ 
  		try{
  			writer.println(s);
  			flush();
  			return true;
  		}catch(Exception e){
  			System.out.println("Exception: In method 'write' of 'ResponseWriter'");
  			return false;
  		}
  	}
  	
  	public synchronized void flush(){
  		writer.flush();
  	}
  }
  
  
  
  1.1                  ws-fx/sandesha/interop/org/apache/sandesha/samples/interop/testclient/TestRunnerThread.java
  
  Index: TestRunnerThread.java
  ===================================================================
  /*
   * Created on Apr 15, 2005
   *
   * To change the template for this generated file go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  package org.apache.sandesha.samples.interop.testclient;
  
  import javax.swing.JOptionPane;
  
  /**
   * @author root
   *
   * To change the template for this generated type comment go to
   * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
   */
  public class TestRunnerThread extends Thread {
  	private int method = 0;
  	private InteropBean bean;
  	
  	public void setMethod(int method){
  		this.method = method;
  	}
  	
  	public void setBean(InteropBean bean){
  		this.bean = bean;
  	}
  	
  	public void run(){
  		
  		InteropStub stub = new InteropStub ();
  		String operation = bean.getOperation();
  		
  		
  		if(operation.equalsIgnoreCase("ping")){
  			//JOptionPane.showMessageDialog(null,"RUNNING PING");
  			String from = bean.getFrom();
  			if(from==null || from.equalsIgnoreCase("anonymous URI")){
  				//JOptionPane.showMessageDialog(null,"RUNNING SYNC");
  				stub.runPingSync(bean);
  			}else {
  				//JOptionPane.showMessageDialog(null,"RUNNING ASYNC");
  				stub.runPingAsync(bean);
  			}
  			
  		}else if(operation.equalsIgnoreCase("echoString") ){
  			String from = bean.getFrom();
  			if(from==null || from.equalsIgnoreCase("anonymous URI")){
  				stub.runEchoStringSync(bean);
  			}else {
  				stub.runEchoStringAsync(bean);
  			}
  			
  		}
  		
  	}
  	
  	
  }