Monday, April 23, 2018

Send email with Attachment JAVA MAIL

    
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;

import javax.mail.Transport;
import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;


import javax.mail.internet.MimeMultipart;


/**
     * @param to
     * @param cc
     * @param from
     * @param subject
     * @param text
     */
    public static void getUtilityWithAttachment(String to, String cc, String from, String subject, String text) {


        // Get system properties
        Properties properties = System.getProperties();

        // Setup mail server
        ResourceBundle rb = ResourceBundle.getBundle("com.incbidea.appName.view.bundles.AppUIBundle");
        String host = rb.getString("SMTP_HOST");

        properties.setProperty("mail.smtp.host", host);
        // properties.setProperty("mail.smtp.port", "25");
        // Get the default Session object.
        Session session = Session.getDefaultInstance(properties);

        try {
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);

            // Set From: header field of the header.
            message.setFrom(new InternetAddress(from));

            // Set To: header field of the header.
            // message.addRecipient(Message.RecipientType.TO, new InternetAddress.parse(to));

            if (to.indexOf(',') > 0)
                message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
            else
                message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));

            if (cc.indexOf(',') > 0)
                message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc));
            else
                message.setRecipient(Message.RecipientType.CC, new InternetAddress(cc));

            // Set Subject: header field
            message.setSubject(subject);


            // Create the message part
            BodyPart messageBodyPart = new MimeBodyPart();

            // Now set the actual message
          //messageBodyPart.setText(text);
            messageBodyPart.setContent(text, "text/html");
            // Create a multipar message
            Multipart multipart = new MimeMultipart();

            // Set text message part
            multipart.addBodyPart(messageBodyPart);

            // Part two is attachment
            messageBodyPart = new MimeBodyPart();
            String filename = "//home//app//USER-GUIDE.doc";
            DataSource source = new FileDataSource(filename);
            messageBodyPart.setDataHandler(new DataHandler(source));
            messageBodyPart.setFileName("NAME_USER-GUIDE.doc");
            multipart.addBodyPart(messageBodyPart);

            // Send the complete message parts
            message.setContent(multipart);


            // Now set the actual message
            //  message.setText(text);

            // Send message
            Transport.send(message);
            //System.out.println("Sent message successfully....");
        } catch (MessagingException e) {


            String messageText =
                "Warning/INFO : EMail works on the SB1/VMQ/PROD . Cannot be sent from local machine; The host is " +
                host + "";
            FacesMessage fm = new FacesMessage(messageText);

            fm.setSeverity(FacesMessage.SEVERITY_ERROR);
            FacesContext context = FacesContext.getCurrentInstance();

            context.addMessage(null, fm);
            e.printStackTrace();

        }
    }

Wednesday, April 11, 2018

How to change the Detached table window title ADF?









Reference: https://vtkrishn.com/2010/07/28/how-to-change-the-default-text-title-of-detached-tabletreetable/
https://technology.amis.nl/2010/07/26/adf-11g-skinning-three-ways-to-change-look-and-feel/



Thursday, March 29, 2018

weblogic.application.ModuleException: java.lang.ClassNotFoundException: oracle.adf.model.servlet.ADFBindingFilter

Add missing library ADF Web Runtime library to WAR Deployment profile - > WEB-INF/lib -> Contributors

Reference: https://www.albinsblog.com/2012/08/problem-while-deploying-adf-application.html#.Wr0paS7wbRY

weblogic.application.ModuleException: java.lang.ClassNotFoundException: oracle.bc4j.mbean.BC4JConfigLifeCycleCallBack

Add missing library BC4J Runtime library to WAR Deployment profile - > WEB-INF/lib -> Contributors

Reference: http://www.catgovind.com/adf/adf-deployement-error-classnotfoundexception-oracle-bc4j-mbean-bc4jconfiglifecyclecallback/


Monday, March 19, 2018

BEA-160187 weblogic.appc failed to compile the application

Issue when using JDeveloper 12.1.3 on Windows 10 machine:




Resolution:


  • Use JDK7 instead of JDK6 for JDeveloper 
  • 12.1.3 supports Java7 on Windows10

Thursday, January 18, 2018

Python script to parse attribute names of XML file

------------------------------------------------------------------------------------

import xml.etree.ElementTree as ET
import csv

tree = ET.parse("ResidentData.xml")
root = tree.getroot()

# open a file for writing

Resident_data = open('/tmp/ResidentData.csv', 'w')

# create the csv writer object

csvwriter = csv.writer(Resident_data)
resident_head = []

count = 0
for member in root.findall('Resident'):
resident = []

name = member.get('name_value')
resident.append(name)
csvwriter.writerow(resident)

Resident_data.close()




______________________________________________________________________________________
XML
_________________________________________________________________

<State>
<Resident Id="100">
<Name name_value="Name123">Sample Name</Name>
<PhoneNumber name_value="Phone123">1234567891</PhoneNumber>
<EmailAddress name_value="Email123">sample_name@example.com</EmailAddress>

</Resident>
<Resident Id="101">
<Name name_value="12name1234">Sample Name1</Name>
<PhoneNumber name_value="12Phone1234">1234567891</PhoneNumber>
<EmailAddress name_value="12Email1234">sample_name1@example.com</EmailAddress>

</Resident>
</State>



________________________________________________________________________________
Sample Output
________________________________________________________________________________

Name123
12name1234



Reference:

https://docs.python.org/2/library/xml.etree.elementtree.html

http://blog.appliedinformaticsinc.com/how-to-parse-and-convert-xml-to-csv-using-python/