|
Removed
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2005, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id: TestGenHttp.java,v 1.14 2007/04/26 21:07:34 paules Exp $ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* IBM Corporation - initial API and implementation |
| 11 |
**********************************************************************/ |
| 12 |
package org.eclipse.hyades.execution.testgen.http; |
| 13 |
|
| 14 |
import java.net.MalformedURLException; |
| 15 |
import java.net.URL; |
| 16 |
import java.util.ArrayList; |
| 17 |
import java.util.Collections; |
| 18 |
import java.util.Comparator; |
| 19 |
import java.util.HashMap; |
| 20 |
import java.util.LinkedList; |
| 21 |
import java.util.List; |
| 22 |
import java.util.ListIterator; |
| 23 |
import java.util.StringTokenizer; |
| 24 |
|
| 25 |
import org.eclipse.hyades.test.core.testgen.TestgenException; |
| 26 |
import org.eclipse.hyades.test.http.runner.HttpRequest; |
| 27 |
import org.eclipse.hyades.test.tools.core.http.util.RequestHelper; |
| 28 |
import org.eclipse.hyades.test.tools.core.internal.resources.CorePluginResourceBundle; |
| 29 |
|
| 30 |
|
| 31 |
/** |
| 32 |
* @author mdunn |
| 33 |
* |
| 34 |
* @deprecated should not be public API. Will be changed to internal in TPTP 5. |
| 35 |
*/ |
| 36 |
public class TestGenHttp |
| 37 |
{ |
| 38 |
private static final String PACKET_A_CONNECTIONNAME |
| 39 |
= "connectionNumber"; |
| 40 |
private static final String PACKET_S_DATA |
| 41 |
= "data"; |
| 42 |
private static final String PACKET_S_DATA_A_ENCODING |
| 43 |
= "encoding"; |
| 44 |
private static final String PACKET_S_DATA_A_ENCODING_V_NONE |
| 45 |
= "NONE"; |
| 46 |
private static final String PACKET_S_DATA_A_ENCODING_V_ASCIIFY |
| 47 |
= "ASCIIFY"; |
| 48 |
private static final String PACKET_S_DATA_A_ENCODING_V_BASE64 |
| 49 |
= "BASE64"; |
| 50 |
// private static final String PACKET_S_DATA_A_LENGTH |
| 51 |
// = "length"; |
| 52 |
private static final String PACKET_S_DATA_A_TYPE |
| 53 |
= "type"; |
| 54 |
private static final String PACKET_S_DATA_A_TYPE_V_HTTPCONTENT |
| 55 |
= "HTTPCONTENT"; |
| 56 |
private static final String PACKET_S_DATA_A_TYPE_V_HTTPMESSAGE |
| 57 |
= "HTTPMESSAGE"; |
| 58 |
//added for bugzilla #90867 - tejas.patel@ca.com |
| 59 |
private static final String PACKET_S_DATA_A_TYPE_V_HTTPDATA |
| 60 |
= "HTTPDATA"; |
| 61 |
private static final String PACKET_A_FROM |
| 62 |
= "from"; |
| 63 |
private static final String PACKET_A_FROM_V_CLIENT |
| 64 |
= "CLIENT"; |
| 65 |
private static final String PACKET_A_FROM_V_SERVER |
| 66 |
= "SERVER"; |
| 67 |
// private static final String PACKET_A_TICKET |
| 68 |
// = "ticket"; |
| 69 |
private static final String PACKET_A_TIMESTAMP |
| 70 |
= "timestamp"; |
| 71 |
private static final String PACKET_A_TYPE |
| 72 |
= "type"; |
| 73 |
// private static final String PACKET_A_TYPE_V_HTTP |
| 74 |
// = "HTTP"; |
| 75 |
private static final String PACKET_A_TYPE_V_HTTPS |
| 76 |
= "HTTPS"; |
| 77 |
|
| 78 |
private static final String HTTP_POST = "POST"; |
| 79 |
|
| 80 |
private static final String CRNL = "\r\n"; |
| 81 |
private static final char SLASH = '/'; |
| 82 |
private static final char COLON = ':'; |
| 83 |
private static final String BLANK = " "; |
| 84 |
|
| 85 |
private boolean isNewType = false; |
| 86 |
|
| 87 |
private class ParsedHttpMessage |
| 88 |
{ |
| 89 |
String method; |
| 90 |
String protocol; |
| 91 |
String host; |
| 92 |
int port; |
| 93 |
String path; |
| 94 |
String version; |
| 95 |
boolean bSSL; |
| 96 |
int enumPage; |
| 97 |
int nPageNum; |
| 98 |
int nConnID; |
| 99 |
boolean newPage; |
| 100 |
String timeStampString; |
| 101 |
ArrayList headerNames = new ArrayList(); |
| 102 |
ArrayList headerValues = new ArrayList(); |
| 103 |
StringBuffer body = new StringBuffer(); |
| 104 |
} |
| 105 |
// New Object to handle |
| 106 |
private class ConnectionNode |
| 107 |
{ |
| 108 |
int connectionNumber; |
| 109 |
LinkedList childrenNodes; |
| 110 |
} |
| 111 |
// Object to hold Response information |
| 112 |
private class ResponseInfo { |
| 113 |
String timeStampString; |
| 114 |
boolean newPage; |
| 115 |
} |
| 116 |
/** |
| 117 |
* Comparator class which compares the nodes in the linked list according |
| 118 |
* to the timestamp values |
| 119 |
* @author shobhit.maini@ca.com |
| 120 |
* |
| 121 |
*/ |
| 122 |
private class NewPageListComparator implements Comparator{ |
| 123 |
|
| 124 |
public int compare(Object Node1, Object Node2) { |
| 125 |
|
| 126 |
TRCNode node1 = (TRCNode) Node1; |
| 127 |
TRCNode node2 = (TRCNode) Node2; |
| 128 |
|
| 129 |
String node1Timestamp = TRCNodeHandler.getAttributeValue(PACKET_A_TIMESTAMP, node1); |
| 130 |
String node2Timestamp = TRCNodeHandler.getAttributeValue(PACKET_A_TIMESTAMP, node2); |
| 131 |
|
| 132 |
int node1TimestampVal = Integer.parseInt(node1Timestamp); |
| 133 |
int node2TimestampVal = Integer.parseInt(node2Timestamp); |
| 134 |
|
| 135 |
if(node1TimestampVal > node2TimestampVal){ |
| 136 |
return 1; |
| 137 |
} |
| 138 |
else if (node1TimestampVal < node2TimestampVal){ |
| 139 |
return -1; |
| 140 |
}else return 0; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
LinkedList connectionsList; |
| 145 |
|
| 146 |
// private HashMap lastRecvHashMap = new HashMap(); |
| 147 |
private ParsedHttpMessage currentHttpRequest; |
| 148 |
private ParsedHttpMessage previousHttpRequest; |
| 149 |
TRCContext context = null; |
| 150 |
LinkedList newPageList; |
| 151 |
|
| 152 |
/** |
| 153 |
* @param context |
| 154 |
*/ |
| 155 |
public TestGenHttp (TRCContext context) |
| 156 |
{ |
| 157 |
super(); |
| 158 |
|
| 159 |
this.context = context; |
| 160 |
connectionsList = new LinkedList(); |
| 161 |
newPageList = new LinkedList(); |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Parse Request Message for Message information |
| 166 |
* modified for bugzilla #90867 & #83976 -george.sebastian@ca.com |
| 167 |
* @param dataNode |
| 168 |
* @throws TestgenException |
| 169 |
*/ |
| 170 |
private void httpRequestMessage (TRCNode dataNode) |
| 171 |
throws TestgenException |
| 172 |
{ |
| 173 |
String tempContent = null; |
| 174 |
byte[] decContent = null; |
| 175 |
String content = dataNode.getElement().getContent(); |
| 176 |
if (content == null) |
| 177 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 178 |
|
| 179 |
String encoding = getAttributeValue(PACKET_S_DATA_A_ENCODING, dataNode); |
| 180 |
if (encoding == null) |
| 181 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_ENCODING_ATT, null); |
| 182 |
// TODO: dhinson: needs to handle non-NONE encodings eventually |
| 183 |
// TODO: dhinson: change to equals() when DuWayne fixes value |
| 184 |
if (encoding.equalsIgnoreCase(PACKET_S_DATA_A_ENCODING_V_NONE)) |
| 185 |
; // do nothing (no translation required) |
| 186 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_ASCIIFY)) { |
| 187 |
TRCAsciifier myasc = new TRCAsciifier(); |
| 188 |
decContent = new byte[content.length()]; |
| 189 |
myasc.decode(content, 0, content.length(), decContent); |
| 190 |
tempContent = new String(decContent); |
| 191 |
String tmp = tempContent.trim(); |
| 192 |
content = tmp; |
| 193 |
//return; // silently ignore |
| 194 |
} |
| 195 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_BASE64)) |
| 196 |
return; // silently ignore |
| 197 |
else |
| 198 |
return; // silently ignore |
| 199 |
|
| 200 |
StringTokenizer bodyTokenizer = new StringTokenizer(content, CRNL); |
| 201 |
for (int headerCount = 0; bodyTokenizer.hasMoreTokens(); |
| 202 |
++headerCount) { |
| 203 |
String header = bodyTokenizer.nextToken(); |
| 204 |
if (headerCount == 0) { |
| 205 |
StringTokenizer headerTokenizer = new StringTokenizer(header); |
| 206 |
|
| 207 |
currentHttpRequest.method = headerTokenizer.nextToken(); |
| 208 |
|
| 209 |
String urn = headerTokenizer.nextToken(); |
| 210 |
if (urn.length() > 6 && urn.substring(0, 7).equals("http://")) { |
| 211 |
try { |
| 212 |
URL url = new URL(urn); |
| 213 |
currentHttpRequest.path = url.getPath(); |
| 214 |
} |
| 215 |
catch (MalformedURLException e) { |
| 216 |
} |
| 217 |
} else |
| 218 |
currentHttpRequest.path = urn; |
| 219 |
|
| 220 |
String version = headerTokenizer.nextToken(); |
| 221 |
currentHttpRequest.version = |
| 222 |
version.substring(version.indexOf(SLASH) + 1, |
| 223 |
version.length()); |
| 224 |
} |
| 225 |
else { |
| 226 |
int colonIndex = header.indexOf(COLON); |
| 227 |
if(colonIndex!=-1){ |
| 228 |
String name = header.substring(0, colonIndex); |
| 229 |
String value = header.substring(colonIndex + 1, header.length()); |
| 230 |
currentHttpRequest.headerNames.add(name); |
| 231 |
currentHttpRequest.headerValues.add(value); |
| 232 |
|
| 233 |
// fetch host and port from Host: header |
| 234 |
if (name.trim().equals("Host")) { |
| 235 |
try { |
| 236 |
URL url = new URL("http://" + value.trim()); |
| 237 |
currentHttpRequest.host = url.getHost(); |
| 238 |
currentHttpRequest.port = url.getPort(); |
| 239 |
if (currentHttpRequest.port == -1) { |
| 240 |
// Check if SSL - if so, use 443 for port |
| 241 |
if (currentHttpRequest.bSSL) |
| 242 |
currentHttpRequest.port = 443; |
| 243 |
else |
| 244 |
currentHttpRequest.port = 80; |
| 245 |
} |
| 246 |
} |
| 247 |
catch (MalformedURLException e) { |
| 248 |
e.printStackTrace(); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
else if(!(CRNL+CRNL).equalsIgnoreCase(header)){ |
| 253 |
currentHttpRequest.body.append(header); |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
/** |
| 260 |
|
| 261 |
* |
| 262 |
* @param dataNode |
| 263 |
* modified for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 264 |
* @throws TestgenException |
| 265 |
*/ |
| 266 |
private void httpRequestContent (TRCNode dataNode) |
| 267 |
throws TestgenException |
| 268 |
{ |
| 269 |
String content = dataNode.getElement().getContent(); |
| 270 |
if (content == null) |
| 271 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 272 |
|
| 273 |
String encoding = getAttributeValue(PACKET_S_DATA_A_ENCODING, dataNode); |
| 274 |
if (encoding == null) |
| 275 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_ENCODING_ATT, null); |
| 276 |
// TODO: dhinson: needs to handle non-NONE encodings eventually |
| 277 |
// TODO: dhinson: change to equals() when DuWayne fixes value |
| 278 |
if (encoding.equalsIgnoreCase(PACKET_S_DATA_A_ENCODING_V_NONE)) |
| 279 |
currentHttpRequest.body.append(content); |
| 280 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_ASCIIFY)) |
| 281 |
; // silently ignore |
| 282 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_BASE64)) |
| 283 |
; // silently ignore |
| 284 |
else |
| 285 |
; // silently ignore |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* This method is called when the TRCRecordingInfo node handler |
| 290 |
* has determined that a STOP message has been found |
| 291 |
* |
| 292 |
* This method will call reorderNodeList() to reorder the list of |
| 293 |
* nodes, then call writeNewPageList() to parse the node list and |
| 294 |
* write the information into the behavior model. |
| 295 |
* |
| 296 |
* @throws TestgenException |
| 297 |
* modified for bugzilla #90867 - george.sebastian@ca.com |
| 298 |
*/ |
| 299 |
protected void handle_http_stop() throws TestgenException { |
| 300 |
// remove_unwanted_responses(); |
| 301 |
// Call new routine to group the nodes |
| 302 |
reorderNodeList(); |
| 303 |
reorderNodeListAccordingToTimestamp(); |
| 304 |
writeNewPageList(); |
| 305 |
//determinePageEnum(); |
| 306 |
//writePageList(); |
| 307 |
context.setPageNumber(0); |
| 308 |
|
| 309 |
} |
| 310 |
/** |
| 311 |
* This method will parse a http response and return whether it |
| 312 |
* is a new page or not (Content-Type: equals text/html ) |
| 313 |
* |
| 314 |
* @param node |
| 315 |
* @return true if Content-Type header equals text/html |
| 316 |
* modified for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 317 |
* @throws TestgenException |
| 318 |
*/ |
| 319 |
private boolean checkResponseForNewPage(TRCNode node) |
| 320 |
throws TestgenException { |
| 321 |
boolean retcode = false; |
| 322 |
|
| 323 |
|
| 324 |
List dataNodeList = TRCNodeHandler.getSubNodeList(PACKET_S_DATA, node); |
| 325 |
if (dataNodeList.isEmpty()) |
| 326 |
throw new TestgenException(CorePluginResourceBundle.E_PACKET_NO_DATA, null); |
| 327 |
|
| 328 |
// populate currentHttpRequest |
| 329 |
ListIterator itr = dataNodeList.listIterator(); |
| 330 |
while (itr.hasNext()) { |
| 331 |
TRCNode dataNode = (TRCNode)itr.next(); |
| 332 |
|
| 333 |
String type = TRCNodeHandler.getAttributeValue(PACKET_S_DATA_A_TYPE, dataNode); |
| 334 |
if (type == null) |
| 335 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_TYPE_ATT, null); |
| 336 |
|
| 337 |
if(type.equalsIgnoreCase(PACKET_S_DATA_A_TYPE_V_HTTPDATA)){ |
| 338 |
retcode = httpRequestMessageContentType(dataNode); |
| 339 |
break; |
| 340 |
} |
| 341 |
if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPMESSAGE)){ |
| 342 |
retcode = httpRequestMessageContentType(dataNode); |
| 343 |
break; |
| 344 |
} |
| 345 |
else |
| 346 |
// ignore any others |
| 347 |
continue; |
| 348 |
} |
| 349 |
return retcode; |
| 350 |
} |
| 351 |
/** |
| 352 |
* Parse http Request to see if Content-Type: is |
| 353 |
* text/html. Return true to indicate new page. |
| 354 |
* |
| 355 |
* @param dataNode |
| 356 |
* modified for bugzilla #90867 & #83976 -george.sebastian@ca.com |
| 357 |
* @return |
| 358 |
* @throws TestgenException |
| 359 |
*/ |
| 360 |
private boolean httpRequestMessageContentType(TRCNode dataNode) |
| 361 |
throws TestgenException { |
| 362 |
boolean isNewPage = false; |
| 363 |
|
| 364 |
String content = dataNode.getElement().getContent(); |
| 365 |
if (content == null) |
| 366 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 367 |
int contentLocation = getContentLocation(content); |
| 368 |
if (contentLocation!=-1){ |
| 369 |
content = content.substring(0,contentLocation-CRNL.length()); |
| 370 |
} |
| 371 |
StringTokenizer bodyTokenizer = new StringTokenizer(content, CRNL); |
| 372 |
for (int headerCount = 0; bodyTokenizer.hasMoreTokens(); |
| 373 |
++headerCount) { |
| 374 |
String header = bodyTokenizer.nextToken(); |
| 375 |
if (headerCount == 0) { |
| 376 |
// Do nothing |
| 377 |
} |
| 378 |
else { |
| 379 |
int colonIndex = header.indexOf(COLON); |
| 380 |
if(colonIndex==-1){ |
| 381 |
continue; |
| 382 |
} |
| 383 |
String name = header.substring(0, colonIndex); |
| 384 |
String value = header.substring(colonIndex + 1, header.length()); |
| 385 |
|
| 386 |
// fetch Content-Type |
| 387 |
if (name.trim().equalsIgnoreCase("Content-Type")) { |
| 388 |
String tempstr = value.trim().toLowerCase(); |
| 389 |
if (tempstr.trim().startsWith("text/html")) |
| 390 |
isNewPage = true; |
| 391 |
else |
| 392 |
isNewPage = false; |
| 393 |
break; |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
if (!isNewPage) { |
| 398 |
// now check for Redirection - status code of 301 or 302 |
| 399 |
isNewPage = checkForRedirect(dataNode); |
| 400 |
} |
| 401 |
return isNewPage; |
| 402 |
} |
| 403 |
/** |
| 404 |
* Loops through the original list of TRCNode nodes, removing responses |
| 405 |
* that contain html or jpeg information (that don't have headers) |
| 406 |
* |
| 407 |
* @throws TestgenException |
| 408 |
*/ |
| 409 |
private void remove_unwanted_responses() throws TestgenException { |
| 410 |
LinkedList pageList = null; |
| 411 |
boolean writethisNode = true; |
| 412 |
int totalNodes = 0; |
| 413 |
int i = 0; |
| 414 |
TRCNode node = null; |
| 415 |
LinkedList newPageList = new LinkedList(); |
| 416 |
|
| 417 |
pageList = context.getPageList(); |
| 418 |
totalNodes = pageList.size(); |
| 419 |
for (i = 0; i < totalNodes; i++) { |
| 420 |
node = (TRCNode)pageList.get(i); |
| 421 |
writethisNode = shouldIWriteNode(node); |
| 422 |
if (writethisNode) |
| 423 |
newPageList.add(node); |
| 424 |
} |
| 425 |
int newTotalNodes = newPageList.size(); |
| 426 |
if (newTotalNodes > 0){ |
| 427 |
pageList.clear(); |
| 428 |
context.setPageList(newPageList); |
| 429 |
} |
| 430 |
} |
| 431 |
/** |
| 432 |
* Determine whether a node has information we need and should be |
| 433 |
* included in the new list of nodes. |
| 434 |
* |
| 435 |
* @param node |
| 436 |
* modified for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 437 |
* @return false if this node is from server and is content only |
| 438 |
* @throws TestgenException |
| 439 |
*/ |
| 440 |
boolean shouldIWriteNode(TRCNode node) throws TestgenException { |
| 441 |
boolean writeNode = true; |
| 442 |
boolean fromServer = false; |
| 443 |
boolean isContent = false; |
| 444 |
|
| 445 |
// populate currentHttpRequest |
| 446 |
|
| 447 |
String from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, node); |
| 448 |
if (from.equals(PACKET_A_FROM_V_CLIENT)) { |
| 449 |
return true; |
| 450 |
} |
| 451 |
else if (from.equals(PACKET_A_FROM_V_SERVER)) { |
| 452 |
fromServer = true; |
| 453 |
} |
| 454 |
|
| 455 |
List dataNodeList = TRCNodeHandler.getSubNodeList(PACKET_S_DATA, node); |
| 456 |
if (dataNodeList.isEmpty()) |
| 457 |
throw new TestgenException(CorePluginResourceBundle.E_PACKET_NO_DATA, null); |
| 458 |
|
| 459 |
ListIterator itr = dataNodeList.listIterator(); |
| 460 |
while (itr.hasNext()) { |
| 461 |
TRCNode dataNode = (TRCNode)itr.next(); |
| 462 |
|
| 463 |
String type = TRCNodeHandler.getAttributeValue(PACKET_S_DATA_A_TYPE, dataNode); |
| 464 |
if (type == null) |
| 465 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_TYPE_ATT, null); |
| 466 |
if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPMESSAGE)) { |
| 467 |
return true; |
| 468 |
} |
| 469 |
if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPCONTENT)) { |
| 470 |
isContent = true; |
| 471 |
break; |
| 472 |
} |
| 473 |
if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPDATA)){ |
| 474 |
isNewType = true; |
| 475 |
return true; |
| 476 |
} |
| 477 |
else |
| 478 |
// ignore any others |
| 479 |
continue; |
| 480 |
} |
| 481 |
if (fromServer && isContent) |
| 482 |
writeNode = false; |
| 483 |
|
| 484 |
return writeNode; |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* @param node |
| 489 |
* @return true if this node is a response (from server) |
| 490 |
*/ |
| 491 |
boolean checkIsResponse(TRCNode node) { |
| 492 |
boolean isResponse = false; |
| 493 |
|
| 494 |
String from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, node); |
| 495 |
if (from.equals(PACKET_A_FROM_V_CLIENT)){ |
| 496 |
isResponse = false; |
| 497 |
} |
| 498 |
else if (from.equals(PACKET_A_FROM_V_SERVER)) { |
| 499 |
isResponse = true; |
| 500 |
} |
| 501 |
return isResponse; |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* @param node |
| 506 |
* @return true if this node is from the CLIENT |
| 507 |
*/ |
| 508 |
boolean checkIsRequest(TRCNode node) { |
| 509 |
boolean isRequest = false; |
| 510 |
|
| 511 |
String from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, node); |
| 512 |
if (from.equals(PACKET_A_FROM_V_CLIENT)){ |
| 513 |
isRequest = true; |
| 514 |
} |
| 515 |
else if (from.equals(PACKET_A_FROM_V_SERVER)) { |
| 516 |
isRequest = false; |
| 517 |
} |
| 518 |
return isRequest; |
| 519 |
} |
| 520 |
/** |
| 521 |
* Check response for status code of 301 or 302 which indicates redirection |
| 522 |
* |
| 523 |
* @param node |
| 524 |
* @return |
| 525 |
* @throws TestgenException |
| 526 |
*/ |
| 527 |
boolean checkForRedirect(TRCNode node) throws TestgenException { |
| 528 |
|
| 529 |
boolean isRedirect = false; |
| 530 |
String content = node.getElement().getContent(); |
| 531 |
if (content == null) { |
| 532 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 533 |
} |
| 534 |
StringTokenizer bodyTokenizer = new StringTokenizer(content, CRNL); |
| 535 |
String statusLine = bodyTokenizer.nextToken(); |
| 536 |
// at this point have HTTP/1.1 301 Object Temporarily Moved |
| 537 |
StringTokenizer status = new StringTokenizer(statusLine, BLANK); |
| 538 |
status.nextToken(); // This is HTTP/1.1 |
| 539 |
String actualStatus = status.nextToken();// This is 200 or 302 or 301, etc... |
| 540 |
Integer intStat = new Integer(actualStatus); |
| 541 |
int actualVal = intStat.intValue(); |
| 542 |
if ((actualVal == 302) || (actualVal == 301)) |
| 543 |
isRedirect = true; |
| 544 |
|
| 545 |
return isRedirect; |
| 546 |
} |
| 547 |
/** |
| 548 |
* @param node |
| 549 |
* modifed for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 550 |
* @return |
| 551 |
* @throws TestgenException |
| 552 |
*/ |
| 553 |
private boolean parseHttpRequest (TRCNode node) |
| 554 |
throws TestgenException |
| 555 |
{ |
| 556 |
boolean retcode = false; |
| 557 |
String timestampString = TRCNodeHandler.getAttributeValue(PACKET_A_TIMESTAMP, node); |
| 558 |
|
| 559 |
List dataNodeList = TRCNodeHandler.getSubNodeList(PACKET_S_DATA, node); |
| 560 |
if (dataNodeList.isEmpty()) |
| 561 |
throw new TestgenException(CorePluginResourceBundle.E_PACKET_NO_DATA, null); |
| 562 |
|
| 563 |
// reset currentHttpRequest |
| 564 |
currentHttpRequest = new ParsedHttpMessage(); |
| 565 |
|
| 566 |
String typeValue = TRCNodeHandler.getAttributeValue(PACKET_A_TYPE, node); |
| 567 |
if (typeValue.equals(PACKET_A_TYPE_V_HTTPS)) |
| 568 |
currentHttpRequest.bSSL = true; |
| 569 |
else |
| 570 |
currentHttpRequest.bSSL = false; |
| 571 |
|
| 572 |
// populate currentHttpRequest |
| 573 |
ListIterator itr = dataNodeList.listIterator(); |
| 574 |
while (itr.hasNext()) { |
| 575 |
TRCNode dataNode = (TRCNode)itr.next(); |
| 576 |
|
| 577 |
String type = TRCNodeHandler.getAttributeValue(PACKET_S_DATA_A_TYPE, dataNode); |
| 578 |
if (type == null) |
| 579 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_TYPE_ATT, null); |
| 580 |
|
| 581 |
if(type.equals(PACKET_S_DATA_A_TYPE_V_HTTPDATA)){ |
| 582 |
httpRequestMessage(dataNode); |
| 583 |
//httpRequestContent(dataNode); |
| 584 |
} |
| 585 |
else if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPMESSAGE)) |
| 586 |
httpRequestMessage(dataNode); |
| 587 |
else if (type.equals(PACKET_S_DATA_A_TYPE_V_HTTPCONTENT)) |
| 588 |
httpRequestContent(dataNode); |
| 589 |
else |
| 590 |
// ignore any others |
| 591 |
continue; |
| 592 |
} |
| 593 |
|
| 594 |
int pageNumber = context.getPageNumber(); |
| 595 |
currentHttpRequest.nPageNum = pageNumber; |
| 596 |
String connectionNumber = TRCNodeHandler.getAttributeValue(PACKET_A_CONNECTIONNAME, node); |
| 597 |
Integer thisConn = new Integer(connectionNumber); |
| 598 |
currentHttpRequest.nConnID = thisConn.intValue(); |
| 599 |
currentHttpRequest.timeStampString = timestampString; |
| 600 |
|
| 601 |
return retcode; |
| 602 |
} |
| 603 |
/** |
| 604 |
* @param thisMessage |
| 605 |
* @return |
| 606 |
*/ |
| 607 |
private boolean createPage(ParsedHttpMessage thisMessage){ |
| 608 |
boolean retcode = false; |
| 609 |
|
| 610 |
int timestamp = 0; |
| 611 |
|
| 612 |
int pageNumber = context.getPageNumber(); |
| 613 |
|
| 614 |
String timestampString = thisMessage.timeStampString; |
| 615 |
if (timestampString != null) |
| 616 |
timestamp = Integer.parseInt(timestampString); |
| 617 |
if ((thisMessage.enumPage == HttpRequest.PAGE_ONLY) || (thisMessage.enumPage == HttpRequest.PAGE_START) |
| 618 |
|| (pageNumber == 0)) |
| 619 |
{ |
| 620 |
pageNumber += 1; |
| 621 |
context.setPageNumber(pageNumber); |
| 622 |
// thisLoop = context.createNewPage(pageNumber); |
| 623 |
String newPageName = thisMessage.host + thisMessage.path; |
| 624 |
context.createNewPage(newPageName); |
| 625 |
} |
| 626 |
String testCaseName = thisMessage.method + " " + |
| 627 |
thisMessage.host; |
| 628 |
context.newTestCaseContext(testCaseName); |
| 629 |
thisMessage.nPageNum = pageNumber; |
| 630 |
// fetch and populate RequestHelper... |
| 631 |
RequestHelper requestHelper = context.getRequestHelper(); |
| 632 |
|
| 633 |
// ... headers |
| 634 |
requestHelper.setAttribute(RequestHelper.ATT_METHOD, |
| 635 |
thisMessage.method); |
| 636 |
requestHelper.setAttribute(RequestHelper.ATT_HOST, |
| 637 |
thisMessage.host); |
| 638 |
requestHelper.setAttribute(RequestHelper.ATT_PORT, |
| 639 |
Integer.toString(thisMessage.port)); |
| 640 |
requestHelper.setAttribute(RequestHelper.ATT_ABS_PATH, |
| 641 |
thisMessage.path); |
| 642 |
requestHelper.setAttribute(RequestHelper.ATT_VERSION, |
| 643 |
thisMessage.version); |
| 644 |
for (int i = 0; i < thisMessage.headerNames.size(); ++i) |
| 645 |
requestHelper.setHeader(((String)thisMessage.headerNames. |
| 646 |
get(i)).trim(), ((String)thisMessage.headerValues. |
| 647 |
get(i)).trim()); |
| 648 |
|
| 649 |
// New attributes from RequestHelper mdd |
| 650 |
// ATT_PAGE_NUM = 8; |
| 651 |
// ATT_PAGE_ORDER = 9; |
| 652 |
// ATT_CONN_ID = 10; |
| 653 |
// ATT_CONN_ORDER = 11; |
| 654 |
// ATT_IS_SSL = 12; |
| 655 |
|
| 656 |
requestHelper.setAttribute(RequestHelper.ATT_PAGE_NUM, |
| 657 |
Integer.toString(thisMessage.nPageNum)); |
| 658 |
requestHelper.setAttribute(RequestHelper.ATT_PAGE_ORDER, |
| 659 |
Integer.toString(thisMessage.enumPage)); |
| 660 |
requestHelper.setAttribute(RequestHelper.ATT_CONN_ID, |
| 661 |
Integer.toString(thisMessage.nConnID)); |
| 662 |
if (thisMessage.bSSL) |
| 663 |
requestHelper.setAttribute(RequestHelper.ATT_IS_SSL, "true"); |
| 664 |
else |
| 665 |
requestHelper.setAttribute(RequestHelper.ATT_IS_SSL, "false"); |
| 666 |
|
| 667 |
// ... body |
| 668 |
requestHelper.setAttribute(RequestHelper.ATT_BODY, |
| 669 |
thisMessage.body.toString()); |
| 670 |
|
| 671 |
// ... calculate and set request's think time |
| 672 |
HashMap myLastRecvHashMap = context.getLastRecvHashMap(); |
| 673 |
|
| 674 |
int thinkTime = 0; |
| 675 |
Integer lastRecvInteger = (Integer)myLastRecvHashMap.get(TRCContext.GLOBAL_LASTRECV); |
| 676 |
if (lastRecvInteger != null) { |
| 677 |
int lastRecv = lastRecvInteger.intValue(); |
| 678 |
// thinkTime = (lastRecv == -1) ? timestamp : timestamp - lastRecv; |
| 679 |
thinkTime = (lastRecv == -1) ? 0 : timestamp - lastRecv; |
| 680 |
if (thinkTime < 0) |
| 681 |
thinkTime = 0; |
| 682 |
} |
| 683 |
requestHelper.setAttribute(RequestHelper.ATT_THINK_TIME, |
| 684 |
Integer.toString(thinkTime)); |
| 685 |
|
| 686 |
return retcode; |
| 687 |
} |
| 688 |
|
| 689 |
/** |
| 690 |
* @param node |
| 691 |
* @return |
| 692 |
* @throws TestgenException |
| 693 |
*/ |
| 694 |
private ResponseInfo parseHttpResponse(TRCNode node) throws TestgenException { |
| 695 |
ResponseInfo thisResponse = new ResponseInfo(); |
| 696 |
HashMap myLastRecvHashMap = context.getLastRecvHashMap(); |
| 697 |
|
| 698 |
int timestamp = Integer.parseInt(TRCNodeHandler.getAttributeValue(PACKET_A_TIMESTAMP, |
| 699 |
node)); |
| 700 |
myLastRecvHashMap.put(TRCContext.GLOBAL_LASTRECV, new Integer(timestamp)); |
| 701 |
context.setLastRecvHashMap(myLastRecvHashMap); |
| 702 |
thisResponse.timeStampString = TRCNodeHandler.getAttributeValue(PACKET_A_TIMESTAMP,node); |
| 703 |
thisResponse.newPage = checkResponseForNewPage(node); |
| 704 |
|
| 705 |
return thisResponse; |
| 706 |
} |
| 707 |
|
| 708 |
/** |
| 709 |
* @throws TestgenException |
| 710 |
* This routine will reorder the node list in connections then use the new |
| 711 |
* this list to process. |
| 712 |
*/ |
| 713 |
private void reorderNodeList() throws TestgenException { |
| 714 |
int totalNodes = -1; |
| 715 |
int i = 0; |
| 716 |
remove_unwanted_responses(); |
| 717 |
LinkedList originalNodeList = context.getPageList(); |
| 718 |
totalNodes = originalNodeList.size(); |
| 719 |
TRCNode node; |
| 720 |
int connectionIndex = -1; |
| 721 |
int connectionNumber = -1; |
| 722 |
|
| 723 |
for (i = 0; i < totalNodes; i++){ |
| 724 |
// check connection number first |
| 725 |
node = (TRCNode)originalNodeList.get(i); |
| 726 |
String strConnectionNumber = TRCNodeHandler.getAttributeValue(PACKET_A_CONNECTIONNAME, node); |
| 727 |
Integer thisConn = new Integer(strConnectionNumber); |
| 728 |
connectionNumber = thisConn.intValue(); |
| 729 |
|
| 730 |
connectionIndex = findConnection(connectionNumber); |
| 731 |
if (connectionIndex == -1) { |
| 732 |
addConnectionNode(connectionNumber,node); |
| 733 |
} |
| 734 |
else { |
| 735 |
addConnectionChild(connectionIndex, node); |
| 736 |
} |
| 737 |
} |
| 738 |
// Now replace old List with New List |
| 739 |
createNewPageList(); |
| 740 |
} |
| 741 |
/** |
| 742 |
* Reorders the nodes in newpage list in the ascending order of time stamp |
| 743 |
* added for for bugzilla #90867 & #83976 - shobhit.maini@ca.com |
| 744 |
* @throws TestgenException |
| 745 |
*/ |
| 746 |
|
| 747 |
private void reorderNodeListAccordingToTimestamp() throws TestgenException { |
| 748 |
|
| 749 |
Collections.sort(newPageList, new NewPageListComparator()); |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
/** |
| 755 |
* This routine will return the index for this connection, if it exists |
| 756 |
* |
| 757 |
* @param connectionNumber |
| 758 |
* the connection number to find |
| 759 |
* @return |
| 760 |
* The index of the found connection number or |
| 761 |
* -1 if not found |
| 762 |
*/ |
| 763 |
private int findConnection(int connectionNumber) { |
| 764 |
int foundIndex = -1; |
| 765 |
int numberOfConnections = -1; |
| 766 |
int i = 0; |
| 767 |
ConnectionNode thisConnection; |
| 768 |
|
| 769 |
numberOfConnections = connectionsList.size(); |
| 770 |
if (numberOfConnections == 0) { |
| 771 |
foundIndex = -1; |
| 772 |
} |
| 773 |
else { |
| 774 |
for (i = 0; i < numberOfConnections; i++) { |
| 775 |
thisConnection = (ConnectionNode)connectionsList.get(i); |
| 776 |
if (thisConnection.connectionNumber == connectionNumber) { |
| 777 |
foundIndex = i; |
| 778 |
break; |
| 779 |
} |
| 780 |
} |
| 781 |
} |
| 782 |
return foundIndex; |
| 783 |
} |
| 784 |
|
| 785 |
/** |
| 786 |
* This method creates a new Connection node, and adds newNode as |
| 787 |
* the first child of that node |
| 788 |
* |
| 789 |
* @param connectionNumber |
| 790 |
* @param newNode |
| 791 |
* @return |
| 792 |
*/ |
| 793 |
private boolean addConnectionNode(int connectionNumber, TRCNode newNode){ |
| 794 |
boolean retcode = true; |
| 795 |
|
| 796 |
// Create a new ConnectionNode |
| 797 |
ConnectionNode newConnectionNode = new ConnectionNode(); |
| 798 |
// Add the connection number and the new child |
| 799 |
newConnectionNode.connectionNumber = connectionNumber; |
| 800 |
newConnectionNode.childrenNodes = new LinkedList(); |
| 801 |
newConnectionNode.childrenNodes.add(newNode); |
| 802 |
// Add this connectionNode to the ConnectionsList |
| 803 |
connectionsList.add(newConnectionNode); |
| 804 |
|
| 805 |
|
| 806 |
return retcode; |
| 807 |
} |
| 808 |
/** |
| 809 |
* This method adds newNode as a child of the Connection node found |
| 810 |
* at connectionIndex |
| 811 |
* |
| 812 |
* @param connectionIndex |
| 813 |
* @param newNode |
| 814 |
* @return |
| 815 |
*/ |
| 816 |
public boolean addConnectionChild(int connectionIndex, TRCNode newNode){ |
| 817 |
boolean retcode = true; |
| 818 |
|
| 819 |
ConnectionNode thisConnection = (ConnectionNode)connectionsList.get(connectionIndex); |
| 820 |
thisConnection.childrenNodes.add(newNode); |
| 821 |
return retcode; |
| 822 |
} |
| 823 |
|
| 824 |
/** |
| 825 |
* This method goes through each Connection node, and adds each child |
| 826 |
* found for that Connection node to the reordered list of TRCNode nodes |
| 827 |
* |
| 828 |
* This newPageList will be processed to create the testsuite. |
| 829 |
* @return |
| 830 |
* modified for bugzilla #90867 & #83976 - george.sebastian@ca.com |
| 831 |
* @throws TestgenException |
| 832 |
* |
| 833 |
*/ |
| 834 |
private void createNewPageList() throws TestgenException { |
| 835 |
|
| 836 |
if (isNewType()){ |
| 837 |
createPageListNew(); |
| 838 |
return; |
| 839 |
} |
| 840 |
createPageListOld(); |
| 841 |
} |
| 842 |
|
| 843 |
//added for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 844 |
private void createPageListOld() throws TestgenException { |
| 845 |
int totalConnections = -1; |
| 846 |
int i = 0; |
| 847 |
int j = 0; |
| 848 |
ConnectionNode thisConnection = null; |
| 849 |
TRCNode thisNode = null; |
| 850 |
TRCNode nextNode = null; |
| 851 |
int totalChildren = -1; |
| 852 |
totalConnections = connectionsList.size(); |
| 853 |
for (i = 0; i < totalConnections; i++){ |
| 854 |
thisConnection = (ConnectionNode)connectionsList.get(i); |
| 855 |
totalChildren = thisConnection.childrenNodes.size(); |
| 856 |
childrenLoop: |
| 857 |
for (j = 0; j < totalChildren; j++){ |
| 858 |
thisNode = (TRCNode)thisConnection.childrenNodes.get(j); |
| 859 |
for(int counter = 1; ; counter++) |
| 860 |
{ |
| 861 |
if((counter+j) >= totalChildren){ |
| 862 |
break; |
| 863 |
} |
| 864 |
if(checkIsPOSTRequest(thisNode)){ |
| 865 |
|
| 866 |
nextNode = (TRCNode)thisConnection.childrenNodes.get(j+counter); |
| 867 |
String from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM,nextNode); |
| 868 |
if(!from.equalsIgnoreCase(PACKET_A_FROM_V_SERVER)){ |
| 869 |
thisNode.getElement().setContent(nextNode.getElement().getContent()); |
| 870 |
((TRCNode)thisNode.getSubNodes().getFirst()).getElement().setContent( |
| 871 |
((TRCNode)nextNode.getSubNodes().getFirst()).getElement().getContent()); |
| 872 |
j++; |
| 873 |
} |
| 874 |
else{ |
| 875 |
boolean isContinue = checkForContinue(nextNode); |
| 876 |
if(true == isContinue) |
| 877 |
{ |
| 878 |
((TRCNode)thisNode.getSubNodes().getFirst()).getElement().setContent( |
| 879 |
((TRCNode)nextNode.getSubNodes().getFirst()).getElement().getContent()); |
| 880 |
continue; |
| 881 |
} |
| 882 |
else |
| 883 |
{ |
| 884 |
newPageList.add(thisNode); |
| 885 |
j = j + counter - 1; |
| 886 |
continue childrenLoop; |
| 887 |
} |
| 888 |
} |
| 889 |
} |
| 890 |
} |
| 891 |
newPageList.add(thisNode); |
| 892 |
continue childrenLoop; |
| 893 |
} |
| 894 |
} |
| 895 |
|
| 896 |
} |
| 897 |
// added for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 898 |
private void createPageListNew() throws TestgenException { |
| 899 |
int totalConnections = -1; |
| 900 |
int i = 0; |
| 901 |
int j = 0; |
| 902 |
int counter = 0; |
| 903 |
ConnectionNode thisConnection = null; |
| 904 |
TRCNode thisNode = null; |
| 905 |
int totalChildren = -1; |
| 906 |
|
| 907 |
totalConnections = connectionsList.size(); |
| 908 |
connectionLoop: |
| 909 |
for (i = 0; i < totalConnections; i++){ |
| 910 |
|
| 911 |
thisConnection = (ConnectionNode)connectionsList.get(i); |
| 912 |
totalChildren = thisConnection.childrenNodes.size(); |
| 913 |
|
| 914 |
childrenLoop: |
| 915 |
for (j = 0; j < totalChildren; j++){ |
| 916 |
|
| 917 |
thisNode = (TRCNode)thisConnection.childrenNodes.get(j); |
| 918 |
String from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, thisNode); |
| 919 |
|
| 920 |
if(from.equals(PACKET_A_FROM_V_CLIENT)) |
| 921 |
{ |
| 922 |
for(counter = 1; ; counter++) |
| 923 |
{ |
| 924 |
if((j + counter) >= totalChildren) |
| 925 |
{ |
| 926 |
newPageList.add(thisNode); |
| 927 |
continue connectionLoop; |
| 928 |
} |
| 929 |
|
| 930 |
TRCNode nextNode = (TRCNode)thisConnection.childrenNodes.get(j + counter); |
| 931 |
from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, nextNode); |
| 932 |
|
| 933 |
if(from.equals(PACKET_A_FROM_V_SERVER)) |
| 934 |
{ |
| 935 |
if(checkIsPOSTRequest(thisNode)) |
| 936 |
{ |
| 937 |
boolean isContinue = checkForContinue(nextNode); |
| 938 |
if(true == isContinue) |
| 939 |
{ |
| 940 |
((TRCNode)thisNode.getSubNodes().getFirst()).getElement().setContent( |
| 941 |
((TRCNode)nextNode.getSubNodes().getFirst()).getElement().getContent()); |
| 942 |
continue; |
| 943 |
} |
| 944 |
else |
| 945 |
{ |
| 946 |
newPageList.add(thisNode); |
| 947 |
j = j + counter - 1; |
| 948 |
continue childrenLoop; |
| 949 |
} |
| 950 |
} |
| 951 |
newPageList.add(thisNode); |
| 952 |
j = j + counter - 1; |
| 953 |
continue childrenLoop; |
| 954 |
}else{ |
| 955 |
//thisNode.getElement().setContent(nextNode.getElement().getContent()); |
| 956 |
((TRCNode)thisNode.getSubNodes().getFirst()).getElement().setContent( |
| 957 |
((TRCNode)nextNode.getSubNodes().getFirst()).getElement().getContent()); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
} |
| 962 |
if (from.equals(PACKET_A_FROM_V_SERVER)) { |
| 963 |
|
| 964 |
for(counter = 1; ; counter++) |
| 965 |
{ |
| 966 |
if((j + counter) >= totalChildren) |
| 967 |
{ |
| 968 |
newPageList.add(thisNode); |
| 969 |
continue connectionLoop; |
| 970 |
} |
| 971 |
|
| 972 |
TRCNode nextNode = (TRCNode)thisConnection.childrenNodes.get(j + counter); |
| 973 |
from = TRCNodeHandler.getAttributeValue(PACKET_A_FROM, nextNode); |
| 974 |
if(from.equals(PACKET_A_FROM_V_CLIENT)) |
| 975 |
{ |
| 976 |
newPageList.add(thisNode); |
| 977 |
j = j + counter - 1; |
| 978 |
continue childrenLoop; |
| 979 |
} |
| 980 |
thisNode.getElement().setContent(nextNode.getElement().getContent()); |
| 981 |
} |
| 982 |
|
| 983 |
} |
| 984 |
newPageList.add(thisNode); |
| 985 |
} |
| 986 |
} |
| 987 |
|
| 988 |
} |
| 989 |
|
| 990 |
/** Check request for POST method |
| 991 |
* |
| 992 |
* @param dataNode |
| 993 |
* @return |
| 994 |
* added for bugzilla #90867 & #83976 - tejas.patel.ca.com,george.sebastian@ca.com |
| 995 |
* @throws TestgenException |
| 996 |
*/ |
| 997 |
boolean checkIsPOSTRequest(TRCNode dataNode) throws TestgenException { |
| 998 |
boolean isPOSTRequest = false; |
| 999 |
String tempContent = null; |
| 1000 |
byte[] decContent = null; |
| 1001 |
String content = ((TRCNode)dataNode.getSubNodes().getFirst()).getElement().getContent(); |
| 1002 |
if (content == null) |
| 1003 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 1004 |
|
| 1005 |
String encoding = getAttributeValue(PACKET_S_DATA_A_ENCODING, dataNode); |
| 1006 |
if (encoding == null) |
| 1007 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_ENCODING_ATT, null); |
| 1008 |
// TODO: dhinson: needs to handle non-NONE encodings eventually |
| 1009 |
// TODO: dhinson: change to equals() when DuWayne fixes value |
| 1010 |
if (encoding.equalsIgnoreCase(PACKET_S_DATA_A_ENCODING_V_NONE)) |
| 1011 |
; // do nothing (no translation required) |
| 1012 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_ASCIIFY)) { |
| 1013 |
TRCAsciifier myasc = new TRCAsciifier(); |
| 1014 |
decContent = new byte[content.length()]; |
| 1015 |
myasc.decode(content, 0, content.length(), decContent); |
| 1016 |
tempContent = new String(decContent); |
| 1017 |
String tmp = tempContent.trim(); |
| 1018 |
content = tmp; |
| 1019 |
|
| 1020 |
} |
| 1021 |
else if (encoding.equals(PACKET_S_DATA_A_ENCODING_V_BASE64)) |
| 1022 |
return false; |
| 1023 |
else |
| 1024 |
return false; |
| 1025 |
|
| 1026 |
StringTokenizer bodyTokenizer = new StringTokenizer(content, CRNL); |
| 1027 |
for (int headerCount = 0; bodyTokenizer.hasMoreTokens(); |
| 1028 |
++headerCount) { |
| 1029 |
String header = bodyTokenizer.nextToken(); |
| 1030 |
if (headerCount == 0) { |
| 1031 |
StringTokenizer headerTokenizer = new StringTokenizer(header); |
| 1032 |
if(HTTP_POST.equalsIgnoreCase(headerTokenizer.nextToken().trim())){ |
| 1033 |
return true; |
| 1034 |
|
| 1035 |
} |
| 1036 |
|
| 1037 |
} |
| 1038 |
} |
| 1039 |
return isPOSTRequest; |
| 1040 |
} |
| 1041 |
|
| 1042 |
/** Check response for status code of 100 which indicates continue |
| 1043 |
* |
| 1044 |
* @param node |
| 1045 |
* added for bugzilla #90867 & #83976 - tejas.patel.ca.com |
| 1046 |
* @return |
| 1047 |
* @throws TestgenException |
| 1048 |
*/ |
| 1049 |
boolean checkForContinue(TRCNode node) throws TestgenException { |
| 1050 |
|
| 1051 |
boolean isContinue = false; |
| 1052 |
String content = ((TRCNode)node.getSubNodes().getFirst()).getElement().getContent(); |
| 1053 |
//String content = node.getElement().getContent(); |
| 1054 |
if (content == null) { |
| 1055 |
throw new TestgenException(CorePluginResourceBundle.E_DATA_NO_CONTENT, null); |
| 1056 |
} |
| 1057 |
StringTokenizer bodyTokenizer = new StringTokenizer(content, CRNL); |
| 1058 |
String statusLine = bodyTokenizer.nextToken(); |
| 1059 |
// at this point have HTTP/1.1 100 Continue |
| 1060 |
StringTokenizer status = new StringTokenizer(statusLine, BLANK); |
| 1061 |
status.nextToken(); // This is HTTP/1.1 |
| 1062 |
String actualStatus = status.nextToken();// This is 200 or 100 or 301, etc... |
| 1063 |
Integer intStat = new Integer(actualStatus); |
| 1064 |
int actualVal = intStat.intValue(); |
| 1065 |
if (actualVal == 100){ |
| 1066 |
isContinue = true; |
| 1067 |
} |
| 1068 |
return isContinue; |
| 1069 |
} |
| 1070 |
/** |
| 1071 |
* This method goes through the newly reordered TRCNode node list, |
| 1072 |
* and creates Behavior Model entries for each. One of the elements of |
| 1073 |
* the behavior model is page enumeration (begin, middle, end or only). |
| 1074 |
* Since you don't know the enumeration of a particular request/response |
| 1075 |
* pair until you have looked at the subsequent pair, we must store the |
| 1076 |
* request and compare the current request to the previous response to |
| 1077 |
* determine enumeration. |
| 1078 |
* |
| 1079 |
* Determine if node is a HttpRequest or HttpResponse |
| 1080 |
* If HttpRequest |
| 1081 |
* parse request and populate currentHttpRequest |
| 1082 |
* If HttpResponse |
| 1083 |
* parse request and determine if it is a New Page |
| 1084 |
* |
| 1085 |
* If have both the request and response |
| 1086 |
* Determine the Page Enumeration for Previous Response |
| 1087 |
* Write Previous Response |
| 1088 |
* |
| 1089 |
* @throws TestgenException |
| 1090 |
*/ |
| 1091 |
public void writeNewPageList() throws TestgenException { |
| 1092 |
int totalNodes = -1; |
| 1093 |
int i = 0; |
| 1094 |
boolean isARequest = false; |
| 1095 |
TRCNode currentNode = null; |
| 1096 |
boolean haveRequest = false; |
| 1097 |
boolean haveResponse = false; |
| 1098 |
ResponseInfo responseInfo = null; |
| 1099 |
|
| 1100 |
// Process the entire node list |
| 1101 |
totalNodes = newPageList.size(); |
| 1102 |
for (i = 0; i < totalNodes; i++) { |
| 1103 |
currentNode = (TRCNode)newPageList.get(i); |
| 1104 |
isARequest = checkIsRequest(currentNode); |
| 1105 |
if (isARequest) { |
| 1106 |
haveRequest = true; |
| 1107 |
parseHttpRequest(currentNode); |
| 1108 |
} |
| 1109 |
else { |
| 1110 |
haveResponse = true; |
| 1111 |
responseInfo = parseHttpResponse(currentNode); |
| 1112 |
currentHttpRequest.timeStampString = responseInfo.timeStampString; |
| 1113 |
currentHttpRequest.newPage = responseInfo.newPage; |
| 1114 |
} |
| 1115 |
|
| 1116 |
if (haveRequest && haveResponse) { |
| 1117 |
haveRequest = false; |
| 1118 |
haveResponse = false; |
| 1119 |
if (totalNodes == 2) { |
| 1120 |
currentHttpRequest.newPage = true; |
| 1121 |
currentHttpRequest.enumPage = HttpRequest.PAGE_ONLY; |
| 1122 |
createPage(currentHttpRequest); |
| 1123 |
break; |
| 1124 |
} |
| 1125 |
if ((previousHttpRequest == null) || (i == 1)) { |
| 1126 |
// This is the First Page |
| 1127 |
currentHttpRequest.newPage = true; |
| 1128 |
currentHttpRequest.enumPage = HttpRequest.PAGE_START; |
| 1129 |
previousHttpRequest = currentHttpRequest; |
| 1130 |
} |
| 1131 |
else { |
| 1132 |
if (previousHttpRequest.newPage) { |
| 1133 |
// Previous Request IS a new page |
| 1134 |
if (currentHttpRequest.newPage) { |
| 1135 |
previousHttpRequest.enumPage = HttpRequest.PAGE_ONLY; |
| 1136 |
} |
| 1137 |
else { |
| 1138 |
// Current Request NOT a new page |
| 1139 |
previousHttpRequest.enumPage = HttpRequest.PAGE_START; |
| 1140 |
} |
| 1141 |
} |
| 1142 |
else { |
| 1143 |
// Previous Message NOT a new page |
| 1144 |
if (currentHttpRequest.newPage) { |
| 1145 |
previousHttpRequest.enumPage = HttpRequest.PAGE_END; |
| 1146 |
} |
| 1147 |
else { |
| 1148 |
previousHttpRequest.enumPage = HttpRequest.PAGE_MID; |
| 1149 |
} |
| 1150 |
} |
| 1151 |
createPage(previousHttpRequest); |
| 1152 |
previousHttpRequest = currentHttpRequest; |
| 1153 |
previousHttpRequest.enumPage = HttpRequest.PAGE_END; |
| 1154 |
if (i == (totalNodes - 1)) { |
| 1155 |
if (previousHttpRequest.newPage) |
| 1156 |
previousHttpRequest.enumPage = HttpRequest.PAGE_ONLY; |
| 1157 |
createPage(previousHttpRequest); |
| 1158 |
} |
| 1159 |
|
| 1160 |
} |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
/** |
| 1166 |
* |
| 1167 |
* @param attribute |
| 1168 |
* added for bugzilla #90867 & #83976 - george.sebastian@ca.com |
| 1169 |
* @param node |
| 1170 |
* @return |
| 1171 |
*/ |
| 1172 |
|
| 1173 |
private String getAttributeValue(String attribute, TRCNode node) { |
| 1174 |
|
| 1175 |
String value = TRCNodeHandler.getAttributeValue(attribute,node); |
| 1176 |
if (value == null ){ |
| 1177 |
|
| 1178 |
for (int i = 0 ; i <node.getSubNodes().size() ; i++) { |
| 1179 |
value = getAttributeValue(attribute, (TRCNode) node.getSubNodes().get(i)); |
| 1180 |
if (value != null) |
| 1181 |
return value; |
| 1182 |
} |
| 1183 |
} |
| 1184 |
return value; |
| 1185 |
} |
| 1186 |
// added for bugzilla #90867 & #83976 - george.sebastian@ca.com |
| 1187 |
public boolean isNewType() { |
| 1188 |
return isNewType; |
| 1189 |
} |
| 1190 |
// added for bugzilla #90867 & #83976 - tejas.patel.ca.com |
| 1191 |
private int getContentLocation(String str) |
| 1192 |
{ |
| 1193 |
int iRet = -1; |
| 1194 |
|
| 1195 |
iRet = str.indexOf(CRNL + CRNL); |
| 1196 |
|
| 1197 |
if(-1 != iRet) |
| 1198 |
iRet += 4; |
| 1199 |
|
| 1200 |
return iRet; |
| 1201 |
|
| 1202 |
} |
| 1203 |
} |