Monday, December 8, 2014

Installing Node-Oracle on Windows 7

Assuming that you Nodejs installed and working on your local pc.

Software Required


  • Windows 7.1 SDK (Microsoft Windows SDK for Windows 7 and .NET Framework 4.0)
    http://www.microsoft.com/en-us/download/details.aspx?id=8279
  • Visual C++ 2010 Express
    http://www.visualstudio.com/en-us/downloads#d-2010-express
  • Python 2.7
    https://www.python.org/downloads/
  • Oracle Download
    Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications ( instantclient-basic-windows.x64-12.1.0.2.0)
    *Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client (instantclient-sdk-windows.x64-12.1.0.2.0)
    http://www.oracle.com/technetwork/topics/winx64soft-089540.html
  • Node package For Oracle
    https://github.com/joeferner/node-oracle

Setup

Step 1
Install Windows 7 SDK
1) Uninstall any c++ redistributable you have on your pc.
2) If you run in to problem installing the windows 7 sdk , try doing what is provided at this help (http://ctrlf5.net/?p=184)

Step 2
Install Visual C++ 2010 Express

Step 3
Download and install Python

Step 4
Download the Oracle Basic + SDK.  (kindly download 64 bit /32 bit depending on your OS)
Extract it at one place
C:\oracle\instantclient_12_1_64

Step 5
Download the node-oracle zip and extract it at
C:\oracle\node-oracle-master

Step 6
set the following variable or create a bat file that you can run.
set OCI_LIB_DIR=C:\oracle\instantclient_12_1_64\sdk\lib\msvc\vc10
set OCI_INCLUDE_DIR=C:\oracle\instantclient_12_1_64\sdk\include
set OCI_VERSION=12
set NLS_LANG=.UTF8 # Optional, but required to support international characters
Path=%PATH%;C:\oracle\instantclient_12_1_64\vc10;C:\oracle\instantclient_12_1_64;C:\Users\jignesh.rangwala\AppData\Roaming\npm;C:\Python27\python.exe;C:\Python27\pythonw.exe


Step 7
Launch the Windows SDK 7.1 Command Prompt, go to the directory of your node-oracle module (C:\oracle\node-oracle-master)
If any where in this step you get file permission errors open the Windows SDK 7.1 Command Prompt as Administrator
1) run npm install -g
2) If everything runs correctly this will build and create node oracle modules at
C:\Users\[user]\AppData\Roaming\npm\node_modules
3) If you not defined yet , define an enviroment variable
NODE_PATH=C:\Users\[user]\AppData\Roaming\npm\node_modules


Run a sample testoracle.js
------------------------------------------------------------------
var oracle = require('oracle'); //without tns var connString = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=db)))"; var connectData = { "tns": connString, "user": "user", "password": "pwd" }; oracle.connect(connectData, function(err, connection) { if (err) { console.log("Error connecting to db:", err); return; } connection.execute("SELECT systimestamp FROM dual", [], function(err, results) { if (err) { console.log("Error executing query:", err); return; } console.log(results); connection.close(); // call only when query is finished executing }); });
------------------------------------------------------------------

If you get this error,
fs.js:438
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);                 ^
Error: ENOENT, no such file or directory 'C:\oracle\node-oracle-master\test\tests-settings.json'

while running your program, just make sure your path should have
C:\oracle\instantclient_12_1_64\sdk\lib\msvc\vc10;
C:\oracle\instantclient_12_1_64;
 before C:\oracle\product\11.2.0\client_1\bin

ie your path should be like this
C:\oracle\instantclient_12_1_64\sdk\lib\msvc\vc10;C:\oracle\instantclient_12_1_64;C:\oracle\product\11.2.0\client_1\bin


Just Verified the same softwares/steps works on windows server 2008 r2



Wednesday, August 13, 2014

EJB3.1 - EJB on Websphere & Client on Remote PC with J2SE

Purpose:  I was looking for a simple hello world ejb (ejb3.1) with remote interface,  that i can deploy on websphere application server and use it from the remote j2se client.
I was not able to find  this kind of sample readily available.

So here is the HelloWorld EJB(3.1) and its client.

1) Create HelloWorld EJB

1.1) Using RAD (/eclipse)  Create a new JavaEE > Enterprise Application Project.

