Thursday, August 4, 2011

[WSO2 GREG] How to deploy WSO2-greg-4.0.0 on WebLogic


Here, I have used WSO2-greg-4.0.0, WebLogic 11g and JDK 1.6 to explain about the "How to deploy the WSO2-greg-4.0.0 on WebLogic".

The subtopics of the above  subject are  as follows:

1) How to create a domain in WebLogic.
2) Create a war file from WSO2-greg-4.0.0.
3) How to configure the greg repository.
4) How to configure the newly created domain.
5) Deploy the greg web app archive file (war file) on WebLogic.

How to create a domain in WebLogic.

You can follow the steps which I have mentioned in CreateNewDomain.pdf to create a new domain.

Create a war file from WSO2-greg-4.0.0.

I) Create a directory in your system (we named it as WAR_DIR) and copy the WEB-INF directory which is under wso2greg-4.0.0/lib/core  to  WAR_DIR.

II) If you want to enable the carbon logging in WebLogic , copy the log4j.properties file which is under wso2greg-4.0.0/lib to the WAR_DIR/WEB-INF/class directory.

III) Copy all the libraries under wso2greg-4.0.0/lib/api to the WAR_DIR/WEB-INF/lib.

You can do the above three steps using an ant task (executing ant createWAR). You only need to run that command from wso2greg-4.0.0/bin. After executing that command relevant WEB-INF directory will be created in directory under wso2greg-4.0.0/tmp/wso2 .

iv) Navigate your command shell to WAR_DIR directory and execute the following command to create the web app archive file.
jar -cvf ./greg.war ./* 

How to configure the greg repository.

I) You need to create a new directory in your file system(we named it as greg-repo) and it will be the repository in our deployment.

II) Copy the repository which is under wso2greg-4.0.0 to the greg-repo.

III) Now, you need to configure the carbon.xml, axis2.xml, registry.xml, and user-mgt.xml.
(You can find those files under wso2greg-4.0.0/repository/conf directory)

Open the carbon.xml and changed the values of the  ServerURL and  WebContextRoot.
<serverurl>https://localhost:7002/greg/services/</serverurl>  
<webcontextroot>/greg</webcontextroot> 
Open the axis2.xml and change the http and https ports according to WebLogic settings.
<transportreceiver class="org.wso2.carbon.core.transports.http.HttpTransportListener" name="http">  
        
<parameter name="port">7001</parameter>  
   
</transportreceiver>
<transportreceiver class="org.wso2.carbon.core.transports.http.HttpsTransportListener" name="https">  
   
<parameter name="port">7002</parameter>  
  
</transportreceiver>

Open the registry.xml and change the database URL of data base configuration as follows.
You need to add the absolute path of WSO2CARBON_DB as the database url.

<url>jdbc:h2:/home/ajith/greg-repo/repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE</url>
Open the user-mgt.xml and change the value of the database url property.
(Keep remember to add the absolute path of WSO2CARBON_DB as the url).
<property name="url">jdbc:h2:/home/ajith/greg-repo/repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE</property>

Deploy the greg web app archive file (greg.war file) on WebLogic.

Copy xalan-*.jar, xercesImpl-*.jar and xml-apis-*.jar from  wso2greg-4.0.0/lib/endorsed to the ext directory of your JDK installation. (/home/ajith/programes/jdk1.6.0_26/jre/lib/ext)

I) Open a new command shell and set the CARBON_HOME environment variable. (Linux : export
CARBON_HOME=/home/ajith/greg-repo ,
Windows: set CARBON_HOME=/home/ajith/greg-repo)

II) Locate your command shell to the bin (Oracle/Middleware/user_projects/domains/greg_domain/bin) directory of your domain and execute the startWebLogic command. (in linux sh startWebLogic.sh)

III) After successfully started the WebLogic server locate your browser  to the http://localhost:7001/console and login using the credentials which you have entered during the domain creation.

IV) After login to AdminiServer Console , navigate your browser to Home>Summary of Environment> Summary of Servers >AdminServer and select the Keystores tab.
And also change the Keystores: to “Custom Identity and Custom Trust” and save it.


V) Enter the following values to the relevant fields of the  keystores configuration. 

Identity section.

Custom Identity Keystore: /home/ajith/greg-repo/repository/resources/security/wso2carbon.jks  
Custom Identity Keystore Type: JKS  
Custom Identity Keystore Passphrase: wso2carbon  
Confirm Custom Identity Keystore Passphrase: wso2carbon
Trust section.
Custom Trust Keystore: wso2carbon  
Custom Trust Keystore Type: JKS  
Custom Trust Keystore Passphrase: wso2crbon  
Confirm Custom Trust Keystore Passphrase: wso2carbon  

VI) Click on the SSL tab on WebLogic AdminServer console and enter the following values for the relevant fields.

Private Key Alias: wso2carbon  
Private Key Passphrase: wso2carbon  
Confirm Private Key Passphrase: wso2carbon

VII) Navigate the AdminServer console to the deployment section and start to install the greg.war file clicking on the “install” button.

VIII) Browse the directory which is contain the greg.war. Then go forward with default configurations until the installation is complete.

IX) After finishing the installation , you should see the greg.war deployment on your command shell.
X) After successfully started the WSO2-greg-4.0.0 server , locate your browser to https://localhost:7002/greg/carbon on your favorite browser and login using the default user name(admin) and password(admin).  

Thursday, February 24, 2011

How to write a custom JSP tag ?

JSP tag is a very useful syntax of JSP. Using this syntax  we can define some operations.
When the JSP's executing the web container will invoke those operations.
JSP tags will help us to remove bulk codes from JSP files (Java and JavaScript ,..).
The most important thing is the tag re-usability.

JSP tag should have a start tag , end tag and tag body is optional.
Eg
<somename:tag>  
   ---------  
     body  
   ---------  
 </somename:tag> 

If you want to use some UI part repeatedly in your project, without duplicating the code you can define your own tag.

If you want to write your own tag (custom tag) then you have to do two things.

1) Write a Java class to define the functionality of tag.

2) Write TLD file, which will describe the above Java class and how your tag will be called.

Creating the TLD file

Later we will call this file as a sample.tld (extension should be .tld).
You need to include this TAG file(sample.tld) to WEB-INf directory or it's subdirectory of your project.
<!--?xml version="1.0" encoding="ISO-8859-1" ?-->  
<taglib>  
    <tlibversion>1.1</tlibversion>  
    <jspversion>1.1</jspversion>  
    <shortname>mt</shortname>  
    <uri>http://myproject/taglibs.jar</uri>  
    <info>Sample tag library</info>  
  
     <tag>  
        <name>report</name>  
        <!--Full qualified class name-->     
        <tagclass>sample.ui.taglibs.Report</tagclass>   
        <bodycontent>JSP</bodycontent>  
        <info>A tag for displaying reporting ui</info>  
        <!--You can define any number of attribute -->  
         <!--according to your need -->  
        <attribute>  
            <name>pdfReport</name>  
            <required>true</required>  
            <rtexprvalue>true</rtexprvalue>  
        </attribute>  
  
        <attribute>  
            <name>htmlReport</name>  
            <required>true</required>  
            <rtexprvalue>true</rtexprvalue>  
        </attribute>  
  
        <attribute>  
            <name>excelReport</name>  
            <required>true</required>  
            <rtexprvalue>true</rtexprvalue>  
        </attribute>              
    </tag>  
</taglib> 

    Creating the Java Class

You need to write a java class extending the BodyTagSupport class.
/** 
 * used to generate reporting UI 
 */  
