1 23 package org.objectweb.clif.isac.plugins.httpmatrix10.actions; 24 25 import java.io.IOException ; 26 import java.util.Hashtable ; 27 28 import org.apache.commons.httpclient.HttpMethod; 29 import org.apache.commons.httpclient.methods.GetMethod; 30 import org.apache.commons.httpclient.methods.PostMethod; 31 import org.objectweb.clif.isac.plugins.httpmatrix10.SessionObject; 32 import org.objectweb.clif.scenario.util.transitions.Transition; 33 import org.objectweb.clif.scenario.util.transitions.TransitionTable; 34 import org.objectweb.clif.storage.api.ActionEvent; 35 36 42 public class MatrixSamples { 43 private static final String METHOD = "method"; 45 private static final String POST_METHOD = "POST"; 46 private static final String GET_METHOD = "GET"; 47 48 54 public static ActionEvent doNext(SessionObject sessionObject, Hashtable params, 55 ActionEvent report) { 56 String methodType = (String )params.get(METHOD); 58 report.setDate(System.currentTimeMillis()); 60 TransitionTable transitionTable = sessionObject.getTransitionTable(); 62 Transition transition = transitionTable.getNextTransition(); 64 65 if (transition.isEndSession()) { 67 report.successful = true; 68 report.comment = "endSession"; 69 report.duration = 0; 70 sessionObject.setFinishState(true); 72 return report; 73 } 74 String [] actions = transition.getAction(); 76 String url = actions[0]; 78 HttpMethod method = null; 80 if (methodType.equals(GET_METHOD)) { 81 method = new GetMethod(url); 82 } 83 else if (methodType.equals(POST_METHOD)) { 84 method = new PostMethod(url); 85 } 86 else { 87 report.successful = false; 88 report.comment = "Unknow http injection method : "+methodType; 89 report.duration = 0; 90 return report; 91 } 92 method.setFollowRedirects(true); 93 method.setStrictMode(false); 94 report.comment = url; 96 try { 98 sessionObject.getHttpClient().executeMethod(method); 99 report.result = method.getStatusCode() + " - " 101 + method.getStatusText(); 102 report.successful = true; 103 } catch (IOException ioex) { 104 report.comment = "Unable to execute http method on " + url + " ->" 105 + ioex; 106 report.successful = false; 107 } finally { 108 method.releaseConnection(); 110 } 111 112 report.duration = (int) (System.currentTimeMillis() - report.getDate()); 114 115 return report; 117 } 118 } | Popular Tags |