Showing posts with label Technologies. Show all posts
Showing posts with label Technologies. Show all posts

Wednesday, July 9, 2014

DB2 CHAR VS VARCHAR

CHAR

VARCHAR disadvantages:
- uses 2 extra bytes to store the length
-  needs a little extra effort when storing and manipulating length of VARCHAR -> may affect efficiency


General Rule:
  • Use CHAR if average length of field is more than 6 bytes to save space
    • if average length of field is less than 6 bytes, there will be no storage savings for using char
  • Use varchar for columns with more that 30 characters (can be shorter for others)

Monday, May 12, 2014

Creating a SOAP Web Service


1. Create the Java class with methods you want to be converted as web service
2. Add a WebService annotation to the class
3. Add WebMethod annotation to the web service method. This is optional. All public methods of the web service class are automatically considered a web service method.

Example:
@WebService
public class BookStore{
@WebMethod
 public List<String> getBookNames() {
 }
}
This will create a web service class called BookStoreService.

Wednesday, May 7, 2014

Consuming a Web Service

What you need:
- wsdl source

1. Use wsimport tool from java se. In command line enter:
wsimport -keep -s , e.g. wsimport -keep -s src
-keep - keep generated files (.java files)

2. Import the the java files in your project and use them as stubs to call the webservice method(s). The name of the stub you can use can be found in the wsdl:service tag of the wsdl.
Ex.
 name="CurrencyConvertor">

CurrencyConvertor cc = new CurrencyConvertor();
CurrencyConvertorSoap ccs = cc.getCurrencyConvertorSoap();




Saturday, April 12, 2014

GlassFish Basics

domain1
- default domain created during installation of GlassFish
- {glassfish.dir}/glassfish/domains/domain1

Start/stop of server
- in {glassfish.dir}/bin run command: asadmin start-domain or asadmin stop-domain

Console
- http://localhost:4848/




Sunday, September 8, 2013

Derby

http://db.apache.org/derby/docs/10.9/devguide/cdevdvlp17453.html

Steps involved during Execution of a Java Program

  1. JVM startup
  2. Loading – finding binary representation of class/interface then constructing the Class object
  3. Linking – combining class/interface into the run-time state of the JVM so that it can be executed
    1. Verification - semantic/structure validation
    2. Preparation - storage allocation, all static fields are created and initialized with default values
    3. Resolution – optionally resolve symbolic reference to other classes/interfaces
  4. Initialization – static initialization 
    1. superclass/superinterface static initialization
      • superclasses are initialized before subclasses
      • interface initialization does not initialize superinterfaces
      • only the class that declares static field is initialized, even though it might be referred to through the name of a subclass, a subinterface, or a class that implements an interface
    2. all static explicit field initializers and static initialization blocks are executed in textual order
  5. Instantiation - creation of object/class instance
    All the instance variables, including those declared in superclasses, are initialized to their default values first.
    1. start the constructor
    2. call explicit constructor this() if available
    3. call explicit/implicit super() unless class is Object – process recursively using same steps a. to e. 
    4. all non-static field initializers and non-static initialization blocks are executed in textual order
    5. execute the rest of the body of constructor
  6. Finalization – finalize() method is called before storage for object is reclaimed by GC
  7. Unloading – happens if its classloader is reclaimed by GC. Bootstrap loader may not be unloaded.
  8. Program Exit

Monday, August 12, 2013

DWR error handling

Exception/error handling of DWR calls can be centralized by setting the handlers. More here: http://directwebremoting.org/dwr/documentation/browser/errors.html


dwr.engine.setErrorHandler(UI.errorHandler);
dwr.engine.setTextHtmlHandler(UI.textHtmlHandler);

 // Handler for errors and exceptions
 errorHandler : function(msg, param2) {
  UI.hideLoading();
  Utils.resetClick();
  View.error(msg, 700)
 },

 // Handler when Ajax returns a text such as session timeout, page not found etc...
 textHtmlHandler : function() {
  UI.hideLoading();
  //View.error("Your session has expired, please login again." );
   document.location = '/adapt/web/jsp/timeout.jsp';
 },

Monday, July 29, 2013

Spring Inversion of Control

Bean Creation
- code POJO, add bean configuration element to the Spring XML configuration file or annotate the POJO
<bean id="message" class="org.springbyexample.di.xml.BelleMessage"/>

Inversion of Control
1. Constructor Injection

public ConstructorMessage(String message) {
    this.message = message;
}

<bean id="message" class="org.springbyexample.di.xml.ConstructorMessage">
    <constructor-arg value="Spring is fun." />
