1 17 package org.apache.sandesha.interop.testclient; 18 19 import org.apache.sandesha.Constants; 20 import org.apache.sandesha.storage.Callback; 21 import org.apache.sandesha.storage.CallbackData; 22 23 28 public class InteropCallback extends Callback { 29 30 private ResponseWriter writer = null; 31 private boolean testFinished = false; 32 33 public synchronized void setTestFinished(boolean finished) { 34 this.testFinished = finished; 35 } 36 37 public synchronized boolean isTestFinished() { 38 return testFinished; 39 } 40 41 public InteropCallback(ResponseWriter writer) { 42 this.writer = writer; 43 } 44 45 public synchronized void onIncomingMessage(CallbackData result) { 46 47 String action = result.getAction(); 48 String msgType = action; 49 if (action != null) { 50 if (action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE)) 51 msgType = "Create Sequence"; 52 else if (action.equals(Constants.WSRM.ACTION_CREATE_SEQUENCE_RESPONSE)) 53 msgType = "Create Sequence Response"; 54 else if (action.equals(Constants.WSRM.ACTION_TERMINATE_SEQUENCE)) 55 msgType = "Terminate Sequence"; 56 else if (action.equals(Constants.WSRM.SEQUENCE_ACKNOWLEDGEMENT_ACTION)) 57 msgType = "Sequence Acknowledgement"; 58 } else { 59 msgType = ""; 60 61 } 62 63 String entry = ""; 64 if (result.getMessageId() != null && result.getMessageId() != "") 65 entry = "<br /><font color='green' size='2' > Received " + msgType + " Message. ID : " + 66 result.getMessageId() + "</font>"; else 68 entry = "<br /><font color='green' size='2' > Received " + msgType + "</font>"; 69 70 71 boolean b = writer.write(entry); 72 if (!b) 73 setTestFinished(true); 74 } 75 76 public synchronized void onOutgoingMessage(CallbackData result) { 77 78 int type = result.getMessageType(); 79 String msgType = null; 80 81 if (type == Constants.MSG_TYPE_CREATE_SEQUENCE_REQUEST) 82 msgType = "Create Sequence"; 83 else if (type == Constants.MSG_TYPE_CREATE_SEQUENCE_RESPONSE) 84 msgType = "Create Sequence Response"; 85 else if (type == Constants.MSG_TYPE_TERMINATE_SEQUENCE) 86 msgType = "Terminate Sequence"; 87 else if (type == Constants.MSG_TYPE_ACKNOWLEDGEMENT) 88 msgType = "Sequence Acknowledgement"; 89 else if (type == Constants.MSG_TYPE_SERVICE_REQUEST) 90 msgType = "Service Request"; 91 else if (type == Constants.MSG_TYPE_SERVICE_RESPONSE) 92 msgType = "Service Response"; 93 94 String entry = ""; 95 if (result.getMessageId() != null && result.getMessageId() != "") 96 entry = "<br /><font color='blue' size='2' > Sent " + msgType + " Message. ID : " + 97 result.getMessageId() + "</font>"; else { 99 entry = "<br /><font color='blue' size='2' > Sent " + msgType + "</font>"; 100 } 101 102 boolean b = writer.write(entry); 103 if (!b) 104 setTestFinished(true); 105 106 if (result.getMessageType() == 6) 107 setTestFinished(true); 108 109 } 110 111 public synchronized void onError(Exception exp) { 112 String message = "Error Occured During the Interop Test"; 113 if (exp.getMessage() != null) { 114 message = exp.getMessage(); 115 } 116 String entry = "<br /><font color='red' size='2' > Error : " + message + "</font>"; 117 boolean b = writer.write(entry); 118 if (!b) 119 setTestFinished(true); 120 } 121 122 } 123 | Popular Tags |