コード例 #1
0
  public ConsoleManager() {

    try {
      this.jndiDataSourceName = EmailConnectorConfig.getConfigInstance().getDataSource();

      boolean checkCertificates = EmailConnectorConfig.getConfigInstance().getCheckCertificates();
      if (checkCertificates) {
        this.sslSocketFactory = Def.SSL_SOCKET_FACTORY_STANDARD;
      } else {
        this.sslSocketFactory = Def.SSL_SOCKET_FACTORY_FUNAMBOL;
      }

      idMailServerSpace =
          DBIDGeneratorFactory.getDBIDGenerator(
              Def.ID_COUNTER_MAILSERVER, DataSourceTools.lookupDataSource(CORE_DB_JNDI_NAME));

      cdao = new ConsoleDAO();

    } catch (EmailConfigException e) {
      log.error("Error Getting Connector Parameters ", e);
    } catch (NamingException e) {
      log.error("Error Getting ID Generator ", e);
    } catch (InboxListenerConfigException e) {
      log.error("Error creating DAO layer ", e);
    } catch (Exception e) {
      log.error("Error Getting ID Generator ", e);
    }
  }
コード例 #2
0
  /**
   * Transforms the alerts into the byte array that is send to the client
   *
   * @return byte representation of the alerts
   * @throws NotificationException
   */
  public byte[] getBytes() throws NotificationException {
    if (this.alerts == null) {
      throw new NotificationException("No alerts to build the message body");
    }

    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    BitOutputStream bout = new BitOutputStream(byteOut);
    try {
      // get the number of syncs in the body
      int syncNr = 0;
      for (int i = 0; i < this.alerts.length; i++) {
        ArrayList items = this.alerts[i].getItems();
        for (int j = 0; j < items.size(); j++) {
          syncNr++;
        }
      }
      if (log.isTraceEnabled()) {
        log.trace("Number of sync items:" + syncNr);
      }
      int[] intRepresentation = getIntBinaryRepresentation(syncNr, NUM_BIT_NUMBER_SYNCS);
      for (int i = 0; i < NUM_BIT_NUMBER_SYNCS; i++) {
        bout.writeBit(intRepresentation[i]);
      }

      // put 0000 in the body - future use
      for (int i = 0; i < NUM_BIT_FUTURE_USE; i++) {
        bout.writeBit(0);
      }

      // for each sync info from each alert
      for (int i = 0; i < this.alerts.length; i++) {
        Alert alert = this.alerts[i];
        ArrayList items = this.alerts[i].getItems();
        for (int j = 0; j < items.size(); j++) {
          Item item = (Item) items.get(j);
          // put in the body syncType -200
          if ((alert.getData() < 206) || (alert.getData() > 210)) {
            throw new NotificationException("Invalid alert data type " + alert.getData());
          }
          intRepresentation = null;
          intRepresentation = getIntBinaryRepresentation(alert.getData() - 200, NUM_BIT_ALERT_DATA);
          for (int k = 0; k < NUM_BIT_ALERT_DATA; k++) {
            bout.writeBit(intRepresentation[k]);
          }
          // put 0000 -future use
          for (int k = 0; k < NUM_BIT_FUTURE_USE; k++) {
            bout.writeBit(0);
          }
          // content type - map between string and value !!!!!
          int contentTypeCode = 0;
          if ((item.getMeta() != null) && (item.getMeta().getType() != null)) {
            String type = item.getMeta().getType();
            Integer tmp = contentTypeCodes.get(type);
            if (tmp != null) {
              contentTypeCode = tmp;
            }
          }
          intRepresentation = null;
          intRepresentation = getIntBinaryRepresentation(contentTypeCode, NUM_BIT_CONTENT_TYPE);
          for (int k = 0; k < NUM_BIT_CONTENT_TYPE; k++) {
            bout.writeBit(intRepresentation[k]);
          }

          //
          // SyncSource: length + uri
          //
          String syncSourceURI = null;

          if (item.getSource() != null) {
            //
            // Trying to use item' source
            //
            syncSourceURI = item.getSource().getLocURI();
          } else if (item.getTarget() != null) {
            //
            // Trying to use item' target
            //
            syncSourceURI = item.getTarget().getLocURI();
          } else {
            throw new NotificationException(
                "The Alert command n. " + i + " doesn't contain an item with source or target uri");
          }

          if (log.isTraceEnabled()) {
            log.trace("SourceURI: " + syncSourceURI);
          }

          // syncsource uri length
          intRepresentation = null;
          intRepresentation =
              getIntBinaryRepresentation(syncSourceURI.length(), NUM_BIT_URI_LENGTH);
          for (int k = 0; k < NUM_BIT_URI_LENGTH; k++) {
            bout.writeBit(intRepresentation[k]);
          }

          // syncsource uri
          byte[] uri = syncSourceURI.getBytes();
          for (int k = 0; k < uri.length; k++) {
            // transform each byte of the server uri string into an 8 bit number
            intRepresentation = getIntBinaryRepresentation(uri[k], 8);
            // write the bit representation of each byte of the uri in the bit output stream
            for (int jj = 0; jj < 8; jj++) {
              bout.writeBit(intRepresentation[jj]);
            }
          }
        }
      }
      bout.close();
    } catch (IOException e) {
      throw new NotificationException("Error during body computing", e);
    }

    return byteOut.toByteArray();
  }