Sunday, September 9, 2012

Spring MVC with Ajax

Spring MVC with AJAX implementation using Jackson API and Jquery

The following jar files needed for this ,

commons-logging-1.1.1.jar
jackson-core-asl-1.4.0150249.jar
jackson-mapper-asl-1.4.3.jar

jstl-1.2.jar
spring-asm-3.0.3.RELEASE.jar
spring-beans-3.0.3.RELEASE.jar
spring-context-3.0.3.RELEASE.jar
spring-context-support-3.0.3.RELEASE.jar
spring-core-3.0.3.RELEASE.jar
spring-expression-3.0.3.RELEASE.jar
spring-web-3.0.3.RELEASE.jar
spring-webmvc-3.0.3.RELEASE.jar


Ajax implementation is based on 
 jackson-core-asl-1.4.0150249.jar and jackson-mapper-asl-1.4.3.jar

1) Added this jars in your classpath.

2) Add the following configuration in your context file,

<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
          <list>
            <ref bean="
jsonConverter"/>
          </list>
    </property>

</bean>

3) Controller Class(EmployeeController.java)

package com.jijo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EmployeeController {

     @RequestMapping(value = "/SaveEmploye.html", method = RequestMethod.POST)
        public @ResponseBody String saveEmployee(@RequestBody Employe employe) {
           if(employe != null){
               System.out.println("*****DATA IS NOT NULL*****: "+employe);
               for(Address address :employe.getAddresses()){
                   System.out.println("Employee Name:"+employe.getFirstName()+" \nHouseName:"+address.getHouseName());
               }
           }
           else{
               System.out.println("employe is null");
           }
            return "done";
        }
}



4) Employe.java

package com.jijo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Employe  implements Serializable{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String employeeId;
    private String firstName;
    private String lastName;
    private String department;
    private List<Address> addresses = new ArrayList<Address>();
    public String getEmployeeId() {
        return employeeId;
    }
    public void setEmployeeId(String employeeId) {
        this.employeeId = employeeId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getDepartment() {
        return department;
    }
    public void setDepartment(String department) {
        this.department = department;
    }
    public List<Address> getAddresses() {
        return addresses;
    }
    public void setAddresses(List<Address> addresses) {
        this.addresses = addresses;
    }
   
}




5) Addess.java
 


package com.jijo;

import java.io.Serializable;

public class Address implements Serializable{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private String houseName;
    private String place;
    private String district;
    private String state;
    private String country;
    private String postalCode;

    public String getHouseName() {
        return houseName;
    }

    public void setHouseName(String houseName) {
        this.houseName = houseName;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }
}



6) Javascript function




function saveEmploye(){
var addresses = [];
var employee = {"employeeId":"10","firstName":"John","lastName":"Smith","department":"IT"};
var address = 

{"houseName":"HouseNo-10",
"place":"PLACE1",
"district":"district1","state":"state1"};
addresses.push(address);
employee.addresses=addresses;

$.ajax({
    type: "post",
    url: "SaveEmploye.html", //your url
    contentType: "application/json",
    data: JSON.stringify(employee),
    success: function(result) {
        alert('Employee saved successfully');
    },
    error: function(){
        alert('
Error occured');
    }
});
}
 

 




Saturday, March 24, 2012

Authentication in Jboss webservice client

URL url = null;
url = new URL("file:/c:/test/test.wsdl");


    PRODGenericDataAccessSoap soap = super.getPort(PRODGenericDataAccessSoap, PRODGenericDataAccessSoap.class);
        BindingProvider bp = (BindingProvider)soap;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "jijo");

//username is jijo
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jijo"); 

//passowrd is jijo
        return soap; 


16:12:49,843 WARN  [org.apache.cxf.phase.PhaseInterceptorChain] Interceptor for {http://www.prodml.org/api/200/genericDataAccess}PROD_GenericDataAccess#{http://www.prodml.org/api/200/genericDataAccess}GetData has thrown exception, unwinding now: java.lang.RuntimeException: Can't find input stream in message
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:116) [:2.3.1]
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60) [:2.3.1]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255) [:2.3.1]
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:755) [:2.3.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2330) [:2.3.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2192) [:2.3.1]
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2036) [:2.3.1]
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) [:2.3.1]
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:696) [:2.3.1]
    at 16:12:51,765 ERROR [STDERR] javax.xml.ws.soap.SOAPFaultException: Can't find input stream in message


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}"/>