Search in sources :

Example 11 with Interceptors

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));
}
Also used : Interceptors(javax.interceptor.Interceptors) JsonSchemaValidationInterceptor(uk.gov.justice.services.adapter.messaging.JsonSchemaValidationInterceptor) JmsLoggerMetadataInterceptor(uk.gov.justice.services.adapter.messaging.JmsLoggerMetadataInterceptor) SubscriptionDescriptor(uk.gov.justice.subscription.domain.SubscriptionDescriptor) Test(org.junit.Test)

Example 12 with Interceptors

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();
}
Also used : Interceptors(javax.interceptor.Interceptors) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) InterceptorBindingDescriptor(org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 13 with Interceptors

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;
}
Also used : PortalUtil.createMessage(it.vige.rubia.PortalUtil.createMessage) JSFUtil.getBundleMessage(it.vige.rubia.ui.JSFUtil.getBundleMessage) Message(it.vige.rubia.model.Message) Post(it.vige.rubia.model.Post) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Date(java.util.Date) LinkedList(java.util.LinkedList) PortalUtil.createPoll(it.vige.rubia.PortalUtil.createPoll) Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) PortalUtil.createPollOption(it.vige.rubia.PortalUtil.createPollOption) Topic(it.vige.rubia.model.Topic) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 14 with Interceptors

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;
}
Also used : PortalUtil.createMessage(it.vige.rubia.PortalUtil.createMessage) Message(it.vige.rubia.model.Message) LinkedList(java.util.LinkedList) Date(java.util.Date) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Forum(it.vige.rubia.model.Forum) SecureActionForum(it.vige.rubia.auth.SecureActionForum) JSFUtil.getPoster(it.vige.rubia.ui.JSFUtil.getPoster) Poster(it.vige.rubia.model.Poster) PortalUtil.createPoll(it.vige.rubia.PortalUtil.createPoll) Poll(it.vige.rubia.model.Poll) PollOption(it.vige.rubia.model.PollOption) PortalUtil.createPollOption(it.vige.rubia.PortalUtil.createPollOption) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Example 15 with Interceptors

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;
}
Also used : Topic(it.vige.rubia.model.Topic) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException) Interceptors(javax.interceptor.Interceptors) SecureActionForum(it.vige.rubia.auth.SecureActionForum)

Aggregations

Interceptors (javax.interceptor.Interceptors)27 SecureActionForum (it.vige.rubia.auth.SecureActionForum)21 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)17 Topic (it.vige.rubia.model.Topic)13 ModuleException (it.vige.rubia.ModuleException)9 Post (it.vige.rubia.model.Post)6 Forum (it.vige.rubia.model.Forum)5 IUserRoleInterceptor (eu.europa.ec.fisheries.uvms.activity.rest.IUserRoleInterceptor)4 PollOption (it.vige.rubia.model.PollOption)4 ViewTopic (it.vige.rubia.ui.view.ViewTopic)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Poll (it.vige.rubia.model.Poll)3 Poster (it.vige.rubia.model.Poster)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Dataset (eu.europa.ec.fisheries.wsdl.user.types.Dataset)2 PortalUtil.createMessage (it.vige.rubia.PortalUtil.createMessage)2