Thursday, December 1, 2011

Get application url using java

/*
If your domain name is http://jijo84.blogspot.com/.
You will get http://jijo84.blogspot.com/ in your application using the following code.
If you are using struts action class, servlet or jsp  , you can use the following code.

*/

import java.net.URL;

public ActionForward checkUrl(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
URL applicationUrl = new URL(request.getScheme(), request.getServerName(), request.getServerPort(),
                        request.getContextPath());
system.out.println(applicationUrl.toString());
return mapping.findForward("success");
}




Saturday, November 19, 2011

Stop the continuous logging in Jboss console log except error

 To stop all logs except error,please
put the below elements in jboss-logging.xml in the deploy folder of Jboss to stop the continuous logging in Jboss console.
 
   <logger category="org.directwebremoting">
      <level name="ERROR"/>
   </logger>
   <logger category="org.apache.mina.filter.logging">
      <level name="ERROR"/>
   </logger>

Thursday, September 29, 2011

Calendar to XMLGregorianCalendar and vice versa

package com.jijo;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Calendar;

 public class DateUtil{

    public    static XMLGregorianCalendar toXMLCalendar(Calendar calandar ){
        XMLGregorianCalendar xmlCalendar =    null;
        try {
            DatatypeFactory dtf = DatatypeFactory.newInstance();
            xmlCalendar = dtf.newXMLGregorianCalendar();
            xmlCalendar.setYear(calandar.get(Calendar.YEAR));
            xmlCalendar.setDay(calandar.get(Calendar.DAY_OF_MONTH));
            xmlCalendar.setMonth(calandar.get(Calendar.MONTH)+ 1);
            xmlCalendar.setHour(calandar.get(Calendar.HOUR_OF_DAY));
            xmlCalendar.setMinute(calandar.get(Calendar.    MINUTE));
            xmlCalendar.setSecond(calandar.get(Calendar.    SECOND));
            xmlCalendar.setMillisecond(calandar.get(Calendar.MILLISECOND));
            int offsetInMinutes = (calandar.get(Calendar.ZONE_OFFSET) + calandar.get(Calendar.DST_OFFSET)) / (60 * 1000);
            xmlCalendar.setTimezone(offsetInMinutes);

        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return    xmlCalendar;

    }
public static Calendar toCalendar(XMLGregorianCalendar xmlCalendar ){
  return xmlCalendar.toGregorianCalendar();
 }

}

Friday, June 24, 2011

Setting CLOB in Hibernate annotation

Setting CLOB in Hibernate annotation

@Lob @Basic(fetch=FetchType.EAGER)
@Column(name = "news")      
   private String news;

Wednesday, June 22, 2011

Specify username, password and timeout in jboss webservice client

Specify the username, password and timeout ,in a jboss web service client.


In your generated client class , getting Soap instance method ,
eg:


public TESTGenericDataAccessSoap getTESTGenericDataAccessSoap(){
{
TESTGenericDataAccessSoap soap = super.getPort(TESTGenericDataAccessSoap , TESTGenericDataAccessSoap .class);
        BindingProvider bp = (BindingProvider)soap;
         Stub stub = (Stub)soap;
         stub._setProperty(StubExt.PROPERTY_CLIENT_TIMEOUT, 10); //Time out
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jijo");//Username
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jijo");//Password
        return soap;
}

The import classes are given,

import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.Stub;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service;
import org.jboss.ws.core.StubExt;

Friday, June 10, 2011

Div is going behind the SWF

When the div is going behind the SWF, give the following paramter 

<param name="wmode" value="transparent" />
eg:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="Test" width="100%" height="100%"
            codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
            <param name="movie" value="Test.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#869ca7" />
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="wmode" value="transparent" />
            <embed src="Test.swf" quality="high" bgcolor="#869ca7"
                width="100%" height="100%" name="Test" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                wmode="transparent"
                type="application/x-shockwave-flash"
                pluginspage="http://www.adobe.com/go/getflashplayer">
            </embed>
    </object>

Sunday, May 29, 2011

Change SVN password or remove stored passord from SVN eclipse plugin

In windows;
remove the following folder
C:\Documents and Settings\…..\Application Data\Subversion\auth\
eg: C:\Documents and Settings\jijo\Application Data\Subversion\auth 
Some times 'Application Data' is hidden.Please enable 'show hidden files' in file system.

Then Remove the auth folder.
In the auth folder you can find the following folders,
svn.simple
svn.ssl.client-passphrase
svn.ssl.server
svn.username


In linux :
~/.subversion/auth
This folder is hidden.Please enable the 'show hidden files'  in file system.Then remove the auth folder.

After the next saving from eclipse to SVN , password option will come.

NB: If you are not found the above path, search the auth folder,and check whether is SVN related and then remove that folder.
 







Thursday, February 24, 2011

increment a value using jstl c tag

<c:set var="numberOfRows" value="0"/><c:set var="numberOfRows" value="${numberOfRows+1}"/>
<c:out value="${numberOfRows}"/>

Wednesday, February 16, 2011

Read data from file using apache commons.io

package com.jijo;
import org.apache.commons.io.FileUtils;
import java.io.File;
//use commons-io-1.3.2.jar 
//download the above jar and include that in your class path.

class FileTest{

public String getFileData(String fileName){ //eg: c:/jijo/test.txt
String xmlData = null;
File file = new File(fileName);
        try{
        xmlData = FileUtils.readFileToString(file);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
return xmlData;
}

}

Code Complete: A Practical Handbook of Software Construction

Visualage for Java Enterprise Edition