1 17 package org.apache.sandesha.client; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.client.Call; 21 import org.apache.sandesha.Constants; 22 import org.apache.sandesha.RMMessageContext; 23 import org.apache.sandesha.SandeshaContext; 24 25 import javax.xml.namespace.QName ; 26 27 32 public class ClientPropertyValidator { 33 34 public static synchronized RMMessageContext validate(Call call) throws AxisFault { 35 36 RMMessageContext rmMessageContext = null; 37 38 boolean inOut = getInOut(call); 39 long msgNumber = getMessageNumber(call); 40 boolean lastMessage = getLastMessage(call); 41 boolean sync = getSync(call); 42 String action = getAction(call); 43 String sourceURL = null; 44 String from = getFrom(call); 45 String replyTo = getReplyTo(call); 46 String acksTo = getAcksTo(call); 47 String to = getTo(call); 48 String faultTo = getFaultTo(call); 49 boolean sendOffer = getOffer(call); 50 String key = getKey(call); 51 SandeshaContext ctx = getCtx(call); 52 53 try { 54 sourceURL = getSourceURL(call); 55 } catch (Exception e) { 56 throw new AxisFault(e.getMessage()); 57 } 58 59 String errorMsg = getValidated(msgNumber, action, replyTo, sync, inOut); 60 if (errorMsg == null) { 61 rmMessageContext = new RMMessageContext(); 62 63 rmMessageContext.setSync(sync); 64 rmMessageContext.setHasResponse(inOut); 65 rmMessageContext.setMsgNumber(msgNumber); 66 rmMessageContext.setLastMessage(lastMessage); 67 rmMessageContext.setSourceURL(sourceURL); 68 rmMessageContext.setSequenceID(key); 69 rmMessageContext.setReplyTo(replyTo); 70 rmMessageContext.setFrom(from); 71 rmMessageContext.setAction(action); 72 rmMessageContext.setAcksTo(acksTo); 73 rmMessageContext.setTo(to); 74 rmMessageContext.setFaultTo(faultTo); 75 rmMessageContext.setSendOffer(sendOffer); 76 rmMessageContext.setCtx(ctx); 77 return rmMessageContext; 78 79 } else 80 throw new AxisFault(errorMsg); 81 82 } 83 84 private static SandeshaContext getCtx(Call call) { 85 return (SandeshaContext) call.getProperty("context"); 86 } 87 88 private static String getKey(Call call) { 89 return (String ) call.getProperty(Constants.ClientProperties.CALL_KEY); 90 } 91 92 private static boolean getOffer(Call call) { 93 Boolean sendOffer = (Boolean ) call.getProperty(Constants.ClientProperties.SEND_OFFER); 94 if (sendOffer != null) { 95 return sendOffer.booleanValue(); 96 } else 97 return false; 98 } 99 100 private static String getFaultTo(Call call) { 101 String faultTo = (String ) call.getProperty(Constants.ClientProperties.FAULT_TO); 102 if (faultTo != null) 103 return faultTo; 104 else 105 return null; 106 } 107 108 private static String getTo(Call call) { 109 String to = (String ) call.getProperty(Constants.ClientProperties.TO); 110 if (to != null) 111 return to; 112 else 113 return call.getTargetEndpointAddress(); 114 } 115 116 117 125 private static boolean getInOut(Call call) { 126 QName returnQName = (QName ) call.getReturnType(); 127 if (returnQName != null) 128 return true; 129 else 130 return false; 131 132 } 133 134 135 private static String getAction(Call call) { 136 String action = (String ) call.getProperty(Constants.ClientProperties.ACTION); 137 if (action != null) 138 return action; 139 else 140 return null; 141 } 142 143 private static String getAcksTo(Call call) { 144 String acksTo = (String ) call.getProperty(Constants.ClientProperties.ACKS_TO); 145 if (acksTo != null) 146 return acksTo; 147 else 148 return null; 149 } 150 151 private static boolean getSync(Call call) { 152 Boolean synchronous = (Boolean ) call.getProperty(Constants.ClientProperties.SYNC); 153 if (synchronous != null) { 154 return synchronous.booleanValue(); 155 } else 156 return false; } 158 159 160 private static String getSourceURL(Call call) throws Exception { 161 String sourceURL = null; 162 sourceURL = (String ) call.getProperty(Constants.ClientProperties.SOURCE_URL); 163 if (sourceURL != null) { 164 return sourceURL; 165 } else { 166 throw new Exception ("No Source URL specified"); 167 168 } 169 } 170 171 175 private static long getMessageNumber(Call call) { 176 Object temp = call.getProperty(Constants.ClientProperties.MSG_NUMBER); 177 SandeshaContext ctx = (SandeshaContext) call.getProperty(Constants.CONTEXT); 178 long msgNo = ctx.getMessageNumber(); 179 if (temp == null) { 180 ctx.setMessageNumber(++msgNo); 181 } else { 182 msgNo = ((Long ) call.getProperty(Constants.ClientProperties.MSG_NUMBER)).longValue(); 183 184 } 185 186 return msgNo; 187 } 188 189 private static boolean getLastMessage(Call call) { 190 Boolean lastMessage = (Boolean ) call.getProperty(Constants.ClientProperties.LAST_MESSAGE); 191 if (lastMessage != null) 192 return lastMessage.booleanValue(); 193 else 194 return false; 195 196 } 197 198 private static String getValidated(long msgNumber, String action, String replyTo, boolean sync, 199 boolean inOut) { 200 String errorMsg = null; 201 202 if (sync && inOut && replyTo == null) { 203 errorMsg = Constants.ErrorMessages.CLIENT_PROPERTY_VALIDATION_ERROR; 204 return errorMsg; 205 } 206 207 if ((action == null)) { 208 errorMsg = Constants.ErrorMessages.MESSAGE_NUMBER_NOT_SPECIFIED; 209 return errorMsg; 210 } 211 return errorMsg; 212 } 213 214 private static String getFrom(Call call) { 215 return (String ) call.getProperty(Constants.ClientProperties.FROM); 216 } 217 218 private static String getReplyTo(Call call) { 219 return (String ) call.getProperty(Constants.ClientProperties.REPLY_TO); 220 } 221 222 } | Popular Tags |