Java Code Examples for org.springframework.binding.message.MessageBuilder

The following examples show how to use org.springframework.binding.message.MessageBuilder. These examples are extracted from open source projects. 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 Project: tutorial   Source File: BuyHandler.java    License: MIT License 6 votes vote down vote up
/**
 * action-state 中的 evaluate 执行的方法需要返回值;并且 action-state 中根据这个返回值来决定下一步去那里
 * @param shoppingCart
 * @param error
 * @return
 */
public String createOrder(ShoppingCart shoppingCart, Order order, MessageContext error) {
    logger.trace("createOrder shoppingCart:{}, order: {}, eror: {}", shoppingCart, order, error);

    String returnValue = "success";

    if (shoppingCart.getCartItems() == null || shoppingCart.getCartItems().size() == 0) {
        error.addMessage(new MessageBuilder(). //
                error() //
                .defaultText("购物车是空的") //
                .build());

        returnValue = "fail";
    }

    // 还应检查购物车内物品是否已经下架等

    //创建订单
    order.setId("O99999");
    order.setPayDate(new Date());

    return returnValue;
}
 
Example 2
Source Project: openregistry   Source File: PersonSearchAction.java    License: Apache License 2.0 6 votes vote down vote up
public void setConfirmationMessage(final ServiceExecutionResult<Person> serviceExecutionResult, final ReconciliationResult reconciliationResult, final MessageContext context) {
    //if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
    //a force add, would result in no reconciliationResult.

    if (reconciliationResult != null){
        if (reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.EXACT ||
                reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.MAYBE) {
            context.addMessage(new MessageBuilder().info().code("roleAdded").build());
            return;
        }
    }

    final Person person = serviceExecutionResult.getTargetObject();
    final Identifier netId = person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);

    if (person.getCurrentActivationKey() != null) {
        final MessageResolver message = new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg(person.getCurrentActivationKey().asString()).build();
        context.addMessage(message);
    } else {
        context.addMessage(new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg("TempKey").build());
    }
}
 
Example 3
Source Project: openregistry   Source File: PersonSearchAction.java    License: Apache License 2.0 6 votes vote down vote up
public void setConfirmationMessage(final ServiceExecutionResult<Person> serviceExecutionResult, final ReconciliationResult reconciliationResult, final MessageContext context) {
    //if reconciliation result is EXACT or MAYBE then only a role was added, not a new person.
    //a force add, would result in no reconciliationResult.

    if (reconciliationResult != null){
        if (reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.EXACT ||
                reconciliationResult.getReconciliationType() == ReconciliationResult.ReconciliationType.MAYBE) {
            context.addMessage(new MessageBuilder().info().code("roleAdded").build());
            return;
        }
    }

    final Person person = serviceExecutionResult.getTargetObject();
    final Identifier netId = person.getPrimaryIdentifiersByType().get(this.preferredPersonIdentifierType);

    if (person.getCurrentActivationKey() != null) {
        final MessageResolver message = new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg(person.getCurrentActivationKey().asString()).build();
        context.addMessage(message);
    } else {
        context.addMessage(new MessageBuilder().info().code("personAddedFinalConfirm").arg(netId.getValue()).arg("TempKey").build());
    }
}
 
Example 4
Source Project: taoshop   Source File: AuthenticationViaFormAction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a warning message to the message context.
 *
 * @param context Message context.
 * @param warning Warning message.
 */
private static void addWarningToContext(final MessageContext context, final MessageDescriptor warning) {
    final MessageBuilder builder = new MessageBuilder()
            .warning()
            .code(warning.getCode())
            .defaultText(warning.getDefaultMessage())
            .args(warning.getParams());
    context.addMessage(builder.build());
}
 
Example 5
/**
 * Adds a warning message to the message context.
 *
 * @param context Message context.
 * @param warning Warning message.
 */
private void addWarningToContext(final MessageContext context, final MessageDescriptor warning) {
    final MessageBuilder builder = new MessageBuilder()
            .warning()
            .code(warning.getCode())
            .defaultText(warning.getDefaultMessage())
            .args(warning.getParams());
    context.addMessage(builder.build());
}
 
Example 6
/**
 * Adds a warning message to the message context.
 *
 * @param context Message context.
 * @param warning Warning message.
 */
private void addWarningToContext(final MessageContext context, final Message warning) {
    final MessageBuilder builder = new MessageBuilder()
            .warning()
            .code(warning.getCode())
            .defaultText(warning.getDefaultMessage())
            .args(warning.getParams());
    context.addMessage(builder.build());
}
 
