Saturday, January 30, 2016

ImageCrawler/WebCrawler for A WebSite

The ImageCrawler/WebCrawler Application is developed to crawl any WebSite to find out missing content or images. This is developed based on Search Algorithm, and has two Versions of Code in it.
One  Version  for using Selenium, which takes screenshots of the error page URLs, and another version runs in the background using a shell script and captures all the page URLs. The end results are emailed to the recipient's list.

Feel free to use it, the code is available for download on Git. Let me know Your feedback.

https://github.com/kanaparthikiran/ImageCrawler

Wednesday, July 15, 2015

Find the Source Jar of a Class file in Java

/**
*
* Gets the Source Jar File Location for the given Class,
* Useful to troubleshoot Class Related Exceptions/Errors.
* @param className
* @return
*/
public String getClassSourceJar(String className) {
 Class namedClass = null;
 String classSrcJarLocation = null;
try {
namedClass = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("The Requested Class is Not Found "+className);
}
CodeSource src = null;
if(namedClass!=null) {
src = namedClass.getProtectionDomain().getCodeSource();
 if(src!=null) {
 URL jar = src.getLocation();
 if(jar!=null) {
 classSrcJarLocation = jar.toString();
 }
 }
}
 return classSrcJarLocation;
}

Thursday, July 17, 2014

Adding SOAP Headers for JAX-WS Client

After trying various options none seem to be apt. I could add the Headers using this JAX-WS approach.

wsimport -keep -verbose -XadditionalHeaders https:// Your Web Service.asmx? WSDL

When You generate the WebService Clients using "XadditionalHeaders" option, it will create the web service methods with the Header as another Parameter, which You can populating using the values You have.

I could not find a better option than this. Other Approaches I tried were - Adding a JAX-WS ClientHandler class ,and using a SAAJ client altogether. Reference - JAXWS Implementation.


https://jcp.org/en/jsr/detail?id=224

Tuesday, November 20, 2012

Cryptography

Symmetric Encryption vs Asymmetric Encryption

Symmetric Encryption works by encrypting a message file by using a private key. The content can be decrypted using the same private key. If both the parties have the same key then only the message can be encrypted/decrypted.
Asymmetric Encryption works with the public key and private key combination.Any message/file encrypted using a public key can only be decrypted using the related private Key. Similarly the message which is encrypted using a private key key can only be decrypted using the related public key.

Digital Certificates is  a way of storing the keys and authenticating them through a neutral vendor, like Thawte, Symantec.


Tuesday, November 13, 2012

Hibernate Locking Strategies


Association Fetching

We can fetch the associated entities wither eagerly or lazily. The fetch parameter can be set to FetchType.LAZY or FetchType.EAGER. EAGER tries to use outer join select to retrieve the associated object, while LAZY is triggers a select when the associated object is accessed for the first time. @OneToMany and @ManyToMany are defaulted to LAZY, and @OneToOne and @ManyToOne are defaulted to EAGER. The recommended approach is to use LAZY on all static fetching definitions and override this choice dynamically through JP-QL. JP-QL has a fetch keyword that allows you to override laziness when doing a particular query. This is very useful to improve performance and is decided on a use case to use case basis.

Named Queries

Though we can write queries in the code, externalizing them makes the code cleaner. - it eases debugging - Named queries are precompiled by Hibernate at start up time. Unfortunately, you lose the type-safety of queries written using the Criteria API.


Hibernate Locking Strategies
Optimistic Locking

Optimistic locking is a technique where you allow your application to perform updates hoping there won't be any simultaneous updates from another process, hence optimistic. Pessimistic locking is the technique where you assume there will be simultaneous updates from another process so you lock the data you are changing before any changes take place.
In Hibernate, optimistic locking is provided fairly seemlesly. You add a version field to your table and a version element to your mapping file. When you update a Hibernate object Hibernate will check the version values match. If they do the update is successful, and the version is incremented, if they are not Hibernate throws a StaleObjectException and you know that something else has updated your data. 


Pessimistic Locking'


Pessimistic locking is provided by specifying a LockMode when you get an object from the database. If you get your object with the LockMode.UPGRADE for example Hibernate will use database specific SQL to lock the record (if your database supports it) such as "select ... for update". Now nothing can update that record till you are finished.


Hibernate Fetching Strategies

Pessimistic Concurrency Control 

Hibernate assumes that two or more users want update the same record at the same time, so it prevents that by placing locks on the records. The lock is placed as soon as the any piece of row is accessed. other users might be able to read the data even though a lock has been placed.

Optimistic Concurrency Control

Instead of placing the lock on the whole record every time that is read, the system merely looks for an indication that two users actually did try to update the same record at the same time. If that evidence is found , then one user's updated are discarded and the user is informed. Hibernate maintains this using version on the columns. Each time the server reads a record to try to updates the server makes a copy of the version number of the record and stores that copy for later reference. When it is time to update the data back to the disk, the server compares the original version number that is read against the version number that the disk drive now contains. - a) If the version numbers are the same, no one else changed the record and the system can write the updated value. b) If the Originally read value and the current value on the dist are not the same, then someone changed the data since it was read, and the current operation is probably out of date. Thus the system discards the version of the data and gives the user an error message. Each time a record is updated, the version number is updated as well.

Sunday, August 26, 2012

Tomcat Configuration


1) Stop/Start tomcat in one step This step will enable the users to stop and start tomcat in a single step. shutdown.bat && startup.bat

Tuesday, August 21, 2012

Databasse Interview Questions


1) Delete vs Truncate vs Drop Delete deletes all/ a few the records of the table. Truncate deletes all the records of the table, where as drop deletes the table and any indexes,privileges associated with the table. Delete is a DML operation, takes more time as it can be rolled back so will store the data in the undo space where as Truncate and Drop are DDL statements and can not be rolled back, so they are faster. From Oracle 10 the database tables can be undroppped. FLASHBACK TABLE TABLE_NAME TO BEFORE DROP;
2) SQL Joins can be classified into Equi join and Non Equi join. 1) SQL Equi joins It is a simple sql join condition which uses the equal sign as the comparison operator. Two types of equi joins are SQL Outer join and SQL Inner join. For example: You can get the information about a customer who purchased a product and the quantity of product. 2) SQL Non equi joins It is a sql join condition which makes use of some comparison operator other than the equal sign like >, <, >=, <=
STORED PROCEDURE VS FUNCTION
IN functions we can not alter database records., can not use statements like insert, update, or delete. However we can perform the same functions in a stored procedure, so use stored procedure when the statements involve these kind of operations. Unlike stored procedures functions can be used to inline in SQL statements, other functions or in procedures so use it when you need to compute some value that will be later used in some SQL statement. Both stored procedure and function can be used to achieve the same goal.


3) Select top 3 rows/ select top row/ select row with maximum value/frequency
Suppose the table named, STREET is like below.

55 2ndstreet 555 57
59 2ndstreet 555 61
63 2ndstreet 555 22
65 1ststreet    555  21
67 2ndstreet 555 69
73 2ndstreet 555 75
77 3rdstreet 555 79
81 2ndstreet 555 83
105 4thstreet 555 107
133 2ndstreet 555 135

This Query gives the maxim/max frequently occuring column.
Query

select *  from (select street_name,count(street_name) from street group by street_name order by count(street_name) desc)  where rownum=1;