Beispiel #1
0
  /**
   * Add piggyback data to header.
   *
   * @param header
   */
  protected final void processPiggybackData(Header header) {

    synchronized (piggyBackData) {
      // Clear previous piggyback data.
      header.clearPiggybackData();
      for (Iterator<Map<String, String>> iter = piggyBackData.iterator(); iter.hasNext(); ) {
        Map<String, String> element = iter.next();
        header.addPiggyBackData(element);
      }
      // remove piggyback data.
      piggyBackData.clear();
    }
  }
Beispiel #2
0
  @Override
  public final Navajo doSimpleSend(Navajo out, String method, Integer retries)
      throws ClientException {

    if (bearerToken == null) {
      if (username == null) {
        throw new ClientException(1, 1, "No username set!");
      }
      if (password == null) {
        throw new ClientException(1, 1, "No password set!");
      }
    }
    if (getCurrentHost() == null) {
      throw new ClientException(1, 1, "No host set!");
    }

    // NOTE: prefix persistence key with method, because same Navajo object
    // could be used as a request
    // for multiple methods!

    // ============ compared services ===================

    /** Make sure that same Navajo is not used simultaneously. */
    synchronized (out) {
      // ====================================================

      Header header = out.getHeader();
      String callingService = null;
      if (header == null) {
        header = NavajoFactory.getInstance().createHeader(out, method, username, password, -1);
        out.addHeader(header);
      } else {
        callingService = header.getRPCName();
        header.setRPCName(method);
        header.setRPCUser(username);
        header.setRPCPassword(password);
      }
      // ALWAY SET REQUEST ID AT THIS POINT.
      if (header.getRequestId() != null && header.getRequestId().equals("42")) {
        System.err.println("ENCOUNTERED TEST!!!");
      } else {
        header.setRequestId(Guid.create());
      }
      String sessionToken = getSessionTokenProvider().getSessionToken();
      header.setHeaderAttribute("clientToken", sessionToken);
      header.setHeaderAttribute("clientInfo", getSystemInfoProvider().toString());

      for (String key : navajoHeaders.keySet()) {
        header.setHeaderAttribute(key, navajoHeaders.get(key));
      }
      // ========= Adding globalMessages

      long clientTime = 0;
      try {
        if (out.getHeader() != null) {
          processPiggybackData(out.getHeader());
        }

        Navajo n = null;

        long timeStamp = System.currentTimeMillis();

        n = doTransaction(out, allowCompression, retries, 0);

        if (n.getHeader() != null) {
          n.getHeader().setHeaderAttribute("sourceScript", callingService);
          clientTime = (System.currentTimeMillis() - timeStamp);
          n.getHeader().setHeaderAttribute("clientTime", "" + clientTime);
          String tot = n.getHeader().getHeaderAttribute("serverTime");
          long totalTime = -1;
          if (tot != null && !"".equals(tot)) {
            totalTime = Long.parseLong(tot);
            n.getHeader().setHeaderAttribute("transferTime", "" + (clientTime - totalTime));
          }
          Map<String, String> headerAttributes = n.getHeader().getHeaderAttributes();
          Map<String, String> pbd = new HashMap<String, String>(headerAttributes);
          pbd.put("type", "performanceStats");
          pbd.put("service", method);
          synchronized (piggyBackData) {
            piggyBackData.add(pbd);
          }
        } else {
          logger.info("Null header in input message?");
        }

        return n;
      } catch (ClientException e) {
        throw e;
      } catch (Exception e) {
        logger.error("Error: ", e);
        throw new ClientException(-1, -1, e.getMessage(), e);
      }
    }
  }