Wednesday, December 29, 2010

Tomcat load balancer using mod_proxy_balancer

/etc/init.d/apache2 stop
sudo a2ensite mynewsite
sudo /etc/init.d/apache2 restart
a2dissite utility to disable sites
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp



NameVirtualHost *:80
<VirtualHost *:80>
    ServerName localhost
    UseCanonicalName On
    ServerAdmin harshal.shah@asurion.com
    Alias /healthcheck /var/www
     DocumentRoot /home/localadmin/liferay

    <Directory "/">
          Options FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all
          ProxyPass ajp://localhost:8009/
     </Directory>
     CustomLog /liferay.log combined
     Options +FollowSymlinks
</VirtualHost>
Enable modules  and configuration in the 

NameVirtualHost *:80
<VirtualHost *:80>
 ServerName ubuntu
 DocumentRoot /home/localadmin/
 ProxyRequests Off

 <Proxy *>
 Order deny,allow
 Allow from all
 </Proxy>

 ProxyPass /balancer-manager !
 ProxyPass / balancer://mycluster/ stickysession=JSESSIONID nofailover=On
 ProxyPassReverse / http://localhost:8081/
 ProxyPassReverse / http://localhost:8082/
 ProxyPassReverse / http://localhost:8083/

 <Proxy balancer://mycluster>
# BalancerMember http://localhost:8081  route=a1
# BalancerMember http://localhost:8082  route=a
  BalancerMember ajp://localhost:8109 route=a1
  BalancerMember ajp://localhost:8209 route=a2
  BalancerMember ajp://localhost:8309 route=a3
  ProxySet lbmethod=byrequests
 </Proxy>

 <Location /balancer-manager>
 SetHandler balancer-manager
 Order deny,allow
 Allow from all
 </Location>

</VirtualHost>

using http://ubuntu/balancer-manager

Enable proxy in proxy.conf in mods enabled.

<IfModule mod_proxy.c>
        #turning ProxyRequests on and allowing proxying from all may allow
        #spammers to use your proxy to send email.

        ProxyRequests Off

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                Deny from none
                #Allow from .example.com
        </Proxy>

        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: he$
        # Set to one of: Off | On | Full | Block

        ProxyVia On
</IfModule>
To get PHP to run alongside Liferay and Tomcat is a simple matter of modifying the liferay.conf file. Here's how you do it:
ssh into the server.
cd /var/www/
sudo mkdir directory name
sudo nano (or vim if you prefer) index.php
Enter this into the text editor.
<?php
        echo "Hello World!";
