Pages

Hot News

Wednesday 5 August 2015

Email send in Liferay through JavaMail API?

Hi Guys,

Let's get a very brief idea about mail send in Liferay.

Email is an integral part of business communication.
Java offers the JavaMail API to make possible email communication from our applications easily.
It is a platform- and protocol-independent framework built as a part of the Java EE spectrum of web/enterprise application development.

The JavaMail API is a set of abstract classes defining the objects that comprise a mail system.

The Protocol of JavaMail

Protocol literally means maintaining certain norms, code of conduct, and so on.

Creating an application with email support is as simple as any Java programming, but the technical aspects behind the scene are quite intriguing and require some understanding of network protocols.

Let's get an idea of protocols supported by the JavaMail API.

SMTP - To supports the mechanism to deliver email.
POP - Mailbox mechanism use on the Internet to get mails.
IMAP - An advanced protocol for receiving messages, multiple mailbox support, mailbox sharing, and so forth.
MIME -It's concerned with the content of the message transfer such as message format, attachments, and so on.

 In liferay its pretty easy to do configuration.

1. GMAIL Configuration,

mail.session.mail.store.protocol=imap
mail.session.mail.transport.protocol=smtp

#smtp properties
mail.session.mail.smtp.host=smtp.gmail.com
mail.session.mail.smtp.password=_PASSWORD
mail.session.mail.smtp.user=_USEREMAILADDRESS

mail.session.mail.smtp.port=465
mail.session.mail.smtp.auth=true
mail.session.mail.smtp.starttls.enable=true
mail.session.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

mail.session.mail.smtp.socketFactory.fallback=false
mail.session.mail.smtp.socketFactory.port=465
# Other protocols mail.session.mail.imap.host=localhost
#mail.session.mail.pop3.host=localhost
#mail.session.mail.pop.host=smtp.gmail.com

2. Office 365 Configuration,

portal.host=_USEREMAILADDRESS
portal.password=_PASSWORD
mail.smtp.host=smtp.office365.com
mail.smtp.socketFactory.port=587
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.auth=true
mail.smtp.port=587
mail.smtp.starttls.enable=true

You can read these properties via portal-ext.properties in your class through PropsUtil.get() Method.

Please take note as,  I am showcase demo only for Office365 Mail.

Let's Create Utility class and define method.

MailSendHelper.java

public final class MailSendHelper {

private MailSendHelper(){}

public static void sendEmail(InternetAddress from,InternetAddress to, String subject, String bodyContent) {
final String userEmail = PropsUtil.get("portal.host");
final String password = PropsUtil.get("portal.password");
Session mailSession = null;
Properties props = new Properties();
props.put("mail.smtp.host","smtp.office365.com");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", true);
props.put("mail.smtp.ssl.trust", "smtp.office365.com");
props.put("mail.debug", true);

mailSession = Session.getInstance(props,
     new javax.mail.Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(userEmail ,password );
     }
});  try {
Message message = new MimeMessage(session);
message.setFrom(from);
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject(subject);
message.setContent(bodyContent, "text/html; charset=utf-8");
Transport.send(message);
LOG.info("DONE");
} catch (MessagingException e) {
LOG.error("Error occured in MailSendHelper",e);
}
}
private static final Log LOG = LogFactoryUtil.getLog(MailSendHelper.class);
}

JAVAMail API Download from this location: http://www.oracle.com/technetwork/java/javamail/javamail145-1904579.html

Hope this article will help you. :)



Monday 25 May 2015

EBS Payment integration with Liferay Portal

Hi Guys,

Today, I am going to represent and explain you how to integrate payment system in Liferay Portal

Please find the attached document and refer it. Then follow below instructions for EBS payment integration with Liferay Portal.

Step 1,

public class FLEBSIntegrationConstants {
public static final String ACTION_PAYMENT = "ebsPaymentResponse";
public static final String PAGE_PAYMENT = "/html/flebsintegration/pay.jsp";
public static final String PAGE_SUCCESS = "/html/flebsintegration/success.jsp";
public static final String PAGE_RESPONSE = "/html/flebsintegration/response.jsp";
public static final String RESPONSE = "response.jsp";
}

Step 2,

Create view.jsp in your portlet

This is the <b>Flebs Integration</b> portlet in View mode.
<portlet:renderURL var="ebsPaymentURL">
<portlet:param name="jspPage" value="<%=FLEBSIntegrationConstants.PAGE_PAYMENT %>" />
</portlet:renderURL>

<br />
<a href="${ebsPaymentURL}">Click Here for Payment &raquo;</a>

