A Simple Example of creating a Scheduled Job using Spring and Quartz

This example use the MethodInvokingJobDetailFactoryBean

Required Jars:

  • spring-core.jar
  • spring-beans.jar
  • spring-context.jar
  • spring-context-support.jar
  • spring-tx.jar
  • quartz-1.5.2.jar

Create the class that you want to be executed by the job (this should be your bussiness object)

package com.scheduler.job;

public class Jobs {
	public void processSomething(){
		System.out.println("execute processSomething()");
	}
}

Read the rest of this entry »

Spring Web Mvc with Annotation

Required Jars:

  • spring-core.jar
  • spring-beans.jar
  • spring-web.jar
  • spring-webmvc.jar
  • spring-context.jar


Configuration on WEB.XML :

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>App Name</display-name>

    <servlet>
        <servlet-name>app-name</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>app-name</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>

</web-app>

Read the rest of this entry »

Send and receive encrypted data between PHP and JAVA. part 2

previous post: Send and receive encrypted data between PHP and JAVA. part 1

Part2. Using public and private key to encrypt and decrypt data

Encrypt Decrypt using public and private key is called Asynchronus Encryption, which mean the key used to encrypt is different from the key used to decrypt, but both keys must be a pairs so they match to each other.
The point is, when we encrypt a message using a private key, so we only can decrypt that message with its public key, and when we encrypt a message using a public key, so we only can decrypt that message with its private key.
To create a private key and public key you can read my other article Common SSL Commands
Read the rest of this entry »

Send and receive encrypted data between PHP and JAVA. part 1

Part1. Using a secret key to encrypt and decrypt data

In this example we use AES-128 (rijndael-128) and CBC method, so we use a secret key and an initial vector key (iv key) to encrypt and decrypt data.

Encryption in JAVA

// The keys
String secretKey = "01234567890abcde";
String ivKey = "fedcba9876543210";

// Create key specs
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "AES");
IvParameterSpec ivSpec = new IvParameterSpec(ivKey.getBytes());

// the text that we want to encrypt
String plaintext = "this is the text that we want to encrypt in java";

// pad the string
String padded = padString16(plaintext);

// Instance the chipper
Cipher cipherEc = Cipher.getInstance("AES/CBC/NoPadding");

// init the chipper with key specs
cipherEc.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

// Encrypt the text
byte[] encrypted = cipherEc.doFinal(padded.getBytes());

// Encode the text with base 64
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(encoder.encode(encrypted));

Read the rest of this entry »

Integrating iBatis with Spring on Web Application

ibatis-config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<!-- Always ensure to use the correct XML header as above! -->
<sqlMapConfig>

   <settings
      cacheModelsEnabled="true"
      enhancementEnabled="true"
      lazyLoadingEnabled="true"
      maxRequests="128"
      maxSessions="24"
      maxTransactions="12"
      defaultStatementTimeout="60"
      useStatementNamespaces="true"
   />

   <!-- path is started from classpath (WEB-INF/classes/) -->
   <sqlMap resource="sqlmap/sqlmap-config.xml" />
</sqlMapConfig>

Read the rest of this entry »

←Older