public void makeCalls() {
      // Make the calls
      int loopCounter = 0;
      for (HttpCallBean callBean : httpCallBeans) {
        Date time = new Date();
        expectedRequestTimes.put(
            identifier + RESPONSE + loopCounter, new Timestamp(time.getTime()));
        cougarManager.makeRestCougarHTTPCall(callBean, requestProtocolTypeEnum);
        loopCounter++;
      }

      // Get actual responses
      loopCounter = 0;
      for (HttpCallBean httpCallBean : httpCallBeans) {
        HttpResponseBean responseBean =
            httpCallBean.getResponseObjectsByEnum(CougarMessageProtocolResponseTypeEnum.REST);
        responseBean.setResponseHeaders(null);
        actualResponses.put(identifier + RESPONSE + loopCounter, responseBean);
        loopCounter++;
      }

      // Set the expected response time
      for (String keyString : expectedResponses.keySet()) {
        HttpResponseBean responseBean = expectedResponses.get(keyString);
        Timestamp requestTime = expectedRequestTimes.get(keyString);
        responseBean.setRequestTime(requestTime);
        responseBean.setResponseTime(requestTime);
      }
    }
Exemple #2
0
  private HttpResponseBean buildHttpResponseBean(
      HttpResponse httpResponse, String response, Date requestTime, Date responseTime) {

    HttpResponseBean httpResponseBean = new HttpResponseBean();

    Header[] headersArray = httpResponse.getAllHeaders();
    Map<String, String> headersMap = new HashMap<String, String>();
    for (Header header : headersArray) {
      String[] headerAttributes = header.toString().split(": ");
      headersMap.put(headerAttributes[0], headerAttributes[1].replace("\r\n", ""));
    }
    httpResponseBean.setResponseHeaders(headersMap);

    httpResponseBean.setHttpStatusCode(httpResponse.getStatusLine().getStatusCode());
    httpResponseBean.setHttpStatusText(httpResponse.getStatusLine().getReasonPhrase());

    httpResponseBean.setRequestTime(new Timestamp(requestTime.getTime()));
    httpResponseBean.setResponseTime(new Timestamp(responseTime.getTime()));

    if ((response != null) && (!response.equalsIgnoreCase(""))) {
      httpResponseBean.setResponseObject(response);
    } else {
      httpResponseBean.setResponseObject(null);
    }

    return httpResponseBean;
  }