Project Name = TestEjb, Under java ee module dependency, check the check box for ejb module.
The project Structure should look like below.






Code for TestEJBRemote.java
---------------------------------------------------------------------------------------------------------------------
package ejb31.test;
import javax.ejb.Remote;

@Remote
public interface TestEJBRemote {   
    public String sayHello(String value);
}

--------------------------------------------------------------------------------------------------------------------- 

Code for TestEJBRemote.java
 --------------------------------------------------------------------------------------------------------------------- 
package ejb31.test;

import javax.ejb.Stateless;

@Stateless
public class TestEJB implements TestEJBRemote {

    public TestEJB() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public String sayHello(String yourValue) {
        System.out.println("got your " + yourValue);
        return "hello " + System.currentTimeMillis() + " - " + yourValue;
    }

}

---------------------------------------------------------------------------------------------------------------------

Code for ejb-jar.xml
 --------------------------------------------------------------------------------------------------------------------- 
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
    <module-name>TestEjbEJB</module-name>
    <display-name>TestEjbEJB</display-name>
   
</ejb-jar>

---------------------------------------------------------------------------------------------------------------------

Code for ibm-ejb-jar-bnd.xml
 ---------------------------------------------------------------------------------------------------------------------  <?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd
        xmlns="http://websphere.ibm.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_2.xsd"
        version="1.2">
      
        <session name="TestEJB"></session>

</ejb-jar-bnd>

---------------------------------------------------------------------------------------------------------------------

Code for ibm-ejb-jar-ext.xml
 ---------------------------------------------------------------------------------------------------------------------
 <?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-ext
    xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_1.xsd"
    version="1.1">

</ejb-jar-ext>

  ---------------------------------------------------------------------------------------------------------------------


Start the Application server (WAS  8.5 / 8) and deploy to the server.


2) Create the EJB Client.

2.1) Right click on TestEjbEJB and click on Export. Export it as EJB JAR File.






The jar file get exported at location c:/temp.

2.2) Now run the IBM createEJBStubs tool located under  AppServer/bin directory.
 

 (run from c:/temp)
C:\IBM\WebSphere85\AppServer_1\bin\createEJBStubs.bat TestEjbEJB.jar -newfile TestEjbEJBClient.jar -quiet

You can check the TestEjbEJBClient.jar - there would be a stub produced by the name of _TestEJBRemote_Stub.class


3) Create the Java Client Project.
Dependency needed





3.1) Create new Java Project TestEJBClient, as below.





Code for TestMain.java
 ---------------------------------------------------------------------------------------------------------------------
package test;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import ejb31.test.TestEJBRemote;
  
public class TestMain {
    Context ctx = null;
    public static void main(String args[]) {
        TestMain t = new TestMain();
        t.test();
    }
  
    public void test() {
       
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
        env.put(Context.PROVIDER_URL,"iiop://localhost:2809");
                      
        try {
            ctx = new InitialContext(env);
           

            String jndiURL = "ejb31.test.TestEJBRemote";
          
            TestEJBRemote remote = (TestEJBRemote) ctx.lookup(jndiURL);
           
          
            System.out.println(remote.sayHello("did you got me"));
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}


  ---------------------------------------------------------------------------------------------------------------------



Thursday, May 1, 2014

Head FIrst JQuery by Ryan Benedetti and Ronan Cranley, O’Reilly Media




First of all big thanks to the "Head First" series designers who gave a very good thought of how the book need to be organised,  the section "How to use this book" tells about all the book, the software required, examples location and how to set up the developers workspace.

The Author gently introduces the concept of Web - HTML + CSS, thats were we are more familiar with.  Explaining JQuery in side by side with CSS explains the non-intrusive nature on which JQuery is majorily used for.  Authors way of introduction of JQuery - why jquery is different then the other scripting library.
After giving a introduction the author goes over the various indepth of  JQuery like selectors, methods, events & function, and keeps going on to the deeper part where jquery is used the most  - Web Page manipulations, Effects, Animation, Custom Functions, Ajax and JSON.
The last two chapters are dedicated to jquery widgets  aka JQuery UI and indepth of JQuery API and objects.
Would have some more explanation of JSON and how that can benefit the data driven pages.















I review for the O'Reilly Reader Review Program