Sunday, November 13, 2011

Tuesday, August 2, 2011

Return Of the Capital than Return on the Capital

1. David Walker explains how US is closer to a scenario as that of Greece in 3 years.












2. See what Bill Gross has got to say about US Job Market (for next 12 months)

** PIMCO is one of the biggest US Bond holder and on July 30th they dumped Bonds for Cash building up close to $53B in cash (Originally $17B). Jobs report and QE2 is going to help rally in capital market further. No worries on long term investment with the capital market, but staying in expensive bond market with US credit rating under downgrade risk does not yield much.













 

… it is time to start to think about …

Return of the Capital

than

Return on the Capital

Friday, July 29, 2011

Creating a Simple Application using Google App Engine

If hosting your application on the Cloud is your primary goal, then Google App Engine might be a good start. Here we are going to see a simple example of how to run an app on Google App Engine.

Install Google App IDE Plugin for your IDE. (For using Eclipse IDE, go to Eclipse.org download eclipse, and go to code.google.com and find how to get it installed for Eclipse)

Steps are more detailed in : http://code.google.com/appengine/docs/java/gettingstarted/installing.html

After Installing, Create a new Web Application Project

image

Name your Project, and deselect “Use Google Web Toolkit” unless needed.

image

This will be the file structure. Under /src/<package Name>/ you will find your Servlet Class source code. (.java file)

image

 

Next – lets modify the Servlet.

Open your servlet from src/((package_name))/((Project_name))Servlet.java & modify your servlet.java code to make it perform some work, when called as below which gives the date and current time.

   1:  package //your package name;
   2:  import java.io.IOException;
   3:  import javax.servlet.http.*;
   4:  import java.io.PrintWriter;
   5:  import java.text.SimpleDateFormat;
   6:  import java.util.Date;
   7:  import java.util.SimpleTimeZone;
   8:   
   9:  @SuppressWarnings("serial")
  10:  public class Conciliation1Servlet extends HttpServlet {
  11:      public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  12:          SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
  13:          fmt.setTimeZone(new SimpleTimeZone(0,""));
  14:          resp.setContentType("text/html");
  15:          PrintWriter out = resp.getWriter();
  16:          out.println("<html><body><p> Current Time is: " + fmt.format(new Date())+ "</p></body></html>");
  17:      }
  18:  }



 