Step 3,
In controller class, Action Method of Pay.jsp
/*
* i. Credentials to test the payment
Card Number – 4111111111111111
Expiry – 07/16
CVV – 123
Bank – EBS

   ii.  Payment Request URL:
Test – https://testing.secure.ebs.in/pg/ma/sale/pay
Production – https://secure.ebs.in/pg/ma/sale/pay

or

Test – https://testing.secure.ebs.in/pg/ma/sale/vpc
Production – https://secure.ebs.in/pg/ma/sale/vpc

   iii. Merchant Login URL
Test – https://testing.secure.ebs.in
Production – https://secure.ebs.in

* API Request URL
* Test – https://testing.secure.ebs.in/api/1_0
* Production – https://secure.ebs.in/api/1_0
*/

public void ebsPaymentResponse(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
String DR = (String)actionRequest.getParameter("DR");
System.out.println("---------DR-----------" +DR);

/////
String key = "ebskey"; //Your Secret Key
StringBuffer data1 = new StringBuffer().append(DR);
for (int i=0; i < data1.length(); i++){
if(data1.charAt(i)== ' ')
data1.setCharAt(i,'+');
}
Base64 base64 = new Base64();
byte[] data = base64.decode(data1.toString());
RC4 rc4 = new RC4(key);
byte[] result = rc4.rc4(data);


ByteArrayInputStream byteIn = new ByteArrayInputStream (result, 0, result.length);
DataInputStream dataIn = new DataInputStream (byteIn);
String recvString1 = "";
String recvString = "";
recvString1 = dataIn.readLine();
int i =0;
while(recvString1 != null ){
i++;
if(i > 705) break;
recvString += recvString1 + "\n";
recvString1 = dataIn.readLine();
}
recvString  = recvString.replace( "=&","=--&" ) ;
System.out.println("--------RECVSTR---------" +recvString);
////
StringTokenizer st = new StringTokenizer(recvString, "=&");
String field ,val;
while(st.hasMoreTokens()) {
field = st.nextToken();

val = st.nextToken();

System.out.print(field+" :--->");
System.out.println(val);

}

PortalUtil.copyRequestParameters(actionRequest, actionResponse);
actionResponse.setRenderParameter("mvcPath", FLEBSIntegrationConstants.RESPONSE);

}

Step 4, response.jsp

hello, <%=request.getParameter("DR")%>



That's All !!
Let me know if u have any suggestions/queries, I would like to hear from your side.


Monday 28 April 2014

How to use Dialog Box (Popup) in Liferay 6.2?

Hi guys,

AlloyUI provide many components for different purposes. These components are very flexible and easy to use.

If you want to create/open DialogBox in liferay 6.2  then you can use the AlloyUI component. 

Lets see example.
  • create portlet.
  • Inside view.jsp put below code

Monday 21 April 2014

How to get string parameter from request when using enctype="multipart/form-data" ?

Hi guys,

Descriptions:

When [ <form> tag ] which has enctype="multipart/form-data"  and also contain additional input type="text" with name="username" and a submit button.

jsp:

<form action="upload" method="post" enctype="multipart/form-data">
User Name: <input type="text" name="username" /><br/>
<input type="file" name="file" />
<input type="submit" value="upload" />
</form>

retrieve string paramName as:
String username = request.getParameter("username"); 
That's prints NULL when form has enctype="multipart/form-data"  If I remove this attributes from the form tag then prints value input by user. 


Whenever a form has enctype="multipart/form-data" . You can not get other form fields by using request.getParameter("paramName");
It will always give you NULL value.

*This problem can be resolved by using below way.

Write the below code in your servlet and get the values of additional formfields :

   List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
   String inputName = null;
for(FileItem item : multiparts){
if(!item.isFormField()){   // Check regular field.
String name = new File(item.getName()).getName();
item.write( new File(UPLOAD_DIR + File.separator + name));
}
if(item.isFormField()){  // Check regular field.
inputName = (String)item.getFieldName(); 
if(inputName.equalsIgnoreCase("username")){ 
username = (String)item.getString(); 
        System.out.println("UserName is:"+username); 
}
}
}

That's All !!
Let me know if u have any suggestions/queries, I would like to hear from your side.


















Saturday 19 April 2014

Display Webcontent in JSP?

Hi guys,

There are many way to display webcontent in jsp.
Here, I am explaining  two easiest way.

First Way :
If you are thinking to display web content in JSP page, Its only 2 steps you follow as given below :


Step 1.

