Skip to main content

Posts

Deploy Ant project in Tomcat using Jenkins

Setup Ant in Jenkins: 1. Download the Ant Binary Distribution from its official site . 2. Unzip the downloaded Ant file. 3. Go to Manage Jenkins  and click on   Configure System 4. Scroll down and Go to Ant Installation and click Add Ant. 5. Uncheck the Install Automatically , another wise it will download the Ant online, After unchecking the Install Automatically it will show textfield for ANT_HOME. 6. You can specify Ant Name any name that you want to use for referering the particular Ant, And in ANT_HOME you need to specify the location for Ant where the Extracted Ant is available. 7. After that apply and save the changes. Install Tomcat Deployment plugin in Jenkins: 1. Go to Manage Jenkins  and click on Manage Plugin 2. Open Available tab and Select   Deploy To Container plugin and Install it using Install without Restart. 3. After that is Start the installation  and redirect you to Installing Plugins/Upgrades page. 4. Now select the Restar
Recent posts

Setup Jenkins in Tomcat Webserver

Jenkins is a software that allows continuous integration. Jenkins will be installed on a server where the central build will take place. System Requirements: 1. JDK 2. Tomcat Java installation : 1. Download the latest JDK from Oracle's site 2. CentOS look for the package jdk-7u17-linux-x64.rpm (64-bit architecture) or jdk-7u17-linux-i586.rpm (32-bit architecture) 3. Once you download the installation package, use the command rpm -ivh 4. Confirm you have the correct Java by running java -version Tomcat installation: 1. Download Apache Tomcat archive file from Apache Tomcat official download page. You can use below wget command to download it. cd /tmp wget http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz 2. After competed download extract archive file in /tmp directory and move to proper location as per your need. We are placing this under /usr/local directory. tar xzf apache-tomcat-7.0.54.tar.gz mv apache-t

Restful WADL WebService that serves the XML

In this tutorial, I am showing you how to develop a simple  RESTFUL web application that serves the XML request and response Jar files required : cxf-bundle-2.7.3.jar httpasyncclient-4.0-beta3.jar httpclient-4.2.1.jar httpcore-4.2.2.jar httpcore-nio-4.2.2.jar javax.ws.rs-api-2.0-m10.jar jaxb-impl-1.0.6.jar jettison-1.3.3.jar neethi-3.0.2.jar org-apache-commons-logging.jar xmlschema-core-2.0.jar 1. Creating a simple Bean class package com.student; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement (name = "Student" ) public class Student {   private String name ;   public String getName() {     return name ;   }   public void setName(String name ) {     this . name = name ;   } } 2.  Create a Web Service Endpoint Interface package com.student; public interface ChangeStudentDetails {   Student changeName(Student student );   Student getName(); } 3.

Change Tomcat JSESSION Cookie Name and Path

Sometime we have a scenario that two different tomcat application running on same domain,  and you want to share a session cookie in between them, there are two problem will come in this scenario i.e: 1. Session Cookie Name : As both the application have same cookie name i.e JSESSIONID , so its difficult to know which JSESSIONID belongs to which application , so in this scenario we need to change the Session cookie name. 2. Cookie Path :  By default tomcat create a session cookie for the app context, due to which we can't share the cookies between two application , so we need to change the cookie path from  context to the root. For doing the above point we can use  ServletContextListener or   web.xml file. 1. ServletContextListener import javax.servlet.SessionCookieConfig; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class MyTestListener implements ServletContextListener  {     public void contextInit

Forwarding Domain name in Tomcat from Apache proxy

When we do the apache proxy integration with the tomcat like in my another blog Apache and Tomcat Integration  we use the localhost mapping in the httpd config for the tomcat url , the main reason behind this is securing the tomcat so that it is not able to accessable from the outside world or using the domain, every request for tomcat need to be pass away from the apache. ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ Now using this approach main problem that occur is  tomcat doesn't aware about the domain name on which he is running, So when we want to redirect to another page from tomcat using response.sendRedirect() then it redirect the request using the localhost instead of domain name and link failure is occurred. So Now how to handle this situation, In apache we have a feature to carry forward the domain name in the tomcat using the Proxy. for doing this you need to open the httpd.conf file located in /etc/httpd/conf/ and replace

Encode from JavaScript and Decode at Java.

if you have a senerio like you want to send encoded parameter values from your web page  and decode them  at server side then this blog may be help you. JavaScript: Before submit the form I am encoding all the value entered by user so that it can not be read by humanly, for encoding the values I have written a method named  encodeBase64 <script> function encodeBase64(input){         var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";         input = escape(input);         var output = "";         var chr1, chr2, chr3 = "";         var enc1, enc2, enc3, enc4 = "";         var i = 0;              do {             chr1 = input.charCodeAt(i++);             chr2 = input.charCodeAt(i++);             chr3 = input.charCodeAt(i++);                      enc1 = chr1 >> 2;             enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);             enc3 = ((chr2 & 15) << 2

Apache CXF client : Log XML request and response in database

Sometimes we have a senerio in which we need to log the request and response in DB or some where else,  in order to see what request is sent to web service and what response we get.  Apache CXF API provides us the facility to achieve this via using Interceptor (LoggingOutInterceptor and LoggingInInterceptor), by default these classes write the request and response in the System.out stream,  Now if you want to store them to DB then you can't use this stream you must need data in some string variable ,  Therfore we need to change the write stream of Interceptor so that we can keep request and response in some string variable. String wsdlURL= "http://localhost:8084/MytestApp/artworkService"; JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  //Bind Service class factory.setServiceClass(MyService.class); //Bind WSDL       factory.setAddress(wsdlURL);                               //Change logging strean Writer outResult = ne