Open web.xml (usually in war/WEB-INF/lib/web.xml ), and modify as shown


   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   3:  xmlns="http://java.sun.com/xml/ns/javaee"
   4:  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   5:  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   6:  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
   7:      <servlet>
   8:          <servlet-name> <!-- Give a Name for Servlet--> </servlet-name>
   9:          <servlet-class> <!-- Package Name --> </servlet-class>
  10:      </servlet>
  11:      <servlet-mapping>
  12:          <servlet-name> <!-- Same name as the Servlet provided above --> </servlet-name>
  13:          <url-pattern>/dothis </url-pattern><!-- Give the URL pattern, example /* (or) /dothis, always start the url pattern with / --> 
  14:      </servlet-mapping>
  15:      <welcome-file-list>
  16:          <welcome-file>index.html</welcome-file>
  17:      </welcome-file-list>
  18:  </web-app>



Now Modify index.html under war/WEB-INF/


   1:  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
   2:  <!-- The HTML 4.01 Transitional DOCTYPE declaration-->
   3:  <!-- above set at the top of the file will set     -->
   4:  <!-- the browser's rendering engine into           -->
   5:  <!-- "Quirks Mode". Replacing this declaration     -->
   6:  <!-- with a "Standards Mode" doctype is supported, -->
   7:  <!-- but may lead to some differences in layout.   -->
   8:   
   9:  <html>
  10:    <head>
  11:      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  12:      <title>Hello App Engine</title>
  13:    </head>
  14:   
  15:    <body>
  16:      <h1>Hello App Engine!</h1>
  17:      
  18:      <table>
  19:        <tr>
  20:          <td colspan="2" style="font-weight:bold;">Available Servlets:</td>        
  21:        </tr>
  22:        <tr>
  23:          <td><a href="dothis">Current Date</a></td>
  24:        </tr>
  25:      </table>
  26:    </body>
  27:  </html>



Open and update version number (line 4) if needed in appengine-web.xml from war/WEB-INF/lib


If you have a google app engine setup for your google login id, then create a google application. You will be asked to choose an application_id. Use this application_id in line 3, before you upload it to google app engine for testing.


   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
   3:      <application><!—application id—></application>
   4:      <version>1</version> <!-- update version number if needed -->
   5:      
   6:      <!-- Configure java.util.logging -->
   7:      <system-properties>
   8:          <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
   9:      </system-properties>
  10:      
  11:  </appengine-web-app>



Execute the App in Debug Mode


image


image


Click on “Current Date” and you will see the current time.


image


Let us now try to customize it per user (in development server a default user test@example.com gets automatically created with app engine, but when you deploy it to google app engine, you will be asked to be authenticated by Google Sign In Process)


Modify the servlet.java as follows.


   1:  package //package name;
   2:  import java.io.IOException;
   3:  import javax.servlet.http.*;
   4:  import java.io.PrintWriter;
   5:  import java.text.SimpleDateFormat;
   6:  import java.util.Date;
   7:  import java.util.SimpleTimeZone;
   8:  import com.google.appengine.api.users.User;
   9:  import com.google.appengine.api.users.UserService;
  10:  import com.google.appengine.api.users.UserServiceFactory;
  11:   
  12:  @SuppressWarnings("serial")
  13:  public class Conciliation1Servlet extends HttpServlet {
  14:      public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  15:          SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
  16:          fmt.setTimeZone(new SimpleTimeZone(0,""));
  17:          
  18:          UserService userService = UserServiceFactory.getUserService();
  19:          User user= userService.getCurrentUser();
  20:          
  21:          String navBar;
  22:          if (user != null)
  23:          {
  24:              navBar = "<p> Welcome, " + user.getNickname() + "! You can <a href=\""+ userService.createLogoutURL("/")+ "\"> Sign Out </a>.</p>";
  25:          } else {
  26:              navBar = "<p> Welcome! <a href=\""+ userService.createLoginURL("/") + "\"> Sign In or Register </a> to customize </p>";
  27:          }
  28:          
  29:          resp.setContentType("text/html");
  30:          PrintWriter out = resp.getWriter();
  31:          out.println("<html><body>");
  32:          out.println(navBar);
  33:          out.println("<p> Current Time is: " + fmt.format(new Date())+ "</p>");
  34:          out.println("</body></html>");
  35:      }
  36:  }



Execute the App in Debug Mode


Open the browser and view index.html


image


Click on Current Date


image


Now Click on “Sign In or Register”, in development it will take you to a simple console that will allow you to login as "test@example.com” but after you deploy in google app engine, you will be asked to login with your google id.


image


test@example.com is a default account that’s in development for debugging use, so choose “Log In”


It will take you back to first screen, because we gave a successful login as to take us to root of the site.


image


Now click on Current Date, lets see what happens now.


image


We should get this type of a window after it has authenticated you.


-- Thz it , its that’s simple–


Now you have a simple Web Application that is ready to be deployed to - Google App Engine


Steps to Upload your application to the cloud is more detailed on : http://code.google.com/appengine/docs/java/gettingstarted/uploading.html


NOTE: update your application_id in appengine-web.xml to the one in your google application admin console for your google account where you are planning to upload the app to. If this is not  the same you might have trouble uploading your application.

Tuesday, July 26, 2011

Getting rid of debt the right way

I think what Prof.Robert Shiller proposes makes a lot more sense at this juncture

Sunday, June 19, 2011

Selecting the appropriate JDBC Connection Resource type


javax.sql.DataSource (local transactions only)
  javax.sql.XADataSource (global transactions)

An XA transaction, in the most general terms, is a "global transaction" that may span multiple resources. A non-XA transaction always involves just one resource.
An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).
XA transactions come from the X/Open group specification on distributed, global transactions. JTA includes the X/Open XA spec, in modified form.
Most stuff in the world is non-XA - a Servlet or EJB or plain old JDBC in a Java application talking to a single database. XA gets involved when you want to work with multiple resources - 2 or more databases, a database and a JMS connection, all of those plus maybe a JCA resource - all in a single transaction. In this scenario, you'll have an app server like Websphere or Weblogic or JBoss acting as the Transaction Manager, and your various resources (Oracle, Sybase, IBM MQ JMS, SAP, whatever) acting as transaction resources. Your code can then update/delete/publish/whatever across the many resources. When you say "commit", the results are commited across all of the resources. When you say "rollback", _everything_ is rolled back across all resources.
The Transaction Manager coordinates all of this through a protocol called Two Phase Commit (2PC). This protocol also has to be supported by the individual resources.
In terms of datasources, an XA datasource is a data source that can participate in an XA global transaction. A non-XA datasource generally can't participate in a global transaction (sort of - some people implement what's called a "last participant" optimization that can let you do this for exactly one non-XA item).
For more details - see the JTA pages on java.sun.com. Look at the XAResource and Xid interfaces in JTA. See the X/Open XA Distributed Transaction specification. Do a google source on "Java JTA XA transaction".