</bean>

2. Setter Injection

public void setMessage(String message) {
    this.message = message;
}

<bean id="message" class="org.springbyexample.di.xml.SetterMessage">
    <property name="message" value="Spring is fun." />
</bean>

3. Reference Injection

<bean id="message" class="org.springbyexample.di.xml.SetterMessage">
    <property name="message" ref="springMessage"" />
</bean>


source: http://www.springbyexample.org/examples/intro-to-ioc.html

Monday, July 8, 2013

Drools Core

  1. create a knowledge builder to load processes from various resources (for example from the classpath or from file system)
  2. create a knowledge base from the builder
  3. instantiate a session based on the knowledge base
  4. start executing processes
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.MyProcess");
ksession.fireAllRules();

Sunday, June 2, 2013

SSL and certificates

Terms:

  • SSL (Secure Socket Layer) - a security protocol that ensures secure transaction/connection between a server and a client
  • https - beginning of an SSL-secured website/URL
  • SSL Certificate - a small data file that establishes encrypted connection. It contains a key pair, a public and private key, and the subject identifying the certificate. Typically an SSL Certificate will contain your domain name, your company name, your address, your city, your state and your country. It will also contain the expiration date of the Certificate and details of the Certification Authority responsible for the issuance of the Certificate.
  • Certificate Authority or CA - the SSL Certificate issuer. It researches companies, checks references, assures identity and encrypts data to and from servers. 
  • certificate chain - a series of intermediate certificates
  • public, private, and session keys - anything encrypted with the public key can only be decrypted with the private key, and vice versa. After the secure connection is made, the session key is used to encrypt all transmitted data. 

Server Setup: (http://www.lwithers.me.uk/articles/cacert.html)

  1. In order for a server to handle SSL connections, it must activate SSL.
  2. Server will be prompted several question about identity of website or organization.
  3. Server generates the CSR (Certificate Signing Request). It contains the private key and a CSR data file.
  4. The CA uses the CSR data file to create a public key to match the private key.
  5. CA sends the SSL certificate.
  6. Server installs the SSL certificate. (http://www.digicert.com/ssl-certificate-installation.htm)

How it works:
  1. Browser connects to a web server secured with SSL (https). Browser requests that the server identify itself.
  2. Server sends a copy of its SSL Certificate (including the server’s public key), to assure the client that it can be trusted. The SSL Certficate was purchased from CA.
  3. Browser checks the certificate root against a list of trusted CAs and that the certificate is unexpired, unrevoked, and that its common name is valid for the website that it is connecting to. If the browser trusts the certificate, it creates, encrypts, and sends back a symmetric session key using the server’s public key. --- "SSL handshake"  
  4. Server decrypts the symmetric session key using its private key and sends back an acknowledgement encrypted with the session key to start the encrypted session.
  5. Server and Browser now encrypt all transmitted data with the session key.

Commands:

  • the default password is changeit
  • list certificates
    keytool -list -v -keystore [cacert location], ex. keytool -list -v -keystore cacerts.jks
  • list certificates to a text file
    keytool -list -v -keystore [cacert location] > [text file path]
    keytool -list -v -keystore "C:/Program Files (x86)/Java/jre6/lib/security/cacerts" > java_cacerts.txt
  • delete certificate (used when certificate is expired)
    keytool -delete -v -alias [alias] -keystore [cacert location], ex. keytool -delete -v -alias [alias] -keystore cacerts.jks
  • add certificate to cacert
    keytool -import -alias [alias name] -keystore  [cacert location] -file [cert to add path]
    keytool -import -alias Verisign -keystore  "C:/Program Files (x86)/Java/jre6/lib/security/cacerts" -file C:/bel/docs/certs/Verisign.cer


Source:
http://www.digicert.com/ssl.htm

Tuesday, April 23, 2013

Custom JSP tags

1) Make sure that the library for tags is in your classpath. servlet-api-2.3.jar supports it.
2) Create the tag class
   Ex.
   public class MyTag extends TagSupport
   public class HelloTag extends SimpleTagSupport
3) Create the tag libray descripto file and put anywhere inside WEB-INF directory
   Ex. WEB-INF/tld/myApp.tld
<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>2.0</jsp-version>
  <short-name>Example TLD</short-name>
  <tag>
    <name>Hello</name>
    <tag-class>com.tutorialspoint.HelloTag</tag-class>
    <body-content>empty</body-content>
  </tag>
</taglib>
4) Use the tag. You can also set uri in tld and use it as your uri in JSP page.
<%@ taglib prefix="ex" uri="WEB-INF/tld/myApp.tld"%>
<html>
  <head>
    <title>A sample custom tag</title>
  </head>
  <body>
    <ex:Hello message="This is custom tag" />
  </body>
