Merry Christmas to you also Rajender.

The eaisest is to inject the DomainList domainList in you mailet

Just declare as field

    @Resource(name = "dnsservice")
    private DomainList domainList;

and the mailet container will inject it for you (see also [1] for an example using a setter method).

That way, your mailet will benefit from any change in the domain list code and from any change in the configuration (can be xml, jpa... based).

Thx, Eric

[1] https://svn.apache.org/repos/asf/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractRecipientRewriteTable.java


On 25/12/2012 19:10, Rajender Vallapureddy wrote:
Hi Eric,

Merry Christmas to you :).

I am trying to read domains from the database from my custom matcher.

I have a written a helper class which is replica of
org.apache.james.domainlist.jpa.JPADomainList.java which has the below
method.

public List<String> getDomainListInternal() throws DomainListException {
                List<String> domains = new ArrayList<String>();

                EntityManager entityManager = entityManagerFactory
                                .createEntityManager();
                LOGGER.info("entity manager created.......");

                final EntityTransaction transaction = 
entityManager.getTransaction();
                try {
                        transaction.begin();
                        domains = 
entityManager.createNamedQuery("listDomainNames")
                                        .getResultList();
                        transaction.commit();
                } catch (PersistenceException e) {
                        getLogger().error("Failed to list domains", e);
                        if (transaction.isActive()) {
                                transaction.rollback();
                        }
                        throw new DomainListException("Unable to retrieve 
domains", e);
                } finally {
                        entityManager.close();
                }
                if (domains.size() == 0) {
                        return null;
                } else {
                        return new ArrayList<String>(domains);
                }


Now In my custom mailet class, I have called the above method, but I
am unable to retrieve the domains from the database table. Below is my
code from custom mailtet.


try{
                        domainsList = 
oTestJPADomainsList.getDomainListInternal();
                }catch (Exception exp)
                {
                        exp.printStackTrace();
                }
                if(domains != null && !domains.isEmpty()){
                        domains.clear();
                }
                
                if(domainsList != null && !domainsList.isEmpty()){
                        for(String aDomain : domainsList)
                        {
                                domains.add(aDomain);
                        }       
                } else {
                        LOGGER.error("Unable to read domains from JPA DOmains 
List...");
                        throw new Exception("No Domains Found");
                }

When I try to send an email I am getting throw the no domains found
exception (my custom exception).

Please can you guide in using the right api to read the domains from
the database source.

Regards,
Rajender

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to