Example usage for java.util.logging Logger severe

List of usage examples for java.util.logging Logger severe

Introduction

In this page you can find the example usage for java.util.logging Logger severe.

Prototype

public void severe(Supplier<String> msgSupplier) 

Source Link

Document

Log a SEVERE message, which is only to be constructed if the logging level is such that the message will actually be logged.

Usage

From source file:jp.ikedam.jenkins.plugins.ldap_sasl.LdapSaslSecurityRealm.java

/**
 * Authorize a user.//from w  w  w .  j  a v a 2  s  .c o  m
 * 
 * @param username
 * @param password
 * @see hudson.security.AbstractPasswordBasedSecurityRealm#authenticate(java.lang.String, java.lang.String)
 */
@Override
protected UserDetails authenticate(String username, String password) throws AuthenticationException {
    Logger logger = getLogger();

    // check configuration.
    String ldapUris = getValidLdapUris();
    if (StringUtils.isBlank(ldapUris)) {
        logger.severe("No valid LDAP URI is specified.");
        throw new AuthenticationServiceException("No valid LDAP URI is specified.");
    }

    String mechanisms = getMechanisms();
    if (StringUtils.isBlank(mechanisms)) {
        logger.severe("No valid mechanism is specified.");
        throw new AuthenticationServiceException("No valid mechanism is specified.");
    }

    // TODO: Test with LDAPS.

    // Parameters for JNDI
    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, ldapUris);
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, mechanisms);
    env.put("com.sun.jndi.ldap.connect.timeout", Integer.toString(getConnectionTimeout()));
    env.put("com.sun.jndi.ldap.read.timeout", Integer.toString(getReadTimeout()));

    logger.fine("Authenticating with LDAP-SASL:");
    logger.fine(String.format("username=%s", username));
    logger.fine(String.format("servers=%s", ldapUris));
    logger.fine(String.format("mech=%s", mechanisms));

    LdapContext ctx = null;
    try {
        ctx = new InitialLdapContext(env, null);
    } catch (javax.naming.AuthenticationException e) {
        // Authentication Failure...
        throw new BadCredentialsException(String.format("Authentication failed: %s", username), e);
    } catch (NamingException e) {
        // Unexpected failure...
        throw new AuthenticationServiceException(String.format("Authentication failed: %s", username), e);
    }

    String userDn = (getUserDnResolver() != null) ? getUserDnResolver().getUserDn(ctx, username) : null;
    logger.fine(String.format("User DN is %s", userDn));

    List<GrantedAuthority> authorities = (getGroupResolver() != null)
            ? getGroupResolver().resolveGroup(ctx, userDn, username)
            : new ArrayList<GrantedAuthority>();

    logger.fine("Authenticating succeeded.");
    return new LdapUser(username, "", // password(not used)
            userDn, // dn of this user.
            true, // enabled
            true, // accountNonExpired
            true, // credentialsNonExpired
            true, // accountNonLocked
            authorities.toArray(new GrantedAuthority[0]));
}

From source file:com.ibm.sbt.services.endpoints.AbstractEndpoint.java

@Override
public JSReference getProxy(String endpointName, String moduleId) {
    String proxyModuleId = moduleId;
    Proxy proxy = null;/*from  ww w .j  a  v  a  2 s.c  om*/

    if (this.getProxyConfig() != null) {
        try {
            proxy = ProxyFactory.getProxyConfig(this.getProxyConfig());
            if (proxy != null && proxy.getProxyModule() != null) {
                proxyModuleId = proxy.getProxyModule();
            }
        } catch (ProxyConfigException ex) {
            Logger logger = Logger.getLogger(AbstractEndpoint.class.getName());
            if (logger.isLoggable(Level.SEVERE)) {
                logger.severe(ex.getMessage());
            }
        }
    }

    return new JSReference(proxyModuleId);
}

From source file:org.blazr.extrastorage.ExtraStorage.java

public Inventory getPlayerStorage(String playerName) {
    try {//  w w w  . j a v  a2  s  .co  m
        if (Inventories.containsKey(playerName.toLowerCase())) {
            return (Inventory) Inventories.get(playerName.toLowerCase());
        }
        return null;
    } catch (Exception e) {
        Logger log = getLogger();
        switch (errorLogLevel) {
        case 0:
            break;
        case 1:
            StackTraceElement[] stackTrace = e.getStackTrace();
            log.severe("Error in getPlayerStorage().");
            log.severe(stackTrace[0].toString());
            log.severe(stackTrace[1].toString());
            break;
        case 2:
            e.printStackTrace();
            log.severe("Error in getPlayerStorage().");
            break;
        default:
            e.printStackTrace();
            log.severe("Error in getPlayerStorage().");
        }
    }
    return null;
}

From source file:org.blazr.extrastorage.ExtraStorage.java

