本文整理汇总了Java中com.icthh.xm.commons.logging.util.MDCUtil类的典型用法代码示例。如果您正苦于以下问题:Java MDCUtil类的具体用法?Java MDCUtil怎么用?Java MDCUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MDCUtil类属于com.icthh.xm.commons.logging.util包,在下文中一共展示了MDCUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSystemEvent
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
private String createSystemEvent(String tenant, String command) {
SystemEvent event = new SystemEvent();
event.setEventId(MDCUtil.getRid());
event.setEventType(command);
event.setTenantInfo(TenantContext.getCurrent());
event.setMessageSource(appName);
event.getData().put(Constants.EVENT_TENANT, tenant);
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
try {
return mapper.writeValueAsString(event);
} catch (JsonProcessingException e) {
log.error("System Event mapping error", e);
throw new BusinessException("Event mapping error", e.getMessage());
}
}
示例2: registerAccount
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* POST /register : register the user.
*
* @param user the managed user View Model
* @return the ResponseEntity with status 201 (Created) if the user is registered or 400 (Bad
* Request) if the login is already in use
*/
@PostMapping(path = "/register",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE})
@Timed
public ResponseEntity registerAccount(@Valid @RequestBody ManagedUserVM user, HttpServletRequest request) {
if (user.getEmail() == null) {
throw new BusinessException("Email can't be empty");
}
user.getLogins().forEach(
userLogin -> userLoginRepository.findOneByLoginIgnoreCase(userLogin.getLogin()).ifPresent(s -> {
throw new BusinessException(LOGIN_IS_USED_ERROR_TEXT);
}));
if (captchaService.isCaptchaNeed(request.getRemoteAddr())) {
captchaService.checkCaptcha(user.getCaptcha());
}
User newUser = accountService.register(user, request.getRemoteAddr());
produceEvent(new UserDTO(newUser), Constants.CREATE_PROFILE_EVENT_TYPE);
mailService.sendActivationEmail(
newUser, TenantContext.getCurrent().getTenant(), TenantUtil.getApplicationUrl(), MDCUtil.getRid());
return new ResponseEntity<>(HttpStatus.CREATED);
}
示例3: createUser
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* POST /users : Creates a new user.
*
* <p>Creates a new user if the login and email are not already used, and sends an mail with an
* activation link. The user needs to be activated on creation.
* @param user the user to create
* @return the ResponseEntity with status 201 (Created) and with body the new user, or with
* status 400 (Bad Request) if the login or email is already in use
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity createUser(@Valid @RequestBody UserDTO user) throws URISyntaxException {
if (user.getId() != null) {
return ResponseEntity.badRequest()
.headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new user cannot already have an ID"))
.body(null);
}
user.getLogins().forEach(userLogin ->
userLoginRepository.findOneByLoginIgnoreCase(userLogin.getLogin())
.ifPresent(s -> {
throw new BusinessException(Constants.LOGIN_IS_USED_ERROR_TEXT);
})
);
User newUser = userService.createUser(user);
produceEvent(new UserDTO(newUser), Constants.CREATE_PROFILE_EVENT_TYPE);
mailService.sendCreationEmail(newUser, TenantUtil.getApplicationUrl(),
TenantContext.getCurrent().getTenant(), MDCUtil.getRid());
return ResponseEntity.created(new URI("/api/users/" + newUser.getUserKey()))
.headers(HeaderUtil.createAlert("userManagement.created", newUser.getUserKey()))
.body(new UserDTO(newUser));
}
示例4: createEventJson
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Build message for kafka's event.
* @param user user data for kafka's event content
* @param eventType event type for kafka's event content
*/
public String createEventJson(UserDTO user, String eventType) {
try {
Map<String, Object> map = new LinkedHashMap<>();
map.put("eventId", MDCUtil.getRid());
map.put("messageSource", appName);
map.put("tenantInfo", TenantContext.getCurrent());
map.put("eventType", eventType);
map.put("startDate", Instant.now().toString());
map.put("data", user);
return mapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
log.warn("Error creating profile event", e);
}
return null;
}
示例5: testSendActivationEmail
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
@Test
public void testSendActivationEmail() throws Exception {
User user = new User();
user.setLangKey("en");
UserLogin userLogin = new UserLogin();
userLogin.setTypeKey(UserLoginType.EMAIL.getValue());
userLogin.setLogin("[email protected]");
user.getLogins().add(userLogin);
mailService.sendActivationEmail(user, TENANT_NAME, URL, MDCUtil.getRid());
verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
MimeMessage message = (MimeMessage) messageCaptor.getValue();
assertThat(message.getAllRecipients()[0].toString()).isEqualTo(user.getEmail());
assertThat(message.getFrom()[0].toString()).isEqualTo(EMAIL_FROM);
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
示例6: testCreationEmail
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
@Test
public void testCreationEmail() throws Exception {
UserLogin userLogin = new UserLogin();
userLogin.setTypeKey(UserLoginType.EMAIL.getValue());
userLogin.setLogin("[email protected]");
User user = new User();
user.setFirstName("john");
user.setUserKey("test");
user.setPassword(RandomStringUtils.random(60));
user.setActivated(true);
user.getLogins().add(userLogin);
userLogin.setUser(user);
mailService.sendCreationEmail(user, URL, TENANT_NAME, MDCUtil.getRid());
verify(javaMailSender).send((MimeMessage) messageCaptor.capture());
MimeMessage message = (MimeMessage) messageCaptor.getValue();
assertThat(message.getAllRecipients()[0].toString()).isEqualTo(user.getEmail());
assertThat(message.getFrom()[0].toString()).isEqualTo(EMAIL_FROM);
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
示例7: testPutRid
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
@Test
public void testPutRid() {
assertNull(MDCUtil.getRid());
MDCUtil.put("key", "value");
assertEquals("value", MDC.get("key"));
assertNull(MDCUtil.getRid());
MDCUtil.putRid("myRid");
assertEquals("myRid", MDCUtil.getRid());
assertEquals("myRid", MDC.get("rid"));
MDCUtil.clear();
assertNull(MDCUtil.getRid());
assertNull(MDC.get("key"));
}
示例8: createEventJson
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Build message content for kafka's event.
* @param profile data for kafka message content
* @param eventType event type for kafka message content
* @return event content
*/
public String createEventJson(Profile profile, String eventType) {
try {
Map<String, Object> map = new LinkedHashMap<>();
map.put("eventId", MDCUtil.getRid());
map.put("messageSource", appName);
map.put("tenantInfo", TenantContext.getCurrent());
map.put("eventType", eventType);
map.put("startDate", Instant.now().toString());
map.put("data", buildDataContent(profile));
return mapper.writeValueAsString(map);
} catch (JsonProcessingException e) {
log.warn("Error creating profile event", e);
}
return null;
}
示例9: main
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Main method, used to run the application.
*
* @param args the command line arguments
* @throws UnknownHostException if the local host name could not be resolved into an address
*/
public static void main(String[] args) throws UnknownHostException {
MDCUtil.put();
SpringApplication app = new SpringApplication(UaaApp.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
log.info("\n----------------------------------------------------------\n\t" +
"Application '{}' is running! Access URLs:\n\t" +
"Local: \t\t{}://localhost:{}\n\t" +
"External: \t{}://{}:{}\n\t" +
"Profile(s): \t{}\n----------------------------------------------------------",
env.getProperty("spring.application.name"),
protocol,
env.getProperty("server.port"),
protocol,
InetAddress.getLocalHost().getHostAddress(),
env.getProperty("server.port"),
env.getActiveProfiles());
String configServerStatus = env.getProperty("configserver.status");
log.info("\n----------------------------------------------------------\n\t" +
"Config Server: \t{}\n----------------------------------------------------------",
configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
示例10: requestPasswordReset
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* POST /account/reset_password/init : Send an email to reset the password of the user.
*
* @param mail the mail of the user
* @return the ResponseEntity with status 200 (OK) if the email was sent, or status 400 (Bad
* Request) if the email address is not registered
*/
@PostMapping(path = "/account/reset_password/init",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Timed
public ResponseEntity requestPasswordReset(@RequestBody String mail) {
return userService.requestPasswordReset(mail)
.map(user -> {
String rid = MDCUtil.getRid();
mailService.sendPasswordResetMail(user, TenantUtil.getApplicationUrl(),
TenantContext.getCurrent().getTenant(), rid);
return new ResponseEntity<>("email was sent", HttpStatus.OK);
}).orElseThrow(() -> new BusinessException("email address not registered"));
}
示例11: consumeEvent
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Consume tenant command event message.
* @param message the tenant command event message
*/
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
backoff = @Backoff(delayExpression = "${application.retry.delay}",
multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
MDCUtil.put();
try {
log.info("Input message {}", message);
ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JavaTimeModule());
try {
SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
String command = event.getEventType();
String userKey = String.valueOf(event.getData().get(Constants.USER_KEY));
TenantContext.setCurrent(event.getTenantInfo());
if (Constants.UPDATE_ACCOUNT_EVENT_TYPE.equalsIgnoreCase(command)) {
log.info("Start to update account for userKey='{}'", userKey);
User user = userService.getUser(userKey);
if (user == null) {
log.error("Failed to update account. User with userKey='{}' does not exists.", userKey);
} else {
SystemEventMapper.toUser(event, user);
userService.saveUser(user);
}
}
} catch (IOException e) {
log.error("Kafka message has incorrect format ", e);
}
} finally {
MDCUtil.remove();
}
}
示例12: consumeEvent
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Consume tenant command event message.
* @param message the tenant command event message
*/
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}",
backoff = @Backoff(delayExpression = "${application.retry.delay}",
multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
MDCUtil.put();
try {
log.info("Input message {}", message);
} finally {
MDCUtil.remove();
}
}
示例13: sendActivationEmail
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Send activation email.
*/
@Async
public void sendActivationEmail(User user, String tenant, String url, String rid) {
MDCUtil.putRid(rid);
String email = user.getEmail();
log.info("Sending activation email to {}", email);
sendEmailFromTemplate(user,
"activationEmail",
"email.activation.title",
generateFrom(tenant),
email, url, tenant);
}
示例14: sendCreationEmail
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
@Async
public void sendCreationEmail(User user, String url, String tenantName, String rid) {
MDCUtil.putRid(rid);
log.info("Sending creation email to '{}'", user.getEmail());
sendEmailFromTemplate(
user,
"creationEmail",
"email.activation.title",
generateFrom(tenantName),
user.getEmail(),
url,
tenantName
);
}
示例15: sendPasswordResetMail
import com.icthh.xm.commons.logging.util.MDCUtil; //导入依赖的package包/类
/**
* Send password reset email.
*
* @param user object which stores info about user
* @param url application url
* @param tenantName tenant name
* @param rid transaction id (use for logging)
*/
@Async
public void sendPasswordResetMail(User user, String url, String tenantName, String rid) {
MDCUtil.putRid(rid);
log.info("Sending password reset email to '{}'", user.getEmail());
sendEmailFromTemplate(
user,
"passwordResetEmail",
"email.reset.title",
generateFrom(tenantName),
user.getEmail(),
url,
tenantName
);
}