</html>

Monday, June 18, 2012

Useful DB2 Queries

ALL TABLES:
select * from sysibm.systables

TABLE DESCRIPTION:
select * from sysibm.syscolumns where tbname = 'tableName'
- NOT VERY RELIABLE, SOME COLs MIGHT BE MISSING

or

select colname, typename, length, scale from syscat.columns
where tabschema = 'schemaName' and tabname = 'tableName'
- NOT VERY RELIABLE, SOME COLs MIGHT BE MISSING

or

describe table tableName - DOES NOT WORK :(

Note: Use SYSCAT views rather than the SYSIBM tables. Reason being is that from release to release the tables are being revised while DB2 development tries hard to keep the SYSCAT view signatures compatible. For this reason SYSCAT is being described in the SQL Reference while SYSIBM is not.

GET CURRENT DATE/TIME:
select current date from sysibm.sysdummy1
select current time from sysibm.sysdummy1
select current timestamp from sysibm.sysdummy1

Note: sysibm.sysdummy1 table is a special in-memory table that can be used to discover the value of DB2 registers

Sources:
http://www.databaseteam.org/9-db2/b4ac3f33bec9fb23.htm#.UfdJQ41OS6M
http://www.ibm.com/developerworks/data/library/techarticle/0211yip/0211yip3.html

Tuesday, May 22, 2012

Database Normalization

First Normal Form (1NF)
- no duplicate columns, e.g. teacher, student1, student2, student3
- no non-atomic columns, e.g. teacher, students
- rows must be have unique identifier (primary key), e.g. teacher, studentID, studentName

 Second Normal Form (2NF)
- satisfied 1NF
use foreign key (move subset of data/column that apply to multiple rows of a table to another table and connect them through the foreign key)
e.g.
studentID, studentName, courseID, courseName to
studentID, studentName, courseID and courseID, courseName

Third Normal Form (3NF)
- 2NF
- remove columns that are not dependent upon primary key
e.g.

Boyce-Codd Normal Form (BCNF or 3.5NF)

Fourth Normal Form

Tuesday, May 15, 2012

HTML

Complete list of HTML tags: http://www.w3schools.com/tags/default.asp

- HTML stands for Hyper Text Markup Language
- HTML is not a programming language, it is a markup language
- Practically speaking, there is no difference between the htm and html extensions
- In XHTML, all elements must be closed. Adding a slash inside the start tag, like
, is the proper way of closing empty elements in XHTML (and XML)
- HTML tags, attribute names and attribute values are not case sensitive but World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML. Newer versions of (X)HTML will demand lowercase attributes
- In XHTML, XML, elements with no end tag (closing tag) are not allowed
- attribute id vs name: id must be unique and is used as an identifier of an HTML element while name is used for form elements and form elements can share the same name
- HTML comment sample:
 <!-- This is a comment --> 
- The <center>, <font>, <basefont>, <s>, <strike> and <u> tags and align, bgcolor and color attributes are deprecated in HTML 4, and removed from HTML5. Style sheets (CSS) should be used to define the layout and display properties for many HTML element
- Always add a trailing slash to subfolder references. If you link like this: href="http://www.w3schools.com/html", you will generate two requests to the server, the server will first add a slash to the address, and then create a new request like this: href="http://www.w3schools.com/html/"
- HTML frames are obsolete in HTML5. Cons: http://webdesign.about.com/od/framesprosandcons/a/aaframesyuck_2.htm
- The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly. 
 <!-- This is a comment --> 

Reference: http://www.w3schools.com

Monday, July 25, 2011

Basic UNIX commands

  • man - manual/help
  • pwd - print working/current directory
  • ls - list files
  • ls -l - lists files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified
  • cd - change directory
  • mkdir [dir] - creates dir
  • rmdir [dir] - removes dir
  • more [options] file(s) - Display contents of files
  • less [options] file(s) - Display contents of files
    Useful commands while viewing a file with 'more' or 'less':
    • <spacebar> - scroll forward one page
    • ^b (control-b) - scroll backward one page
    • /<text> - search for string
    • n - find next occurence of string
    • N - find previous occurence of string (search for string in opposite direction)*
    • g - go to the beginning of the file*
    • G - go to the end of the file*
    • v - edit the current file with 'vi'*
    • :n - go to the next file*
    • :p - go to the previous file*
    • q - quit
    *works in 'less', not 'more'
  • grep [options] <pattern> [files] - search inside files for the given pattern
    Useful options:
    • -i - ignore case
    • -r or -R - search files in directories/subdirectories recursively
    • -v - nvert match: select non-matching lines
  • tail [options] [filenames] - show tail/end of file
  • tail -f temp.log - follow/monitor the file, display the last 10 lines of temp.log and append new lines to the display as new lines are added to temp.log
  • vi filename - edit the file
    Modes:
    • command mode - letters of the keyboard will be interpreted as commands
    • insert mode - letters of the keyboard will type or edit text
    Useful commands:
    • x - deletes the character the cursor is under
    • dd - deletes the line the cursor is on
    • a - append after the cursor
    • i - insert before the cursor
    • ESC - non edit mode
    • :wq - saves the current changes and exits vi
    • :w - saves the current changes but does not exit vi
    • :q - exits vi without saving any change

References:
http://claymore.rfmh.org/public/computer_resources/unix_commands.html
http://mally.stanford.edu/~sr/computing/basic-unix.html
http://cmgm.stanford.edu/classes/unix/vi.html
http://en.wikipedia.org
http://www.ccsf.edu/Pub/Fac/vi.html

Sunday, March 6, 2011

Deployment

  1. Create the package for full release
    1. Check out the Project in Eclipse
      1. Open SVN Repositories. Click Window->Open Perspective->SVN Repository Browser
      2. Assuming that you already have Repository Location set up, find the project in the trunk or branches
      3. Right click project then click Show History to ensure that it has the latest change/fix needed
      4. Tag or make a branch out of the project. Right click project then click New->Tag or Branch
      5. Right click newly created tag/branch then click Show History to ensure that the it has the latest change/fix needed
      6. Check out the newly created tag or branch. Right click project the click Check Out

    2. Build the package
      1. In the console, go to emea-pom of the checked out project
      2. Type
        mvn clean package –DemeaVersion=${currentversion}
      3. After a successful build, go to the emea-release project and copy the whole target folder in a different directory.

  2. Generate the config files/folders of the package
    1. Create a config folder inside the target folder or where the jar is located
    2. Create folders dev, sit, uat and prod inside config folder
    3. Open you FTP Client (e.g. FileZilla) and copy the config files to the newly created folders
      • DEV
      • SIT
      • UAT
      • PROD
    4. Update the ini file with the changes from project and change the VERSION property

  3. Deploy DEV using the exploded jar
    1. In FileZilla, upload/add target/classes/versions to /ams/domains/ACCTSVCS102/versions
    2. In FileZilla, copy target/config/dev to/ams/domains/ACCTSVCS102/versions/config
    3. On DEV WEBLOGIC, stop and delete previously deployed ear
    4. Open Putty and login to DEV (ehdeapp10v.uk.jpmorgan.com)
    5. Point latest to latest deployed version

      1. Go to /ams/domains/ACCTSVCS102/versions/biz-rules
      2. Type rm latest
      3. Type ln -s {newversionFolder} latest
      4. Do step 1-3 to config & emea folders as well

    6. On DEV WEBLOGIC, deploy new ear and start
    7. Delete temporary files

      1. Go to /ams/domains/ACCTSVCS102/scripts and type stop_all.sh
      2. Go to /ams/domains/ACCTSVCS102/servers/admACCTSVCS
      3. Delete tmp folder. Type rm -rf {folderName}
      4. Go to /ams/domains/ACCTSVCS102/servers/mngACCTSVCS
      5. Delete tmp & stage folder
      6. Go to /ams/domains/ACCTSVCS102/scripts and type start_all.sh

    8. Check server: DEV

  4. Copy package(jar) and config files to SIT (ehdeapp10v.uk.jpmorgan.com), /home/eis_dev/a_pfdv01/AMSNA

  5. Create JIRA

  6. Finish!

Thursday, January 20, 2011

Common DB2 SQLCODE

SQLCODE Description
-301THE VALUE OF INPUT HOST VARIABLE OR PARAMETER NUMBER position-number CANNOT BE USED AS SPECIFIED BECAUSE OF ITS DATA TYPE
-302THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE
-440THE NUMBER OF PARAMETERS IN THE PARAMETER LIST DOES NOT MATCH THE NUMBER OF PARAMETERS EXPECTED FOR STORED PROCEDURE name, AUTHID authid, LUNAME luname. number PARAMETERS WERE EXPECTED.
-551 auth-id DOES NOT HAVE THE PRIVILEGE TO PERFORM OPERATION operation ON OBJECT object-name


Complete list: http://www.caliberdt.com/tips/sqlcode.htm