Java Code Examples for org.apache.logging.log4j.ThreadContext#get()

The following examples show how to use org.apache.logging.log4j.ThreadContext#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadContextKeyExistsFilter.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
public Result filter() {
    if (key == null) {
        return Result.NEUTRAL;
    }

    if (ThreadContext.get(key) != null) {
        if (acceptIfKeyExists) {
            return Result.ACCEPT;
        } else {
            return Result.DENY;
        }
    } else {
        if (denyIfKeyDoesNotExist) {
            return Result.DENY;
        } else {
            return Result.NEUTRAL;
        }
    }
}
 
Example 2
Source File: RequestContext.java    From audit-log-plugin with MIT License 5 votes vote down vote up
public static String getRequestId() {
    String uuidStr = ThreadContext.get(REQUEST_ID);
    if (uuidStr == null) {
        ThreadContext.put(REQUEST_ID, UuidUtil.getTimeBasedUuid().toString());
        uuidStr = ThreadContext.get(REQUEST_ID);
    }
    return uuidStr;
}
 
Example 3
Source File: LogEventFactory.java    From logging-log4j-audit with Apache License 2.0 5 votes vote down vote up
private static void validateContextConstraint(RequestContext constraint, StringBuilder errors) {
    if (constraint == null) {
        // the request context is not mandatory
        return;
    }

    String value = ThreadContext.get(constraint.key());
    if (value != null) {
        validateConstraints(true, constraint.constraints(), constraint.key(), value, errors);
    } else if (constraint.required()) {
        appendNewline(errors);
        errors.append("ThreadContext does not contain required key ").append(constraint.key());
    }
}
 
Example 4
Source File: RequestContext.java    From logging-log4j-audit with Apache License 2.0 5 votes vote down vote up
public static Long getAccountNumber() {
    String value = ThreadContext.get(ACCOUNT_NUMBER);
    if (value == null || value.length() == 0) {
        return 0L;
    }
    try {
        return Long.parseLong(value);
    } catch (Exception e) {
        return 0L;
    }
}
 
Example 5
Source File: CephPrimaryStorageBase.java    From zstack with Apache License 2.0 4 votes vote down vote up
private void handle(final UploadBitsToBackupStorageMsg msg) {
    checkCephFsId(msg.getPrimaryStorageUuid(), msg.getBackupStorageUuid());
    SimpleQuery<BackupStorageVO> q = dbf.createQuery(BackupStorageVO.class);
    q.select(BackupStorageVO_.type);
    q.add(BackupStorageVO_.uuid, Op.EQ, msg.getBackupStorageUuid());
    String bsType = q.findValue();

    String path = CP_PATH;
    String hostname = null;

    if (!CephConstants.CEPH_BACKUP_STORAGE_TYPE.equals(bsType)) {
        List<PrimaryStorageCommitExtensionPoint> exts = pluginRgty.getExtensionList(PrimaryStorageCommitExtensionPoint.class);
        DebugUtils.Assert(exts.size() <= 1, "PrimaryStorageCommitExtensionPoint mustn't > 1");
        if (exts.size() == 0) {
            throw new OperationFailureException(operr(
                    "unable to upload bits to the backup storage[type:%s], we only support CEPH", bsType
            ));
        } else {
            path = exts.get(0).getCommitAgentPath(self.getType());
            hostname = exts.get(0).getHostName(msg.getBackupStorageUuid());
            DebugUtils.Assert(path != null, String.format("found the extension point: [%s], but return null path",
                    exts.get(0).getClass().getSimpleName()));
        }
    }

    UploadCmd cmd = new UploadCmd();
    cmd.sendCommandUrl = restf.getSendCommandUrl();
    cmd.fsId = getSelf().getFsid();
    cmd.srcPath = msg.getPrimaryStorageInstallPath();
    cmd.dstPath = msg.getBackupStorageInstallPath();

    if (msg.getImageUuid() != null) {
        cmd.imageUuid = msg.getImageUuid();
        ImageInventory inv = ImageInventory.valueOf(dbf.findByUuid(msg.getImageUuid(), ImageVO.class));

        StringBuilder desc = new StringBuilder();
        for (CreateImageExtensionPoint ext : pluginRgty.getExtensionList(CreateImageExtensionPoint.class)) {
            String tmp = ext.getImageDescription(inv);
            if (tmp != null && !tmp.trim().equals("")) {
                desc.append(tmp);
            }
        }
        cmd.description = desc.toString();
    }
    if (hostname != null) {
        // imagestore hostname
        cmd.hostname = hostname;
    }

    final String apiId = ThreadContext.get(Constants.THREAD_CONTEXT_API);
    final UploadBitsToBackupStorageReply reply = new UploadBitsToBackupStorageReply();
    new HttpCaller<>(path, cmd, CpRsp.class, new ReturnValueCompletion<CpRsp>(msg) {
        @Override
        public void success(CpRsp rsp) {
            if (rsp.installPath != null) {
                reply.setInstallPath(rsp.installPath);
            }
            bus.reply(msg, reply);
        }

        @Override
        public void fail(ErrorCode errorCode) {
            reply.setError(errorCode);
            bus.reply(msg, reply);
        }
    }).specifyOrder(apiId).call();
}
 
Example 6
Source File: Log4j2MsgIdHolder.java    From xian with Apache License 2.0 4 votes vote down vote up
@Override
protected String get0() {
    return ThreadContext.get(MSG_ID_KEY);
}
 
Example 7
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getTransId() {
    return ThreadContext.get(TRANSACTION_ID);
}
 
Example 8
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getLocale() {
    return ThreadContext.get(LOCALE);
}
 
Example 9
Source File: RequestContext.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
public static String getHostName() {
    return ThreadContext.get(HOST_NAME);
}
 
Example 10
Source File: RequestContext.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
public static String getUserId() {
    return ThreadContext.get(USER_ID);
}
 
Example 11
Source File: RequestContext.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
public static String getIpAddress() {
    return ThreadContext.get(IP_ADDRESS);
}
 
Example 12
Source File: RequestContext.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
public static String getSessionId() {
    return ThreadContext.get(SESSION_ID);
}
 
Example 13
Source File: Log4jMDCAdapter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public String get(final String key) {
    return ThreadContext.get(key);
}
 
Example 14
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getProductName() {
    return ThreadContext.get(PRODUCT_NAME);
}
 
Example 15
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getUserId() {
    return ThreadContext.get(USER_ID);
}
 
Example 16
Source File: RequestContext.java    From audit-log-plugin with MIT License 4 votes vote down vote up
public static String getTimeStamp() {
    return ThreadContext.get(TIMESTAMP);
}
 
Example 17
Source File: Log4jMDCAdapter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public String get(final String key) {
    return ThreadContext.get(key);
}
 
Example 18
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getId() {
    return ThreadContext.get(REQUEST_ID);
}
 
Example 19
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getUserAgent() {
    return ThreadContext.get(USER_AGENT);
}
 
Example 20
Source File: RequestContext.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public static String getClientId() {
    return ThreadContext.get(CLIENT_ID);
}