Package com.mockey.model

Examples of com.mockey.model.ResponseFromService


    // ************************************************************************
    // STEP #4) Get the Response (static,dynamic, or proxy).
    // ************************************************************************
    service.setHttpMethod(originalHttpReqFromClient.getMethod());
    ResponseFromService response = service.execute(request, serviceUrl);

    // ************************************************************************
    // STEP #5) If twisting was enabled, let's be sure to set the original URL
    // ************************************************************************
    if (!originalHttpReqURI.equalsIgnoreCase(targetHttpReqURI)) {
      response.setOriginalRequestUrlBeforeTwisting(new Url(originalHttpReqURI));
    }
    logRequestAsFulfilled(service, request, response, originalHttpReqFromClient.getRemoteAddr(), inspectionMessage);

    try {
      // Wait for a X hang time seconds.
      logger.debug("Waiting..." + service.getHangTime() + " miliseconds ");
      Thread.currentThread().sleep(service.getHangTime());
      logger.debug("Done Waiting");
    } catch (Exception e) {
      // Catch interrupt exception.
      // Or not.
    }

    if (!(service.getServiceResponseType() == Service.SERVICE_RESPONSE_TYPE_PROXY)) {
      if (response.getHeaders() != null) {
        for (Header h : response.getHeaders()) {
          resp.setHeader(h.getName(), h.getValue());
        }
      }

      try {
        resp.setStatus(response.getHttpResponseStatusCode());
      } catch (java.lang.IllegalArgumentException iae) {
        logger.debug("Unable to set the response status to '" + response.getHttpResponseStatusCode() + "'", iae);
      }
      byte[] myCharSetBytes = response.getBody().getBytes();
      new PrintStream(resp.getOutputStream()).write(myCharSetBytes);
      resp.getOutputStream().flush();
    } else {
      // RULE_FOR_HEADERS
      try {
        resp.setStatus(response.getHttpResponseStatusCode());
      } catch (java.lang.IllegalArgumentException iae) {
        logger.debug("Unable to set the response status to '" + response.getHttpResponseStatusCode() + "'", iae);
      }
      response.writeToOutput(resp);
    }
  }
View Full Code Here


      httpclient.getCredentialsProvider()
          .setCredentials(proxyServer.getAuthScope(), proxyServer.getCredentials());
      httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyServer.getHttpHost());
    }

    ResponseFromService responseMessage = null;
    try {
      HttpHost htttphost = new HttpHost(realServiceUrl.getHost(), realServiceUrl.getPort(),
          realServiceUrl.getScheme());

      HttpResponse response = httpclient.execute(htttphost, request.postToRealServer(realServiceUrl));
      if (response.getStatusLine().getStatusCode() == 302) {
        log.debug("FYI: 302 redirect occuring from " + realServiceUrl.getFullUrl());
      }
      responseMessage = new ResponseFromService(response);
      responseMessage.setRequestUrl(realServiceUrl);
    } catch (Exception e) {
      log.error(e);
      throw new ClientExecuteProxyException("Unable to retrieve a response. ", realServiceUrl, e);
    } finally {
      // When HttpClient instance is no longer needed,
View Full Code Here

TOP

Related Classes of com.mockey.model.ResponseFromService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.