Example #1
0
  /** @see de.willuhn.jameica.hbci.passports.rdh.keyformat.KeyFormat#importKey(java.io.File) */
  public RDHKey importKey(File file) throws ApplicationException, OperationCanceledException {
    // Checken, ob die Datei lesbar ist.
    if (file == null)
      throw new ApplicationException(i18n.tr("Bitte wählen Sie eine Schlüsseldatei aus"));

    if (!file.canRead() || !file.isFile())
      throw new ApplicationException(i18n.tr("Schlüsseldatei nicht lesbar"));

    // Das ist ein Hibiscus-Schluessel. Wir lassen den Schluessel gleich dort, wo er ist
    try {
      RDHKeyImpl key = new RDHKeyImpl(file);
      key.setFormat(this);
      return key;
    } catch (RemoteException re) {
      Logger.error("unable to import key " + file.getAbsolutePath(), re);
      throw new ApplicationException(
          i18n.tr("Schlüsseldatei kann nicht importiert werden: {0}", re.getMessage()));
    }
  }
Example #2
0
  /** @see de.willuhn.jameica.hbci.passports.rdh.keyformat.KeyFormat#createKey(java.io.File) */
  public RDHKey createKey(File file) throws ApplicationException, OperationCanceledException {
    HBCIHandler handler = null;
    RDHKeyImpl key = null;

    try {
      key = new RDHKeyImpl(file);
      key.setFormat(this);

      // Wir machen den Handler einmal auf und wieder zu, damit
      // der Schluessel gleich initialisiert wird.
      HBCIPassport passport = load(key, true);
      passport.saveChanges();
      passport.syncSigId();
      passport.syncSysId();

      // Bei der Neuerstellung fragen wir immer den User nach der HBCI-Version
      // Wir fragen die HBCI-Version via Messaging ab, damit sie ggf. auch
      // (z.Bsp. vom Payment-Server) automatisch beantwortet werden kann.
      QueryMessage msg = new QueryMessage(passport);
      Application.getMessagingFactory()
          .getMessagingQueue("hibiscus.passport.rdh.hbciversion")
          .sendSyncMessage(msg);
      Object data = msg.getData();
      if (data == null || !(data instanceof String))
        throw new ApplicationException(i18n.tr("HBCI-Version nicht ermittelbar"));

      String version = (String) msg.getData();
      Logger.info("using hbci version: " + version);

      handler = new HBCIHandler(version, passport);
      handler.close();
      handler = null;
      Application.getMessagingFactory()
          .sendMessage(
              new StatusBarMessage(
                  i18n.tr("Schlüssel erfolgreich erstellt"), StatusBarMessage.TYPE_SUCCESS));
      return key;
    } catch (ApplicationException ae) {
      throw ae;
    } catch (OperationCanceledException oce) {
      throw oce;
    } catch (Exception e) {
      OperationCanceledException oce =
          (OperationCanceledException) HBCIFactory.getCause(e, OperationCanceledException.class);
      if (oce != null) throw oce;

      ApplicationException ae =
          (ApplicationException) HBCIFactory.getCause(e, ApplicationException.class);
      if (ae != null) throw ae;

      NeedKeyAckException ack =
          (NeedKeyAckException) HBCIFactory.getCause(e, NeedKeyAckException.class);
      if (ack != null) {
        Application.getMessagingFactory()
            .sendMessage(
                new StatusBarMessage(
                    i18n.tr("Schlüssel erfolgreich erstellt"), StatusBarMessage.TYPE_SUCCESS));
        String msg =
            i18n.tr(
                "Bitte senden Sie den INI-Brief an Ihre Bank\nund warten Sie auf die Freischaltung durch die Bank.");
        try {
          Application.getCallback().notifyUser(msg);
        } catch (Exception e2) {
          Logger.error("unable to notify user", e2);
          Application.getMessagingFactory()
              .sendMessage(new StatusBarMessage(msg, StatusBarMessage.TYPE_SUCCESS));
        }
        return key;
      }

      Logger.error("unable to create key " + file.getAbsolutePath(), e);
      throw new ApplicationException(
          i18n.tr("Fehler beim Erstellen des Schlüssels: {0}", e.getMessage()));
    } finally {
      try {
        if (handler != null) handler.close();
      } catch (Throwable t) {
        Logger.error("error while closing handler", t);
      }
    }
  }