1. #11
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Vote Rating
    1
    Answers
    2
    sachintaware is on a distinguished road

      0  

    Default


    Actually,the examples I have been going through have the same configuration and I am following them(Following some tutorials from websites)!!
    Please suggest a better alternative or the standard solution,so that I have a permanent solution.

    Thanks

  2. #12
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    The main point I'm trying to make is that you shouldn't be trying to manually load the application context XML file. This is automatically handled for you via the WEB-INF/web.xml configuration.

    I don't know at what point in your application you're doing it, but this piece of code is not needed and should be deleted:

    Code:
    ApplicationContext context = new FileSystemXmlApplicationContext("C:/Documents and Settings/Administrator/workspace/StaffingApplication/WebContent/WEB-INF/applicationContext.xml");

  3. #13
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Vote Rating
    1
    Answers
    2
    sachintaware is on a distinguished road

      0  

    Default


    Yes got your point friend.
    Actually,earlier I had configured my bean in the xml file.As posted before.
    And the the reason for using it there was I had the mailService object of the bean that I was using to call the MailService class' "sendMail" function.

    Code:
     ApplicationContext context = new FileSystemXmlApplicationContext("WEB-INF/applicationContext.xml");
     MailService mailService = (MailService) context.getBean("mailService");
     mailService.sendMail(from,toAddress,subject,mailBody);

    MailService class


    Code:
     @Service("mailService")
    public class MailService {
        
        @Autowired
        private MailSender mailSender;
        @Autowired
        private SimpleMailMessage alertMailMessage;
        
          
       public void sendMail(String from, String[] toAddress, String subject, String mailBody)throws MailException {
    ...
    ...
    }
    But now I have fixed it.
    Thanks for your continuous support.

  4. #14
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Vote Rating
    1
    Answers
    2
    sachintaware is on a distinguished road

      0  

    Default


    @friend
    but still I am not able to fix the original error,went through your files and I have not used Jackson
    but JSON Array and JSON Object(but that should not be the reason I suppose)
    And also,the Json is handled(i.e the list is retrieved from database) before even the mail is sent to the list.
    but the error comes when the mail is sent.

    Again i would like to highlight, I GET THIS IN FIREFOX (firebug)and NOT IN CHROME BROWSER.(In chrome I get the mail sent successfully message)
    Reproducing the error.
    Code:
    uncaught exception: [Exception... "'You're trying to decode an invalid JSON String: ' when calling method: [nsIDOMEventListener::handleEvent]"  nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"  location: "JS frame :: chrome://firebug/content/net/spy.js :: callPageHandler :: line 812"  data: no]
    http://localhost:9191/StaffingApplication/js/ext-all-debug.js
    
    Line 20820 :
       disableCache = options.disableCaching !== false ? (options.disableCaching || me.disableCaching) : false;      //This line is from ext-all-debug.js
    My Controller code:
    Code:
     @RequestMapping(value = "/email/view.action", method = RequestMethod.POST)
        public Object emailView(HttpServletRequest req,HttpServletResponse res) throws AddressException{
            
            /*********************Mail function*********************/                  
            
            String from="sachitaware21@gmail.com";
            String[] toAddress = (req.getParameter("to").split(","));
            
            InternetAddress[] addressTo = new InternetAddress[toAddress.length];
            for (int i = 0; i < toAddress.length; i++)
            {
                addressTo[i] = new javax.mail.internet.InternetAddress(toAddress[i]);        
            }
            String subject = req.getParameter("subject");
            String mailBody =req.getParameter("body");
            String firstName = (req.getParameter("firstName"));
            
            
            MailService mailService = new MailService();
            mailService.sendMail(from,toAddress,subject,mailBody);
            //mailService.sendAlertMail("Exception occurred");  
                  
            return null;    
            
        }
        //JSON to iterate over the results and send to the extjs view
    
    @SuppressWarnings("unchecked")
        private Map<String,Object> getMap(List<CandidateStatus> candidatestatus){
            
         //    Map<String,Object> modelMap = new HashMap<String,Object>(3);
        //    Map<String,Object> candDetails = new HashMap<String,Object>(7);
                
            Iterator<CandidateStatus> iterator=candidatestatus.iterator();
            CandidateStatus astring = new CandidateStatus();
            
            JSONArray jArray = new JSONArray();
            while(iterator.hasNext())
            {
                JSONObject candDetails    = new JSONObject();
                astring = iterator.next();
                                    
                candDetails.put("clientName",astring.getRequirement().getClient().getClientName());
                candDetails.put("firstName",astring.getCandidate().getFirstName());
                candDetails.put("lastName",astring.getCandidate().getLastName());
                candDetails.put("email",astring.getCandidate().getEmail());
                candDetails.put("phone",astring.getCandidate().getPhone());
                candDetails.put("statusTitle",astring.getStatusTitle());
                candDetails.put("reqTitle",astring.getRequirement().getReqTitle());
                
                 jArray.add(candDetails);
             }
            //System.out.println("----"+candDetails+"----");
                JSONObject modelMap = new JSONObject();
               modelMap.put("success",true);
                modelMap.put("totalCount",jArray.size());
                modelMap.put("data", jArray);     
                modelMap.toString();
            return modelMap;

    MailServce class


    Code:
    @Service("mailService")
    public class MailService {
        
        @Autowired
        private MailSender mailSender;
        @Autowired
        private SimpleMailMessage alertMailMessage;
        
          
        public void sendMail(String from, String[] toAddress, String subject, String mailBody)throws MailException {
            
                        /*************Get the username from session***************/
            
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            String username = auth.getName(); //get logged in username   
            
            System.out.println("----Username is-------"+username+"--------------");
        
            SimpleMailMessage message = new SimpleMailMessage();         
            message.setFrom(from);
            message.setTo(toAddress);
            message.setSubject(subject);
            message.setText(mailBody);
            
            Properties props = new Properties();
            JavaMailSenderImpl sender = new JavaMailSenderImpl();
            
            props.setProperty("mail.smtp.auth", "true");
            props.setProperty("mail.smtp.starttls.enable", "true");
            props.setProperty("mail.transport.protocol", "smtp");
            props.setProperty("mail.debug", "true");
            
            sender.setHost("smtp.gmail.com");
            sender.setPort(587);
                           
            if(username.equals("options")){
                 sender.setUsername("sachitaware21");
                 sender.setPassword("mypasswd");
                 sender.setJavaMailProperties(props);
                 
            }
            else if (username.equals("options1")){
                sender.setUsername("newastronsolutions");
                sender.setPassword("mypasswd");
                sender.setJavaMailProperties(props);          
            }     
            
            try {
                  sender.send(message);
                  // mailSender.send(message);
                }catch(MailException exception)
                {
                    //log the message and go on
                    System.err.println(exception.getMessage());
                }
                
            }
            
    }
    I am not using a bean to set the config as I have to change the Email Id based on the current logged in user.
    But not able to fix the firebug error I mentioned at the top.

    Thanks

  5. #15
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    I noticed that your Controller request mapping ('email/view.action') is returning a null and I don't see that your request handler is returning a ModelMap either. It looks like there's no JSON response to be decoded.

    I always return a JSON response from all request mappings, with a minimum of success: true.

    Last edited by friend; 16 May 2012 at 10:39 AM. Reason: grammar

  6. #16
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Vote Rating
    1
    Answers
    2
    sachintaware is on a distinguished road

      0  

    Default


    I have tried doing that earlier,but will think over it surely.Also,is it that Chrome and Mozilla behave differently over the same??

    Also,to add I am giving the error under the XML tab in the firebug console.

    Code:
    XML Parsing Error: no element found Location: moz-nullprincipal:{02e54f82-a834-4424-9a75-e6d1574fce98} Line Number 1, Column 1:
    Thanks

  7. #17
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Vote Rating
    27
    Answers
    106
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    It's really hard to debug a problem such as this without seeing the big picture.

    I'm thinking that a full, working example app with user authentication (login/logout), email functionality and the use of Spring MVC native JSON view handling would help you.

    It will take me a bit of time, but I'm willing to take a production app, strip it down to just user authentication and email functions (and maybe an innocuous CRUD page), zip up the Eclipse project, do a mysql dump on a test database and share these artifacts with you.

    I'll include a 'readme.txt' on importing the Eclipse project, importing the MySQL database and Tomcat JNDI datasource config via conf/context.xml. Seeing a working example will probably save us both a ton of forum posts. :]

    Again, It'll take a while to do this, but I'll send you a 'private message' via the forums when it's ready and provide a download link.

  8. #18
    Sencha User
    Join Date
    Nov 2011
    Posts
    149
    Vote Rating
    1
    Answers
    2
    sachintaware is on a distinguished road

      0  

    Default


    That would really do a WORLD of good!!!!!!
    You are a gem of a person.Will wait for that.

    And close the thread on that note!!!

    Thanks

Thread Participants: 2

Tags for this Thread