Put Below configuration in " portal-ext.properties " :

article.name=YourJournalArticleName
no.actical.text=No Article Exists with this name.

Step 2.
Put Below code inside your jsp.
JSP File : 

<%
String content = StringPool.BLANK;
try{ 
String articleName = PropsUtil.get("article.name");

JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);
String articleId = journalArticle.getArticleId(); 
JournalArticleDisplay articleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScoprGroupId(), articleId,"","",themeDisplay);
content = articleDisplay.getContent();
}Catch(Exception e){
content = PropsUtil.get("no.article.text");
}
%>

<%= content %>

*Note: In this way you required to restart server because we have updated portal-ext.properties file.

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

Alternate cool option to display webcontent in jsp as:

Follow the list of below steps.
Step 1:

Put below code inside your java class.
For retrieve the wecontentid  and  GroupId.

 long lGroupId = themeDisplay.getScopeGroupId();
String lGroupName = themeDisplay.getScopeGroupName();


JournalArticle jArticleId = JournalArticleLocalServiceUtil.getArticleByUrlTitle(

lGroupId, "webcontentname");

renderReq.setAttribute("lGroupId", lGroupId);
renderReq.setAttribute("jArticleId", jArticleId.getArticleId());

Step 2:

Put below code inside your jsp.


<liferay-ui:journal-article articleId="${jArticleId}"

groupId="${lGroupId}" />

*Note: If we are follow the above way then we don't required to restart the server.

That's all !!

Let me know if u have any suggestions/queries, I would like to hear from your side.

Thursday 17 April 2014

Cognos Integration with Liferay Portal.


There are two easiest way from which we can achieve this things.

1. IFrame
2. WSRP

1. IFrames:
  • This is one of the easier options
  • It is very useful when you have lots of things to expose or to display third party data.
  • It provides loose-coupling between Portal and Cognos so as reports change the Portal doesn't need to change
Implementation way:
  • The portlet will be accessible to logged in user only. Either This portlet has been developed as a custom portlet using Plugins-SDK or OOB Iframe portlet.
  • To display third party data in iframe so used iFrame to achieve this functionality. The information is being fetched by the web services.
  • Using Iframe in cognos-integration-portlet makes it possible to embed another HTML page inside the current page.  
  • Furthermore the user can navigate through the embedded page without loosing the context of the portal page.

The configurations for this portlet are stored in portlet.properties file under WEB-INF/src folder. Here is a reference of the same:

cognos.page.targeturl =
cognos.graphic.format=


2. WSRP:
  • You can expose cognos portlets running on a WebSphere server as a WSRP (Web Services for Remote Portlets) producer.
  • In your portal, you can consume the cognos portlets via the OOB WSRP portlet .
  • This provides a good level of decoupling because the Cognos portlets can run on a separate WAS server from your Portal server.

That's it!!:)

Sunday 2 September 2012

How To Execute Trigger in Liferay Databases?

A Trigger is a named database object which defines some action that the database should take when some databases related event occurs. Triggers are executed when you issues a data manipulation command like INSERT, DELETE, UPDATE on a table for which the trigger has been created. They are automatically executed and also transparent to the user. But for creating the trigger the user must have the CREATE TRIGGER privilege. In this section we will describe you about the syntax to create and drop the triggers and describe you some examples of how to use them.

How to create triggers ?

Syntax For Create :
CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_statement

Syntax of Drop TRIGGER is :
  DROP TRIGGER mycentral_user_trigger;

Syntax of show all TRIGGER is :
  select trigger_schema, trigger_name, action_statement from information_schema.triggers;

The trigger can associate only with the table name and that must be refer to a permanent table. Trigger_time means trigger action time. It can be BEFORE or AFTER. It is used to define that the trigger fires before or after the statement that executed it. Trigger_event specifies the statement that executes the trigger. The trigger_event can be any of the DML Statement : INSERT, UPDATE, DELETE.

We can not have the two trigger for a given table, which have the same trigger action time and event. For Instance : we cannot have two BEFORE INSERT triggers for same table. But we can have a BEFORE INSERT and BEFORE UPDATE trigger for a same table.

Trigger_statement have the statement that executes when the trigger fires but if you want to execute multiple statement the you have to use the BEGIN?END compound statement.

We can refer the columns of the table that associated with trigger by using the OLD and NEW keyword. OLD.column_name is used to refer the column of an existing row before it is deleted or updated and NEW.column_name is used to refer the column of a new row that is inserted or after updated existing row.

/----- errors display query ------/
show count(*) errors;
show errors;