Example #1
0
  @Override
  public void create(final CreateSsl command, ActionReport report) {

    NetworkConfig netConfig = command.config.getNetworkConfig();
    // ensure we have the specified listener
    NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
    Protocol httpProtocol;
    try {
      if (listener == null) {
        report.setMessage(
            WebContainer.rb.getString(
                MessageFormat.format(CREATE_SSL_HTTP_NOT_FOUND, command.listenerId)));
        httpProtocol = command.findOrCreateProtocol(command.listenerId);
      } else {
        httpProtocol = listener.findHttpProtocol();
        Ssl ssl = httpProtocol.getSsl();
        if (ssl != null) {
          report.setMessage(
              WebContainer.rb.getString(
                  MessageFormat.format(CREATE_SSL_HTTP_ALREADY_EXISTS, command.listenerId)));
          report.setActionExitCode(ActionReport.ExitCode.FAILURE);
          return;
        }
      }
      ConfigSupport.apply(
          new SingleConfigCode<Protocol>() {
            public Object run(Protocol param) throws TransactionFailure {
              Ssl newSsl = param.createChild(Ssl.class);
              command.populateSslElement(newSsl);
              param.setSsl(newSsl);
              return newSsl;
            }
          },
          httpProtocol);

    } catch (TransactionFailure e) {
      command.reportError(report, e);
    }
    command.reportSuccess(report);
  }
Example #2
0
  @Override
  public void delete(DeleteSsl command, ActionReport report) {

    NetworkConfig netConfig = command.config.getNetworkConfig();
    NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);

    if (networkListener == null) {
      report.setMessage(
          WebContainer.rb.getString(
              MessageFormat.format(DELETE_SSL_HTTP_LISTENER_NOT_FOUND, command.listenerId)));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }

    Protocol protocol = networkListener.findHttpProtocol();
    if (protocol.getSsl() == null) {
      report.setMessage(
          WebContainer.rb.getString(
              MessageFormat.format(DELETE_SSL_ELEMENT_DOES_NOT_EXIST, command.listenerId)));
      report.setActionExitCode(ActionReport.ExitCode.FAILURE);
      return;
    }

    try {
      ConfigSupport.apply(
          new SingleConfigCode<Protocol>() {
            public Object run(Protocol param) {
              param.setSsl(null);
              return null;
            }
          },
          networkListener.findHttpProtocol());
    } catch (TransactionFailure e) {
      command.reportError(report, e);
    }
  }