Java AcmeConflictException类使用实例

发布时间:2025-12-09 11:45:30 浏览次数:8

实例1: loadOrRegisterAccount

import org.shredzone.acme4j.exception.AcmeConflictException; //导入依赖的package包/类private Registration loadOrRegisterAccount(Session session) throws AcmeException {Registration reg;try {messages.add("registering new user", LOG);reg = new RegistrationBuilder().create(session);URI agreement = reg.getAgreement();messages.add("accepting terms of service", LOG);EditableRegistration editableReg = reg.modify();editableReg.setAgreement(agreement);editableReg.addContact("mailto:" + config.getProperty("server.login"));editableReg.commit();} catch (AcmeConflictException ex) {messages.add("account already exists. use it", LOG);reg = Registration.bind(session, ex.getLocation());}return reg;} 

实例2: findOrRegisterAccount

import org.shredzone.acme4j.exception.AcmeConflictException; //导入依赖的package包/类/** * Finds your {@link Registration} at the ACME server. It will be found by your user's * public key. If your key is not known to the server yet, a new registration will be * created. * <p> * This is a simple way of finding your {@link Registration}. A better way is to get * the URI of your new registration with {@link Registration#getLocation()} and store * it somewhere. If you need to get access to your account later, reconnect to it via * {@link Registration#bind(Session, URI)} by using the stored location. * * @param session *            {@link Session} to bind with * @return {@link Registration} connected to your account */private Registration findOrRegisterAccount(Session session, String contact) throws AcmeException {    Registration reg;    try {        // Try to create a new Registration.        reg = new RegistrationBuilder().addContact("mailto:" + contact).create(session);        log.info("Registered a new user, URI: " + reg.getLocation());        // This is a new account. Let the user accept the Terms of Service.        // We won't be able to authorize domains until the ToS is accepted.        URI agreement = reg.getAgreement();        reg.modify().setAgreement(agreement).commit();    } catch (AcmeConflictException ex) {        // The Key Pair is already registered. getLocation() contains the        // URL of the existing registration's location. Bind it to the session.        reg = Registration.bind(session, ex.getLocation());        log.info("Account does already exist, URI: " + reg.getLocation());        log.debug(ex);    }    return reg;} 

实例3: RegistrationManager

import org.shredzone.acme4j.exception.AcmeConflictException; //导入依赖的package包/类public RegistrationManager(Session session) throws AcmeException {    this.session = session;    try {        this.registration = new RegistrationBuilder().create(session);    } catch (AcmeConflictException ex) {        this.registration = Registration.bind(session, ex.getLocation());        LOG.info("You already have an account. Account reestablished.");    }} 
ACMEZONE
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477