use of javax.interceptor.Interceptors in project microservice_framework by CJSCommonPlatform.
the class SubscriptionJmsEndpointGeneratorTest method shouldCreateJmsEndpointAnnotatedWithInterceptors.
@Test
public void shouldCreateJmsEndpointAnnotatedWithInterceptors() throws Exception {
SubscriptionDescriptor subscriptionDescriptor = setUpMessageSubscription("jms:topic:people.handler.command", "people.abc", serviceName, componentName);
generator.run(subscriptionDescriptor, configurationWithBasePackage(BASE_PACKAGE, outputFolder, generatorProperties));
Class<?> clazz = compiler.compiledClassOf(BASE_PACKAGE, "ContextEventProcessorPeopleHandlerCommandJmsListener");
Interceptors interceptorsAnnotation = clazz.getAnnotation(Interceptors.class);
assertThat(interceptorsAnnotation, not(nullValue()));
assertThat(interceptorsAnnotation.value(), hasItemInArray(JsonSchemaValidationInterceptor.class));
assertThat(interceptorsAnnotation.value(), hasItemInArray(JmsLoggerMetadataInterceptor.class));
}
use of javax.interceptor.Interceptors in project Payara by payara.
the class InterceptorsHandler method processAnnotation.
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
Interceptors interceptors = (Interceptors) ainfo.getAnnotation();
EjbBundleDescriptorImpl ejbBundle = ((EjbDescriptor) ejbContexts[0].getDescriptor()).getEjbBundleDescriptor();
// Process each of the interceptor classes.
for (Class interceptor : interceptors.value()) {
processInterceptorClass(interceptor, ejbBundle, ainfo);
}
for (EjbContext next : ejbContexts) {
EjbDescriptor ejbDescriptor = (EjbDescriptor) next.getDescriptor();
// Create binding information.
InterceptorBindingDescriptor binding = new InterceptorBindingDescriptor();
binding.setEjbName(ejbDescriptor.getName());
for (Class interceptor : interceptors.value()) {
binding.appendInterceptorClass(interceptor.getName());
}
if (ElementType.METHOD.equals(ainfo.getElementType())) {
Method m = (Method) ainfo.getAnnotatedElement();
MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.EJB_BEAN);
binding.setBusinessMethod(md);
} else if (ElementType.CONSTRUCTOR.equals(ainfo.getElementType())) {
Constructor c = (Constructor) ainfo.getAnnotatedElement();
Class cl = c.getDeclaringClass();
Class[] ctorParamTypes = c.getParameterTypes();
String[] parameterClassNames = (new MethodDescriptor()).getParameterClassNamesFor(null, ctorParamTypes);
MethodDescriptor md = new MethodDescriptor(cl.getSimpleName(), null, parameterClassNames, MethodDescriptor.EJB_BEAN);
binding.setBusinessMethod(md);
}
// All binding information processed from annotations should go
// before the binding information processed from the descriptors.
// Since descriptors are processed first, always place the binding
// info at the front. The binding information from the descriptor
// is ordered, but there is no prescribed order in which the
// annotations are processed, so all that matters is that it's
// before the descriptor bindings and that the descriptor binding
// order is preserved.
ejbBundle.prependInterceptorBinding(binding);
}
return getDefaultProcessedResult();
}
use of javax.interceptor.Interceptors in project rubia-forums by flashboss.
the class EditPost method execute.
/**
* @return the navigation state of the application
*/
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String execute() {
String navState = null;
boolean success = false;
try {
// setup the business objects to be updated
Post post = forumsModule.findPostById(postId);
forumsModule.updateAttachments(attachments, post);
// TODO: cleanup this forums update process............move this as
// a private method
// setup attachment information
Topic topic = post.getTopic();
// make sure this topic is not locked
if (topic.getStatus() == TOPIC_LOCKED) {
// should not allow posting a reply since the topic is locked
throw new Exception(getBundleMessage(BUNDLE_NAME, TOPIC_LOCKED_ERR_KEY));
}
// setup the message/subject related data
Message message = createMessage();
message.setText(this.message);
message.setSubject(subject);
// update the message/subject/topicType data on the business objects
post.setMessage(message);
if (isFirstPost) {
topic.setSubject(subject);
topic.setType(topicType);
}
// miscellaneous post related update
post.setEditCount(post.getEditCount() + 1);
post.setEditDate(new Date());
// TODO: cleanup this poll update process............move this as a
// private method
// setup poll information
List<PollOption> localPollOptions = new LinkedList<PollOption>();
for (String key : options.keySet()) {
PollOption pollOption = createPollOption(topic.getPoll());
pollOption.setQuestion(options.get(key));
pollOption.setVotes(0);
localPollOptions.add(pollOption);
}
// update poll information
if (topic.getPoll() == null || topic.getPoll().getTitle() == null || topic.getPoll().getTitle().trim().length() == 0) {
// no existing poll information found in the database
if (localPollOptions.size() > 0 && question != null && question.trim().length() > 0) {
// need to add a new poll to this topic
Poll poll = createPoll();
poll.setTitle(question);
poll.setLength(activeDuration);
poll.setOptions(localPollOptions);
validatePoll(poll);
forumsModule.addPollToTopic(topic, poll);
}
} else {
// existing poll information is available in the database
if (localPollOptions.size() > 0) {
// this is a diff update..............................
// setup the poll to be updated in the database
Poll poll = createPoll();
poll.setTitle(question);
poll.setLength(activeDuration);
poll.setVoted(topic.getPoll().getVoted());
poll.setCreationDate(topic.getPoll().getCreationDate());
for (PollOption newPollOption : localPollOptions) {
Iterator<PollOption> stored = topic.getPoll().getOptions().iterator();
while (stored.hasNext()) {
PollOption oldPollOption = (PollOption) stored.next();
if (oldPollOption != null && oldPollOption.getQuestion().equals(newPollOption.getQuestion())) {
newPollOption.setVotes(oldPollOption.getVotes());
break;
}
}
}
poll.setOptions(localPollOptions);
forumsModule.addPollToTopic(topic, poll);
} else {
// remove the poll from the database...poll was removed
// during this editPost process
topic.setPoll(null);
}
}
forumsModule.update(topic);
forumsModule.update(post);
// set the proper navigation state
navState = SUCCESS;
success = true;
} catch (PollValidationException e) {
// handle proper validation error with a proper message...not just a
// generic message..
// just use generic error page for the proof of concept
// set the custom exception such that e.toString() results in the
// proper message
handleException(e);
} catch (Exception e) {
handleException(e);
} finally {
// cleanup if necessary
if (success) {
cleanup();
}
}
return navState;
}
use of javax.interceptor.Interceptors in project rubia-forums by flashboss.
the class NewTopic method execute.
/**
* Execute
*
* @return the navigation state of the application
*/
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String execute() {
String navState = null;
boolean success = false;
try {
// setup the message
Message message = createMessage();
message.setText(this.message);
message.setSubject(subject);
// setup the forum and the corresponding poster
Forum forum = forumsModule.findForumById(forumId);
Poster poster = getPoster(userModule, forumsModule);
// setup the poll related information
Poll poll = createPoll();
if (question != null && question.trim().length() > 0) {
poll.setTitle(question);
poll.setLength(activeDuration);
List<PollOption> pollOptions = new LinkedList<PollOption>();
for (String option : options.keySet()) {
PollOption pollOption = createPollOption(poll);
pollOption.setQuestion((String) options.get(option));
pollOption.setVotes(0);
pollOptions.add(pollOption);
}
poll.setOptions(pollOptions);
validatePoll(poll);
}
poster.incrementPostCount();
// actually create the topic in this forum
// use this method when poll and attachments are actually integrated
// poll
forumsModule.createTopic(// poll
forum, // poll
message, // poll
new Date(), // poll
poster, // poll
poll, // attachments
attachments, topicType);
// setup the navigation state
navState = SUCCESS;
success = true;
} catch (MessageValidationException e) {
// handle proper validation error with a proper message...not just a
// generic message..
// just use generic error page for the proof of concept
// set the custom exception such that e.toString() results in the
// proper message
handleException(e);
} catch (PollValidationException e) {
// handle proper validation error with a proper message...not just a
// generic message..
// just use generic error page for the proof of concept
// set the custom exception such that e.toString() results in the
// proper message
handleException(e);
} catch (Exception e) {
handleException(e);
} finally {
// cleanup if necessary
if (success) {
cleanup();
}
}
return navState;
}
use of javax.interceptor.Interceptors in project rubia-forums by flashboss.
the class TopicWatchController method activateWatch.
/**
* @return the navigation state of the application
*/
@SecureActionForum
@Interceptors(AuthorizationListener.class)
public String activateWatch() {
String navState = null;
try {
// checking for needed parameters
if (topicId == -1 || watchType == -1) {
return navState;
}
// make sure a watch for this topic is not already issued for this
// user
boolean isDuplicate = isWatched();
if (isDuplicate) {
return navState;
}
// get the topic that must be activated for watching
Topic topic = forumsModule.findTopicById(topicId);
// activate the watch for the selected topic
forumsModule.createWatch(getPoster(userModule, forumsModule), topic, watchType);
navState = "success";
} catch (Exception e) {
handleException(e);
}
return navState;
}
Aggregations