Example 7
Source Project: Spring-MVC-Blueprints   Source File: CartController.java    License: MIT License 5 votes vote down vote up
public Event checkUser(LoginForm login, MessageContext messageContext) {
	if (loginService.retrieveAccount(login.getUsername()) == null) {
		MessageBuilder errorMessageBuilder1 = new MessageBuilder().error();
		errorMessageBuilder1.source("username");
		errorMessageBuilder1.code("login.username.error");
		messageContext.addMessage(errorMessageBuilder1.build());
		
		MessageBuilder errorMessageBuilder2 = new MessageBuilder().error();
		errorMessageBuilder2.source("password");
		errorMessageBuilder2.code("login.password.error");
		messageContext.addMessage(errorMessageBuilder2.build());
		return new EventFactorySupport().error(this);
	}
	return new EventFactorySupport().success(this);
}
 
Example 8
Source Project: enhanced-pet-clinic   Source File: User.java    License: Apache License 2.0 5 votes vote down vote up
public void validateCreateUser(ValidationContext context) {
	MessageContext messages = context.getMessageContext();
	if (!StringUtils.equals(uiPassword, verifyPassword)) {
		messages.addMessage(new MessageBuilder().error().source("password").source("verifyPassword")
				.defaultText("Passwords must be the same.").build());
	}
}
 
Example 9
Source Project: openregistry   Source File: AbstractPersonServiceAction.java    License: Apache License 2.0 5 votes vote down vote up
public final boolean convertAndReturnStatus(final ServiceExecutionResult<?> serviceExecutionResult, final MessageContext messageContext, final String successMessageCode) {
    this.converter.convertValidationErrors(serviceExecutionResult.getValidationErrors(), messageContext);

    if (serviceExecutionResult.succeeded() && successMessageCode != null) {
        messageContext.addMessage(new MessageBuilder().info().code(successMessageCode).build());
    }
    return serviceExecutionResult.succeeded();
}
 
Example 10
Source Project: openregistry   Source File: RoleAction.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isRoleNewForPerson(SorPerson sorPerson, Type affiliationType, MessageContext context) {
	//check if person already has the role to be added.
	logger.info("IsRoleNewForPerson: code:"+ affiliationType);
	final Person person = getPersonService().findPersonById(sorPerson.getPersonId());
	if (person.pickOutRole(affiliationType) != null){
		context.addMessage(new MessageBuilder().error().code("roleAlreadyExists").build());
		return false;
	}
	return true;
}
 
Example 11
Source Project: openregistry   Source File: AbstractPersonServiceAction.java    License: Apache License 2.0 5 votes vote down vote up
public final boolean convertAndReturnStatus(final ServiceExecutionResult<?> serviceExecutionResult, final MessageContext messageContext, final String successMessageCode) {
    this.converter.convertValidationErrors(serviceExecutionResult.getValidationErrors(), messageContext);

    if (serviceExecutionResult.succeeded() && successMessageCode != null) {
        messageContext.addMessage(new MessageBuilder().info().code(successMessageCode).build());
    }
    return serviceExecutionResult.succeeded();
}
 
Example 12
Source Project: openregistry   Source File: RoleAction.java    License: Apache License 2.0 5 votes vote down vote up
public boolean isRoleNewForPerson(SorPerson sorPerson, Type affiliationType, MessageContext context) {
    //check if person already has the role to be added.
    logger.info("IsRoleNewForPerson: code:"+ affiliationType.getDescription());
    final Person person = getPersonService().findPersonById(sorPerson.getPersonId());
    if (person.pickOutRole(affiliationType) != null){
        context.addMessage(new MessageBuilder().error().code("roleAlreadyExists").build());
        return false;
    }
    return true;
}
 
Example 13
/**
 * Checks if is valid login ticket.
 *
 * @param context the context
 * @param messageContext the message context
 *
 * @return true, if is valid login ticket
 */
protected final boolean isValidLoginTicket(final RequestContext context, final MessageContext messageContext) {
    final String authoritativeLoginTicket = WebUtils.getLoginTicketFromFlowScope(context);
    final String providedLoginTicket = WebUtils.getLoginTicketFromRequest(context);
    if (!authoritativeLoginTicket.equals(providedLoginTicket)) {
        logger.warn("Invalid login ticket {}", providedLoginTicket);
        final String code = "INVALID_TICKET";
        messageContext.addMessage(new MessageBuilder().error().code(code).arg(providedLoginTicket).defaultText(code).build());
        return false;
    }
    return true;
}
 
Example 14
/**
 * Populate errors instance.
 *
 * @param code the error code
 * @param messageContext the message context
 */