public boolean addItemToPlayerStorage(String playerName, ItemStack item) {
    try {// ww w.j  a v a  2 s . c o  m
        boolean hasEmpty = false;
        for (ItemStack inventoryItem : (Inventory) Inventories.get(playerName.toLowerCase())) {
            if (inventoryItem == null) {
                hasEmpty = true;
            }
        }
        if (hasEmpty) {
            ((Inventory) Inventories.get(playerName.toLowerCase())).addItem(new ItemStack[] { item });
            return true;
        }
        return false;
    } catch (Exception e) {
        Logger log = getLogger();
        switch (errorLogLevel) {
        case 0:
            break;
        case 1:
            StackTraceElement[] stackTrace = e.getStackTrace();
            log.severe("Error in addItemToPlayerStorage().");
            log.severe(stackTrace[0].toString());
            log.severe(stackTrace[1].toString());
            break;
        case 2:
            e.printStackTrace();
            log.severe("Error in addItemToPlayerStorage().");
            break;
        default:
            e.printStackTrace();
            log.severe("Error in addItemToPlayerStorage().");
        }
    }
    return false;
}

From source file:org.blazr.extrastorage.ExtraStorage.java

public boolean removeItemFromPlayerStorage(String playerName, ItemStack item) {
    try {/*  w  w  w  .  j av  a  2  s.com*/
        boolean hasItem = false;
        for (ItemStack inventoryItem : (Inventory) Inventories.get(playerName.toLowerCase())) {
            if (inventoryItem == item) {
                hasItem = true;
            }
        }
        if (hasItem) {
            ((Inventory) Inventories.get(playerName.toLowerCase())).remove(item);
            return true;
        }
        return false;
    } catch (Exception e) {
        Logger log = getLogger();
        switch (errorLogLevel) {
        case 0:
            break;
        case 1:
            StackTraceElement[] stackTrace = e.getStackTrace();
            log.severe("Error in removeItemFromPlayerStorage().");
            log.severe(stackTrace[0].toString());
            log.severe(stackTrace[1].toString());
            break;
        case 2:
            e.printStackTrace();
            log.severe("Error in removeItemFromPlayerStorage().");
            break;
        default:
            e.printStackTrace();
            log.severe("Error in removeItemFromPlayerStorage().");
        }
    }
    return false;
}

From source file:jext2.DataBlockAccess.java

/**
 * Free count blocks. Update inode.blocks.
 * @param  blockNr   start physical block to free
 * @param  count   number of blocks to free
 * @throws JExt2Exception//from   w  w  w .j  av a 2  s  .c o  m
 */
@NotThreadSafe(useLock = true)
private void freeDataBlocksContiguous(long blockNr, long count) throws JExt2Exception {
    /* counter to set {superblock|blockgroup}.freeBlocksCount */
    int groupFreed = 0;
    int freed = 0;

    if (blockNr < superblock.getFirstDataBlock() || blockNr + count < blockNr
            || blockNr + count > superblock.getBlocksCount()) {
        throw new RuntimeException("Free blocks not in datazone" + " blockNr=" + blockNr + " count=" + count);
    }

    long overflow;
    do {
        overflow = 0;
        int groupNr = Calculations.groupOfBlk(blockNr);
        int groupIndex = Calculations.groupIndexOfBlk(blockNr);
        BlockGroupDescriptor groupDescr = blockGroups.getGroupDescriptor(groupNr);

        /* Check to see if we are freeing blocks across a group boundary. */
        if (groupIndex + count > superblock.getBlocksPerGroup()) {
            overflow = groupIndex + count - superblock.getBlocksPerGroup();
            count -= overflow;
        }

        Bitmap bitmap = bitmaps.openDataBitmap(groupDescr);

        /* Check to see if we are trying to free a system block */
        if (!(groupDescr.isValidDataBlockNr(blockNr) && groupDescr.isValidDataBlockNr(blockNr + count - 1))) {
            throw new RuntimeException("Freeing blocks in system zones");
        }

        /* Set block bits to "free" */
        groupFreed = 0;
        for (int i = 0; i < count; i++) {
            if (!(bitmap.isSet(groupIndex + i))) {
                Logger log = Filesystem.getLogger();
                log.severe(String.format("Bit allready cleared! block=%d groupIndex=%d bitmap=%s inode=%d",
                        (blockNr + i), (groupIndex + i), bitmap.getBitStringContaining(groupIndex + i),
                        inode.getIno()));
            }

            if (groupIndex + i > superblock.getBlocksPerGroup()) {
                groupFreed++;
            } else {
                groupFreed++;
                bitmap.setBit(groupIndex + i, false);
            }
        }
        bitmap.write();
        bitmaps.closeBitmap(bitmap);

        groupDescr.setFreeBlocksCount(groupDescr.getFreeBlocksCount() + groupFreed);
        freed += groupFreed;

        blockNr += count;
        count = overflow;
    } while (overflow > 0);

    inode.setBlocks(inode.getBlocks() - freed * (superblock.getBlocksize() / 512));
    inode.setModificationTime(new Date());
    superblock.setFreeBlocksCount(superblock.getFreeBlocksCount() + freed);
}