?>
cd /etc/apache2/sites-enabled/
sudo nano (or vim if that's your preference) 000-default
Make sure the first item on the page looks like this...
NameVirtualHost *:80
Make sure the <VirtualHost> directive looks like this...
<VirtualHost *:80>
Save and exit the file.
sudo nano liferay.conf
Make sure the <VirtualHosts> directive looks like this...
<VirtualHost *:80>
Add an alias inside the <VirtualHost> tag.
Alias /apps "/var/www/apps"
Add a <Directory> directive inside the <VirtualHost> tag. It should look like this...
<Directory "/apps/">
      Options FollowSymLinks
      AllowOverride None
      Order allow,deny
      Allow from all
      ProxyPass [http://localhost:80/apps/]

</Directory>
Save and exit the file.
Restart the server
/etc/init.d/apache2 restart
Test to see if it's working by navigating to the root URL of the server. You should be taken to Liferay. Then navigate to the siteurl/apps/ and you should see a blank page that says "Hello World".

Restful webservices with Eclipse

Java file place it in the same package

package name.brucephillips.hellows.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;

/**
 * Defines a RESTful web service
 * that can be called by using
 * the URI /hello
 *
 * @author Bruce Phillips
 *
 */
@Path("/hello")
public class HelloResource {

    /**
     * Processes HTTP get requests
     * that have no parameters
     * for example /hello
     * @return "Hello"
     */
    @GET
    @Produces("text/plain")
    public String getMessage() {
       
        // Return plain text
        return "Hello";
       
    }//end method getMessage
   
    /**
     * Processes HTTP get requests
     * that have a username parameter
     * for example /hello/Bruce
     * @param userName
     * @return "Hello {userName}"
     */
    @GET
    @Path("{username}")
    @Produces("text/plain")
    public String getMessage(@PathParam("username") String userName) {
       
        return "Hello " + userName;
       
    }//end overloaded method getMessage
   
    /**
     * Processes HTTP post requests
     * that have sent a form parameter
     * named name
     * @param name
     * @return "Hello {name}"
     */
    @POST
    @Consumes("application/x-www-form-urlencoded")
    @Produces("text/plain")
    public String postMessage(@FormParam("name") String name) {
        System.out.println("In here");
        return "Hello " + name;
       
    }//end method postMessage
  
   
   
}//end class HelloResource




web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>helloWS</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>name.brucephillips.hellows.resources</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

index.jsp
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Hello Home Page</title>
</head>
<body>
<h3>Example RESTful Web Service</h3>

<p>Click on a link to call one of the helloWS methods and view the response.</p>

<p><a href="services/hello">Plain Hello</a></p>

<p><a href="services/hello/Bruce">Hello Bruce</a></p>

<p>Enter your name and click the button to get a personal hello.</p>

<form method="post" action="services/hello">

<p>Name: <input type="text" name="name" /></p>

<p><input type="submit" name="submit" value="Submit" /></p>

</form>

<h3>References</h3>

<ol>
<li><a href="http://wikis.sun.com/display/Jersey/Main" target="_blank">Jersey: RESTful Web services made easy</a></li>
<li><a href="http://docs.sun.com/app/docs/doc/820-4867/6nga7f5mk?l=en&a=view" target="_blank">RESTful Web Services Developer's Guide</a></li>
<li><a href="https://jsr311.dev.java.net/nonav/releases/1.0/index.html?overview-summary.html" target="_blank">jsr311-api 1.0 API</a></li>
<li><a href="http://lqd.hybird.org/journal/?p=123" target="_blank">Hacking Jersey/JAX-RS to run RESTful web services on Google AppEngine/Java</a></li>
<li><a href="http://www.brucephillips.name/restful/helloWS.zip" target="_blank">Zipped Eclipse Maven Project</a></li>
</ol>


</body>
</html>


Add the jar files

asm-3.1.jar
jersey-core-1.1.0-ea.jar
jersey-server-1.1.0-ea.jar
jsr311-api-1.1.jar

Make sure the jar version are the same....



In this article I would like to describe how to get your RESTful webservice to output XML. RESTful doesnt output as much detail as the SOAP specification, but it gives you enough data to work with, assuming you know what the data types are.
Firstly, create a class that represents your output. Remember the import!
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class userData {
    public String firstname;
    public String lastname;
    public String idnumber;
    public String pin;
    public int status;
}
Then we can start coding the webservice. I’m not going to go into detail, but am just going to put in the specifics that are relevant for this article
import java.util.ArrayList;
import java.util.List;
 
@Path("airtime_functions")
public class airtime {
    @GET
    @Path("get_users")
    @Produces("application/xml")
    public List<userData> get_users(@QueryParam("user_id") String user_id)
    {
        List<userData> retUser = new ArrayList<userData>();
        try
        {
            errorMsg = "";
            con = getJNDIConnection();
            stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            String sql = "SELECT * from users where user_id = ?";
            PreparedStatement prest = con.prepareStatement(sql);
            prest.setString(1, user_id);
            prest.execute();
            rs = prest.getResultSet();
            while (rs.next())
            {
                userData toReturn = new userData();
                toReturn.firstname = rs.getString("firstname");
                toReturn.idnumber = rs.getString("idnumber");
                toReturn.lastname = rs.getString("surname");
                toReturn.pin = rs.getString("pin");
                toReturn.status = rs.getInt("status");
                retUser.add(toReturn);
            }
            con.close();
            return retUser;
        } catch (Exception e)
        {
            userData toReturn = new userData();
            toReturn.firstname = "Error: " + e;
            toReturn.idnumber = "";
            toReturn.lastname = "";
            toReturn.pin = "";
            toReturn.status = 0;
            retUser.add(toReturn);
            return retUser;
        }
    }

Restful webservices with Netbeans

1. Netbeans 6.9
2. Create a project Helloworld
3. Right Click the project and choose the option create Restful webservice.
3. Deploy and test the service
4. Right Click on project properties set relative url as resources/helloworld

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloworld;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBElement;
import javax.ws.rs.FormParam;
import javax.ws.rs.QueryParam;
import java.util.ArrayList;
import java.util.List;

/**
 * REST Web Service
 *
 * @author localadmin
 */

@Path("helloworld")
public class HelloWorld {
    @Context
    private UriInfo context;

    /** Creates a new instance of HelloWorld */
    public HelloWorld() {
    }

    /**
     * Retrieves representation of an instance of helloworld.HelloWorld
     * @return an instance of java.lang.String
     */
    @POST
   // @Produces("text/html")
   @Produces("application/xml")
  // @Consumes("application/x-www-form-urlencoded")
 //   public List<userData> getHtml(@QueryParam("name") String user_id) {
      public List<userData> getHtml(@FormParam("test") String user_id) {
           userData toReturn = new userData();
                toReturn.name = user_id;
        List<userData> retUser = new ArrayList<userData>();
        retUser.add(toReturn);
   return retUser;
  }

    /**
     * PUT method for updating or creating an instance of HelloWorld
     * @param content representation for the resource
     * @return an HTTP respons with content of the updated or created resource.
     */
    @PUT
    @Consumes("text/html")
    public void putHtml(String content) {
    }
}


2nd Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloworld;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class userData {
    public String name;
   
}

And the post html
 <html>
<head>
<script src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"
type="text/javascript">
</script>

    <script type="text/javascript">
      function register(){
    //    window.open("/welcome.html",'welcome','width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes');
        alert("hey");
        $.ajax({
            type: "GET",
            url: "http://localhost:8080/HelloWorld/resources/helloworld",
            data: "user_id=" + document.getElementById("user_id").value ,
            success: function(msg){
                            window.alert(msg);
                        },
                error: function(xmlHttpRequest, status, err) {
                    alert('Status ' + status + ', Error ' + err);
                }
    });
        }
    </script>
</head>
<body>
<form action="http://localhost:8080/HelloWorld/resources/helloworld" method="post">
<textarea name="test" rows="8" cols="40" value="tangeo"></textarea>
<input type="text" id="name" name="name" value="harshal"/>
<input type="submit" value="submit"/>
<div id="response">
hello
    </div>
</form>
</body>
</html>
Create the security key and password

1 ./usr/lib/jvm/java-6-sun/bin# keytool -genkey -alias tomcat -keypass changeit -keystore sslkey.bin -storepass changeit
2. Go to glass fish Server http://localhost:4848 Network Config http listener 2 enable ssl and set port number to 8443.
3. Click on tab SSL and put in certificate name as tomcat or the one given above as alias.
4. In Key Store place /usr/lib/jvm/java-6-sun/bin/sslkey.bin
5. Go back to HelloWorld project in netbeans and click on web.xml then click on security tab. Click on Add Web Resource Collection
 put the name as http://localhost:8080/HelloWorld/resources/application.wadl which is displayed when you right click project in netbean and Test WebService on this page the resource name is present.
6. Coming back after web resource collection in url pattern place /helloworld.

HAJDBC with Liferay

Integrate HAJDBC and Liferay

1. Create portal-ext.properties as below and place it in the root folder of the liferay
# HAJDBC
#
jdbc.default.driverClassName=net.sf.hajdbc.sql.Driver
jdbc.default.url=jdbc:ha-jdbc:cluster1
jdbc.default.username=lportal
jdbc.default.password=lportal
2. Create ha-jdbc-cluster1.xml as below and place it in the folder C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\classes
<ha-jdbc>
<!--<distributable config="" 
stack="sequencer" /> -->
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy" >
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster default-sync="diff" balancer="load" meta-data-cache="none"
dialect="net.sf.hajdbc.dialect.MySQLDialect" transaction-mode="parallel"
auto-activate-schedule="0 * * ? * *" failure-detectschedule="0 * * ? * *">
<database id="database1">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal1</url>
<user>lportal</user>
<password>lportal</password>
</database>

<database id="database2">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal</url>
<user>lportal</user>
<password>lportal</password>
</database> 
</cluster>
</ha-jdbc>
3. Create stacks.xml as below and place it in the location C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\classes

<!--
Sample file that defines a number of stacks, used by multiplexer
JGroups channel Author: Bela Ban Version: $Id: stacks.xml,v 1.1
2006/02/16 09:08:53 belaban Exp $
-->
<protocol_stacks>
<stack name="fc-fast-minimalthreads" description="Flow control, no up or
down threads">
<config>
<UDP mcast_port="45566" mcast_addr="228.10.10.10" tos="16"
ucast_recv_buf_size="20000000" ucast_send_buf_size="640000"
mcast_recv_buf_size="25000000" mcast_send_buf_size="640000"
loopback="false" discard_incompatible_packets="true"
max_bundle_size="64000" max_bundle_timeout="30"
use_incoming_packet_handler="true" use_outgoing_packet_handler="false"
ip_ttl="2" down_thread="false" up_thread="false" enable_bundling="true" />
<PING timeout="2000" down_thread="false" up_thread="false"
num_initial_members="3" />
<MERGE2 max_interval="100000" down_thread="false" up_thread="false"
min_interval="20000" />
<FD_SOCK down_thread="false" up_thread="false" />
<VERIFY_SUSPECT timeout="1500" down_thread="false" />
<pbcast.NAKACK max_xmit_size="60000" use_mcast_xmit="false"
gc_lag="0" retransmit_timeout="100,200,300,600,1200,2400,4800"
down_thread="false" up_thread="false" discard_delivered_msgs="true" />
<UNICAST timeout="300,600,1200,2400,3600" down_thread="false"
up_thread="false" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000" down_thread="false" up_thread="false"
max_bytes="400000" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="3000"
down_thread="false" up_thread="false" join_retry_timeout="2000"
shun="true" />
<FC max_credits="2000000" down_thread="false" up_thread="false"
min_threshold="0.10" />
<FRAG2 frag_size="60000" down_thread="false" up_thread="true" />
<pbcast.STATE_TRANSFER down_thread="false"
up_thread="false" />
</config>
</stack>

<stack name="sequencer" description="Totally ordered multicast using a
sequencer">
<config>
<UDP bind_addr="192.168.5.1" mcast_port="45566" mcast_addr="228.10.10.10"
tos="16" ucast_recv_buf_size="20000000" ucast_send_buf_size="640000"
mcast_recv_buf_size="25000000" mcast_send_buf_size="640000"
loopback="false" discard_incompatible_packets="true"
max_bundle_size="64000" max_bundle_timeout="30"
use_incoming_packet_handler="true" use_outgoing_packet_handler="false"
ip_ttl="2" down_thread="false" up_thread="false" enable_bundling="true" />
<PING timeout="2000" down_thread="false" up_thread="false"
num_initial_members="3" />
<MERGE2 max_interval="10000" down_thread="false" up_thread="false"
min_interval="5000" />
<FD_SOCK down_thread="false" up_thread="false" />
<VERIFY_SUSPECT timeout="1500" down_thread="false" />
<pbcast.NAKACK max_xmit_size="60000" use_mcast_xmit="false"
gc_lag="0" retransmit_timeout="100,200,300,600,1200,2400,4800"
down_thread="false" up_thread="false" discard_delivered_msgs="true" />
<UNICAST timeout="300,600,1200,2400,3600" down_thread="false"
up_thread="false" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="50000" down_thread="false" up_thread="false"
max_bytes="400000" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="3000"
down_thread="false" up_thread="false" join_retry_timeout="2000"
shun="true" handle_concurrent_startup="true" />
<SEQUENCER down_thread="false" up_thread="false" />
<FC max_credits="2000000" down_thread="false" up_thread="false"
min_threshold="0.10" />
<FRAG2 frag_size="60000" down_thread="false" up_thread="true" />
<pbcast.STATE_TRANSFER down_thread="false"
up_thread="false" />

</config>
</stack>


<stack name="tcp" description="Using TCP as transport">
<config>
<TCP start_port="7800" loopback="true" send_buf_size="100000"
recv_buf_size="200000" />
<TCPPING timeout="3000" initial_hosts="localhost[7800]"
port_range="3" num_initial_members="3" />
<FD timeout="2000" max_tries="4" />
<VERIFY_SUSPECT timeout="1500" down_thread="false"
up_thread="false" />
<pbcast.NAKACK gc_lag="100" retransmit_timeout="600,1200,2400,4800" />
<pbcast.STABLE stability_delay="1000"
desired_avg_gossip="20000" down_thread="false" max_bytes="0"
up_thread="false" />
<VIEW_SYNC avg_send_interval="60000" down_thread="false"
up_thread="false" />
<pbcast.GMS print_local_addr="true" join_timeout="5000"
join_retry_timeout="2000" shun="true" />
</config>
</stack>

</protocol_stacks>
4. Add the following jars in the location C:\Liferay-Portal\Tomcat\webapps\ROOT\WEB-INF\lib
a. ha-jdbc-2.0.16-rc-1-jdk1.6.jar
b. jcl-over-slf4j-1.5.7.jar
c. jgroups-2.6.10.jar
d. jibx-run-1.2.1.jar
e. log4j-1.2.15.jar
5. In tomcat server.xml add the below just before the last </> tag location: C:\Liferay-Portal\Tomcat\conf
<Context>
<!-- ... -->
<Resource name="jdbc/cluster" type="javax.sql.DataSource"
username="lportal" password="lportal" driverClassName="net.sf.hajdbc.sql.Driver"
url="jdbc:ha-jdbc:cluster1"/>
<!-- ... -->
</Context>
6. In tomcat web.xml add the below just before the last </webapp> tag location : C:\Liferay-Portal\Tomcat\conf
<resource-env-ref>
<resource-env-ref-name>jdbc/cluster</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
<!-- ... -->
7. Now the configuration is done go to mysql root and create a database lportal1 with following commands
a. mysql> create database lportal1 character set utf8;
b. mysql> grant all on lportal1.* to 'lportal'@'localhost' identified by 'lportal'
with grant option;
c. mysql> grant all on lportal1.* to 'lportal'@'localhost' identified by 'lportal'
with grant option;
8. Now start tomcat..

Trouble shooting : If tomcat throws exception that the lportal1…table does not exits.
Then reverse the database location ie 
Use this ha-jdbc-cluster1.xml in step 2
<ha-jdbc>
<!--<distributable config="" 
stack="sequencer" /> -->
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy" >
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster default-sync="diff" balancer="load" meta-data-cache="none"
dialect="net.sf.hajdbc.dialect.MySQLDialect" transaction-mode="parallel"
auto-activate-schedule="0 * * ? * *" failure-detectschedule="0 * * ? * *">
<database id="database1">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal</url>
<user>lportal</user>
<password>lportal</password>
</database>

<database id="database2">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/lportal1</url>
<user>lportal</user>
<password>lportal</password>
</database> 
</cluster>
</ha-jdbc>
We have changed the position highlighted in red.

Batch file to start a java program with other jars

for %%i in (%0) do cd /d %%~dpi..\
call bin\set_env.bat
set JAVA_ARGS=%JAVA_ARGS% -Xms512m -Xmx2056m
::set JAVA_ARGS=%JAVA_ARGS% -Dcom.sun.management.jmxremote.port=50065
::set JAVA_ARGS=%JAVA_ARGS% -Dlogback.file.name=GPComponent

set MAIN=gpro.brokersimulator.SimulatorView

%JAVA_HOME%\bin\java %JAVA_ARGS% -cp %CLASSPATH% %MAIN%

pause

Batch to move the file out

Send out file :

FOR /F "tokens=1-4 delims=/ " %%i IN ('DATE /T') DO SET TODAY=%%l%%j%%k

SET OUTFILE=\\WTPCPFTGT001\ftp_itg$\G-TRADE_EXEC_%TODAY%.csv

osql -S wtpcpdb1 -E -w 4000 -Q "exec gpro..ITG_Canada_EXEC" -o %OUTFILE%

Batch to zip a file and ftp to different location

@echo OFF
if not '%1'=='' GOTO SETDATE

: i=dayofwkstr, j=month, k=day, l=year
FOR /F "tokens=1-4 delims=/ " %%i IN ('DATE /T') DO SET DateStr=%%l%%j%%k
for /F "tokens=1-2 delims=: " %%i IN ('time /T') DO SET TimeStr=%%i%%j
GOTO AFTERSETDATE

:SETDATE
SET DateStr=%1

:AFTERSETDATE
echo %DateStr%
echo %TimeStr%

@echo on
SET SRV_NAME=%COMPUTERNAME%


del \\%SRV_NAME%\d$\Gpro-logs-tables\*.* /Q /S /F

:server side
xcopy \\WTPCPAPGT303\inforeach\inforeach\out\*.* /S  \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP303
xcopy \\WTPCPAPGT301\d$\inforeach\inforeach\out\*.* /S  \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP301

:Gpro.log
xcopy \\WTPCPAPGT303\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP303
xcopy \\WTPCPAPGT301\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP301

:djwin.log
xcopy \\WTPCPAPGT303\c$\temp\djwin.log \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP303

:DJExporter.txt
xcopy \\WTPCPAPGT303\c$\temp\DJExporter.txt \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP303

:ClientInfo.txt
xcopy \\WTPCPAPGT301\c$\temp\ClientInfo.txt \\%SRV_NAME%\d$\Gpro-logs-tables\ServerSide\AP301

:client side



xcopy \\WTPCPCXGT001\e$\inforeach\inforeach\out\*.* /S \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX1
xcopy \\WTPCPCXGT001\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX1

xcopy \\WTPCPCXGT002\e$\inforeach\inforeach\out\*.* /S \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX2
xcopy \\WTPCPCXGT002\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX2

xcopy \\WTPCPCXGT003\e$\inforeach\inforeach\out\*.* /S \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX3
xcopy \\WTPCPCXGT003\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX3

xcopy \\WTPCPCXGT004\e$\inforeach\inforeach\out\*.* /S \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX4
xcopy \\WTPCPCXGT004\c$\temp\gpro.log \\%SRV_NAME%\d$\Gpro-logs-tables\ClientSide\CTX4

:BCP out the GP_ tables

isqlw -i\\WTPCPDBGT301\e$\GProProduction\Daily\sql\GP_Tables_bcp_new.sql -o\\WTPCPDBGT301\e$\GProProduction\Daily\Logs\GP_Tables_bcp.out -E



call wzzip.exe -rp  \\%SRV_NAME%\d$\Gpro-logs-tables\%DateStr%%TimeStr%Gpro_Logs_Tables \\%SRV_NAME%\d$\Gpro-logs-tables\

copy \\%SRV_NAME%\d$\Gpro-logs-tables\%DateStr%%TimeStr%Gpro_Logs_Tables.zip \\%SRV_NAME%\E$\GProProduction\Logs-Archive\



@ECHO on
            SET PROCESS=GETFILE
            SET CMDFILE=INFOREACH_FTP.FTP
            SET LOGFILE=INFOREACH_FTP.LOG
            SET LOCAL_DATA=D:\Gpro-logs-tables

            SET USERNAME=gpro@in4reach.com
            SET PASSWORD=gpro01
            SET HOSTNAME=www.in4reach.com
            SET SERVICE=%1

                       
            Echo open %HOSTNAME%                            >  %CMDFILE%
            Echo %USERNAME%>> %CMDFILE%
            Echo %PASSWORD%>> %CMDFILE%
            Echo lcd %LOCAL_DATA%                                >> %CMDFILE%
            Echo bin                                        >> %CMDFILE%
            Echo hash                                       >> %CMDFILE%
            Echo put %DateStr%%TimeStr%Gpro_Logs_Tables.zip    >> %CMDFILE%
            Echo quit                                       >> %CMDFILE%

@ECHO ON

 ftp -v -s:%CMDFILE% > %LOGFILE%

Simple Ajax Clock

AJAX:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>

             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             version="2.4">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
            <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>

Index.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html" import="java.util.*" %>

<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
      
        <%
        response.setHeader("Cache-Control","no-cache");
        Date a= new java.util.Date();
        out.write(a.toString());
       // response.setHeader("Refresh","3");
        %>
    </head>
    <body>
   </body>
</html>

Caller.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
">

<html >
<head>
    <meta http-equiv="refresh" content="5">
<script LANGUAGE="JavaScript">
  
function createRequestObject(){
var req;
        if(window.XMLHttpRequest){
        //For Firefox, Safari, Opera
        req = new XMLHttpRequest();
        }
            else if(window.ActiveXObject){
            //For IE 5+
            req = new ActiveXObject("Microsoft.XMLHTTP");
            }
    else{
    //Error for an old browser
    alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
    }

return req;
}

//Make the XMLHttpRequest Object
var http = createRequestObject();

function sendRequest(method, url){
        if(method == 'get' || method == 'GET'){
        http.open(method,url);
        http.onreadystatechange = handleResponse;
        http.send(null);
        }
}

function handleResponse(){
    if(http.readyState == 4 && http.status == 200){
        var response = http.responseText;
        if(response){
        document.getElementById("ajax_res").innerHTML = response;
        }
    }
}

</script>

<title>JSP Page using AJAX</title>
 <% response.setHeader("Refresh","1"); %>
</head>
<!--
<body onmouseover="sendRequest('GET','index.jsp')"> -->
<body onload="sendRequest('GET','index.jsp')">
  
<h>Server Date Time:</h>
<div id="ajax_res"> Time
</div>
</body>
</html>

Test.jsp
  <%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


<HTML>
<HEAD>

<%

String action = request.getParameter("chkRefresh");
String refreshCmd = "";

if (action != null) {
refreshCmd = "setInterval('window.location.reload()', 4000);";
} else {
refreshCmd = " ";
action = "off";
}

%>

<SCRIPT LANGUAGE="JavaScript"><!--

<%=refreshCmd %>

function setAutoRefresh() {
data.submit();
}

//-->
</SCRIPT>

<TITLE>test.jsp</TITLE>
</HEAD>
<BODY>
<FORM NAME="data" ACTION="test.jsp" METHOD="post">

<% if (action.equalsIgnoreCase("off")) { %>
<P><INPUT type="checkbox" name="chkRefresh"
onclick="setAutoRefresh()">Auto Refresh OFF</P>
<%} else {%>
<P><INPUT type="checkbox" name="chkRefresh" onclick="setAutoRefresh()"
checked>Auto Refresh ON</P>
<% } %>

</FORM>
</BODY>
</HTML>