protected final void populateErrorsInstance(final String code, final MessageContext messageContext) {
    try {
        messageContext.addMessage(new MessageBuilder().error().code(code).defaultText(code).build());
    }  catch (final Exception fe) {
        logger.error(fe.getMessage(), fe);
    }
}
 
Example 15
@Override
public String getPersonToGreet(final Principal p, final MessageContext messageContext) {

    String personId = p.getId();
    final Object attrValue = p.getAttributes().get(this.greetingAttributeName);

    if (attrValue == null) {
        LOGGER.warn("No attribute value could be found for [{}]", this.greetingAttributeName);
        return p.getId();
    }

    String greetingPersonId = attrValue.toString();
    if (attrValue instanceof Collection) {
        final Collection col =((Collection) attrValue);
        if (!col.isEmpty()) {
            greetingPersonId = col.iterator().next().toString();
            LOGGER.warn("Found multiple attribute values [{}] for [{}] to greet. Picked [{}]",
                    attrValue, this.greetingAttributeName,
                    greetingPersonId);
        }
    }

    if (!StringUtils.isBlank(greetingPersonId)) {
        personId = greetingPersonId;
    }

    final MessageResolver resolver = new MessageBuilder().source(CODE).info().code(CODE).arg(personId).build();
    messageContext.addMessage(resolver);

    final Message[] messages = messageContext.getMessagesBySource(CODE);
    if (messages == null || messages.length == 0) {
        LOGGER.warn("The greeting message for principal [{}] could not be resolved by the "
                + "code [{}] in any of the configured message resource bundles. Falling back to principal id [{}]",
                p, CODE, p.getId());
        return p.getId();
    }
    return messages[0].getText();
}
 
Example 16
Source Project: sso   Source File: ValidateLoginCaptchaAction.java    License: MIT License 4 votes vote down vote up
/**
 * 跳转到错误页
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 17
/**
 * Return invalid login ticket event.
 *
 * @param context the context
 * @param messageContext the message context
 * @return the error event
 * @since 4.1.0
 */
protected Event returnInvalidLoginTicketEvent(final RequestContext context, final MessageContext messageContext) {
    final String loginTicketFromRequest = WebUtils.getLoginTicketFromRequest(context);
    logger.warn("Invalid login ticket [{}]", loginTicketFromRequest);
    messageContext.addMessage(new MessageBuilder().error().code("error.invalid.loginticket").build());
    return newEvent(ERROR);
}
 
Example 18
/**
 * Converts the validation errors returned from the {@link org.openregistry.core.service.PersonService} into
 * Spring {@link org.springframework.binding.message.MessageContext} for Spring Web flow.
 *
 * @param validationErrors the errors provided by the {@link org.openregistry.core.service.PersonService}
 * @param messages an instance of Spring's {@link org.springframework.binding.message.MessageContext}
 */
public void convertValidationErrors(final Set<ConstraintViolation> validationErrors, final MessageContext messages) {
    for (final ConstraintViolation violation : validationErrors) {
        messages.addMessage(new MessageBuilder().error().args(violation.getConstraintDescriptor().getAttributes().values().toArray())
                .source(violation.getPropertyPath().toString()).code(violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName()).defaultText(violation.getMessage()).build());
    }
}
 
Example 19
/**
 * Converts the validation errors returned from the {@link org.openregistry.core.service.PersonService} into
 * Spring {@link org.springframework.binding.message.MessageContext} for Spring Web flow.
 *
 * @param validationErrors the errors provided by the {@link org.openregistry.core.service.PersonService}
 * @param messages an instance of Spring's {@link org.springframework.binding.message.MessageContext}
 */
public void convertValidationErrors(final Set<ConstraintViolation> validationErrors, final MessageContext messages) {
    for (final ConstraintViolation violation : validationErrors) {
        messages.addMessage(new MessageBuilder().error().args(violation.getConstraintDescriptor().getAttributes().values().toArray())
                .source(violation.getPropertyPath().toString()).code(violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName()).defaultText(violation.getMessage()).build());
    }
}
 
Example 20
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 21
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 22
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 23
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 24
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 25
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}
 
Example 26
Source Project: CAS   Source File: ValidateLoginAction.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 跳转到错误页
 *
 * @param requestContext
 * @return
 */
private Event getError(final RequestContext requestContext, String CODE) {
    final MessageContext messageContext = requestContext.getMessageContext();
    messageContext.addMessage(new MessageBuilder().error().code(CODE).build());
    return getEventFactorySupport().event(this, CODE);
}