From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.ExtensibleChoiceParameterDefinitionJenkinsTest.java

/**
 * @param def//from  ww w  .  j a va2  s  .  c  o m
 * @param value
 * @return
 * @throws Exception
 */
private EnvVars runBuildWithSelectParameter(ParameterDefinition def, String value) throws Exception {
    FreeStyleProject job = j.createFreeStyleProject();
    job.addProperty(new ParametersDefinitionProperty(def));
    CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
    job.getBuildersList().add(ceb);

    WebClient wc = j.createAllow405WebClient();

    HtmlPage page = wc.getPage(job, "build?delay=0sec");

    HtmlForm form = null;

    try {
        form = page.getFormByName("parameters");
    } catch (ElementNotFoundException e) {
        Logger logger = Logger.getLogger(this.getClass().getName());
        logger.log(Level.SEVERE, "Failed to retrieve parameter form", e);
        logger.severe(page.asXml());
        throw e;
    }

    try {
        HtmlSelect select = form.getSelectByName("value");
        HtmlOption opt;
        try {
            opt = select.getOptionByText(value);
        } catch (ElementNotFoundException e) {
            int newOptPos = select.getOptionSize();
            // There's no such option, so create new option tag.
            DomElement newOpt = page.createElement("option");
            // this seems trim the value...
            //newOpt.setAttribute("value", value);
            newOpt.appendChild(page.createTextNode(value));
            select.appendChild(newOpt);

            opt = select.getOption(newOptPos);
            opt.setValueAttribute(value);
        }
        opt.setSelected(true);
    } catch (ElementNotFoundException e) {
        // selectbox was not found.
        // selectbox is replaced with input field.
        HtmlTextInput input = (HtmlTextInput) form.getInputByName("value");
        input.setValueAttribute(value);
    }
    j.submit(form);

    j.waitUntilNoActivity();

    job.delete();

    return ceb.getEnvVars();
}

From source file:edu.harvard.iq.dataverse.harvest.client.HarvesterServiceBean.java

private void logException(Throwable e, Logger logger) {

    boolean cause = false;
    String fullMessage = "";
    do {/* w  w w . ja  v  a2  s  . co  m*/
        String message = e.getClass().getName() + " " + e.getMessage();
        if (cause) {
            message = "\nCaused By Exception.................... " + e.getClass().getName() + " "
                    + e.getMessage();
        }
        StackTraceElement[] ste = e.getStackTrace();
        message += "\nStackTrace: \n";
        for (int m = 0; m < ste.length; m++) {
            message += ste[m].toString() + "\n";
        }
        fullMessage += message;
        cause = true;
    } while ((e = e.getCause()) != null);
    logger.severe(fullMessage);
}

From source file:org.usrz.libs.logging.LevelTraceTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasLastEvent("at Finest level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasLastEvent("at Finer level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasLastEvent("at Fine level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasLastEvent("at Config level");
    assertTrue(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasLastEvent("at Info level");
    assertTrue(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasLastEvent("at Warning level");
    assertTrue(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}

From source file:org.usrz.libs.logging.LevelDebugTest.java

@Test
public void testJavaLogging() {
    final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

    logger.finest("Foobar FINEST");
    AppenderForTests.hasNoLastEvent("at Finest level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINEST));

    logger.finer("Foobar FINER");
    AppenderForTests.hasNoLastEvent("at Finer level");
    assertFalse(logger.isLoggable(java.util.logging.Level.FINER));

    logger.fine("Foobar FINE");
    AppenderForTests.hasLastEvent("at Fine level");
    assertTrue(logger.isLoggable(java.util.logging.Level.FINE));

    logger.config("Foobar CONFIG");
    AppenderForTests.hasLastEvent("at Config level");
    assertTrue(logger.isLoggable(java.util.logging.Level.CONFIG));

    logger.info("Foobar INFO");
    AppenderForTests.hasLastEvent("at Info level");
    assertTrue(logger.isLoggable(java.util.logging.Level.INFO));

    logger.warning("Foobar WARNING");
    AppenderForTests.hasLastEvent("at Warning level");
    assertTrue(logger.isLoggable(java.util.logging.Level.WARNING));

    logger.severe("Foobar SEVERE");
    AppenderForTests.hasLastEvent("at Severe level");
    assertTrue(logger.isLoggable(java.util.logging.Level.SEVERE));

}