public class Report extends BodyTagSupport {  
  
 private boolean pdfReport;  
 private boolean htmlReport;  
 private boolean excelReport;  
  
 public boolean isPdfReport() {  
    return pdfReport;  
 }  
  
 public void setPdfReport(boolean pdfReport) {  
    this.pdfReport = pdfReport;  
 }  
  
 public boolean isHtmlReport() {  
    return htmlReport;  
 }  
  
 public void setHtmlReport(boolean htmlReport) {  
    this.htmlReport = htmlReport;  
 }  
  
 public boolean isExcelReport() {  
    return excelReport;  
 }  
  
 public void setExcelReport(boolean excelReport) {  
    this.excelReport = excelReport;  
 }  
  
  
 public int doStartTag() throws JspException {  
          
  JspWriter writer = pageContext.getOut();  
        String context = "<div>";  
  
        if (pdfReport) {  
            context = context + "<a style="background-image:url(../admin/images/pdficon.gif);">Generate Pdf Report</a>";  
        }  
        if (htmlReport) {  
            context = context + "<a style="background-image:url(../admin/images/htmlicon.gif);">Generate Html Report</a>";  
        }  
        if (excelReport) {  
            context = context + "<a style="background-image:url(../admin/images/excelicon.gif);">Generate Excel Report</a>";  
        }  
        context = context + "</div>";  
  
        try {  
            writer.write(context);  
        } catch (IOException e) {  
  
          String msg = "Cannot write reporting tag content";  
            throw new JspException(msg, e);  
        }  
        return EVAL_PAGE;  
    }  
}  
Now you have to include following line in your JSP before use this custom tag.
<%@ taglib uri="http://myproject/taglibs.jar" prefix="carbon" %>
Now you can use new custom tag in your JSP like this.
Finally reporting UI generate like this.
Let's say if you want to add only PDF icon, then you can call custom tag like this
without changing Java code , JavaScript code, or HTML.
<carbon:report pdfreport="true" htmlreport="false" excelreport="false">  
</carbon:report>