@Override
  public MessageInfo createRequestMessageInfo() {
    if (requestSoap == null) {
      return null;
    }

    return new MessageInfo(
        Origin.CLIENT_PROXY,
        requestSoap.getClient(),
        requestServiceId,
        requestSoap.getUserId(),
        requestSoap.getQueryId());
  }
  protected void verifyClientStatus() throws Exception {
    ClientId client = requestSoap.getClient();

    String status = ServerConf.getMemberStatus(client);
    if (!ClientType.STATUS_REGISTERED.equals(status)) {
      throw new CodedException(X_UNKNOWN_MEMBER, "Client '%s' not found", client);
    }
  }
  protected void verifyClientAuthentication() throws Exception {
    if (!SystemProperties.shouldVerifyClientCert()) {
      return;
    }

    log.trace("verifyClientAuthentication()");

    ClientId sender = requestSoap.getClient();
    IsAuthentication.verifyClientAuthentication(sender, clientCert);
  }
  private void checkRequestHash() throws Exception {
    RequestHash requestHashFromResponse = response.getSoap().getHeader().getRequestHash();
    if (requestHashFromResponse != null) {
      byte[] requestHash =
          calculateDigest(
              getAlgorithmId(requestHashFromResponse.getAlgorithmId()), requestSoap.getBytes());

      if (log.isTraceEnabled()) {
        log.trace(
            "Calculated request message hash: {}\n" + "Request message (base64): {}",
            encodeBase64(requestHash),
            encodeBase64(requestSoap.getBytes()));
      }

      if (!Arrays.areEqual(requestHash, decodeBase64(requestHashFromResponse.getHash()))) {
        throw new CodedException(
            X_INCONSISTENT_RESPONSE, "Request message hash does not match request message");
      }
    } else {
      throw new CodedException(
          X_INCONSISTENT_RESPONSE,
          "Response from server proxy is missing request message " + "hash");
    }
  }
  private void sendRequest(HttpSender httpSender) throws Exception {
    log.trace("sendRequest()");
    try {
      // If we're using SSL, we need to include the provider name in
      // the HTTP request so that server proxy could verify the SSL
      // certificate properly.
      if (SystemProperties.isSslEnabled()) {
        httpSender.setAttribute(AuthTrustVerifier.ID_PROVIDERNAME, requestServiceId);
      }

      // Start sending the request to server proxies. The underlying
      // SSLConnectionSocketFactory will select the fastest address
      // (socket that connects first) from the provided addresses.
      // Dummy service address is only needed so that host name resolving
      // could do its thing and start the ssl connection.
      URI[] addresses = getServiceAddresses(requestServiceId, requestSoap.getSecurityServer());
      httpSender.setAttribute(ID_TARGETS, addresses);
      httpSender.setTimeout(SystemProperties.getClientProxyTimeout());

      httpSender.addHeader(HEADER_HASH_ALGO_ID, getHashAlgoId());
      httpSender.addHeader(HEADER_PROXY_VERSION, ProxyMain.getVersion());

      try {
        httpSender.doPost(
            getDummyServiceAddress(addresses), reqIns, CHUNKED_LENGTH, outputContentType);
      } catch (Exception e) {
        // Failed to connect to server proxy
        MonitorAgent.serverProxyFailed(createRequestMessageInfo());
        // Rethrow
        throw e;
      }
    } finally {
      if (reqIns != null) {
        reqIns.close();
      }
    }
  }