This is a decision chart that I found on the internet, which shows how response codes are identified. Will be helpful if someone is trying to triage response codes issues.
Please Download this image and Zoom to see the details.
Standard Annotation : Are applied to regular java classes, methods and statementsMeta Annotations: Applied to annotation definition to describe the behavior of the annotation being declared and how it can be used.
These are annotations used when defining an annotation@Retention : When are the annotations loaded into the JVM
@Target : Elements of the Java class to which annotation is applicable
If an Inherited meta-annotation is pre sent on an annotation type declaration, and the user queries the annotation type on a class declaration, and the class declaration has no annotation for this type, then the class's superclass will automatically be queried for the annotation type
This process will be repeated until an annotation for this type is found, or the top of the class hierarchy (Object) is reached. If no superclass has an annotation for this type, then the query will indicate that the class in question has no such annotation.@Inherited Example:
@Target(ElementType.METHOD, ElementType.CLASS) @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface changelog { String author() default "author" ; // Annotation member String date(); // Annotation member } @changelog(author="vidhya", date="30/11/2012") public class superclass { } public class subclass extends superclass { }
When subclass is queried for ChangeLog annotation, it will be successful as the changelog annotation is @inherited.@Documented: If a type declaration is annotated with Documented, its annotations become part of the public API of the annotated elements.
Each annotation must be defined by an annotation interface. The methods of the interface correspond to the elements of the annotation.
@Target(ElementType.METHOD, ElementType.CLASS) @Retention(RetentionPolicy.RUNTIME) Public @interface ChangeLog { String author(); // Annotation member String date(); // Annotation member }3 Types of annotation Definition
1. Marker - No Parameters, just used to denote a type. @Test in Junit 1.4 onwards
2. Single Value Annotation - This contains just one value @name("Single Value")
3. Multiple parameter annotation - has many parameters @user(id="1234", name="user1")
//Defined Annotation@ChangeLog(author="user1", date="10/10/2012")public class MyTest { @ChangeLog(author="user2", date="20/08/2012") @TestCase public void test1() } // The Annotation Reader import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class AnnotationTest { public static void main( String[] args ) throws Exception { //access the class annotation Class clazz = MyTest.class; System.out.println( clazz.getAnnotation(ChangeLog.class ) ); //access the method annotation Method method = clazz.getMethod( "test1" ); ChangeLog changelog = (ChangeLog) method.getAnnotation(ChangeLog.class); System.out.println("--- Changelog Author:"+changelog.author()"); } }
package test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerTest
{
public static void main(String args[])
{
Logger logger = LoggerFactory.getLogger(LoggerTest.class);
logger.info("Testing slf4j");
}
}
1 [main] INFO test.LoggerTest - Testing slf4j
How is Logback Special to slf4j?
Logback has a direct implementation of Slf4j. If we want to plug this in, a slf4j wrapper jar file is not needed. Logback's ch.qos.logback.classic.Logger class is a direct implementation of SLF4J's org.slf4j.Logger interface. Thus, using SLF4J in conjunction with logback involves strictly zero memory and computational overhead.
Famous slf4j binding dependencies To bind the logging frameworks we may have to include the slf4j binding dependencies to plugin. If you have multiple plugins, the 1st in the order of compiler dependency is picked up. The good thing about slf4j is, it resolvs the logging plugin at compile time. Below are the slf4j wrappers fof different logger
slf4j-log4j12-1.7.2.jar LOG4j slf4j-jdk14-1.7.2.jar Util Logging slf4j-simple-1.7.2.jar SIMPLE slf4j-jcl-1.7.2.jar JCL Diagram showing SLF4J binding and respecting jarsReferences:FAQs: http://slf4j.org/faq.htmlManual : http://slf4j.org/manual.html
| Command | Description |
| crontab -e | edit or create a crontab file |
| crontab -i | list the crontab contents |
| crontab -r | remove the crontab settings |
| crontab -v | Last time the crontab was changed |
| Min | Hours | Day | Month | Day of week | Command | Description |
| 30 | 13 | * | * | * | echo 'Executes at 1:30 PM everyday' | Executes at 1:30 PM everyday |
| 30 | 13 | 1 | 1 | * | echo 'Executes on Jan 01 at 1:30 PM' | Executes on Jan 01 at 1:30 PM |
| 30 | 13 | 1 | * | * | echo 'Executes on 1st of every month at 1:30 PM' | Executes on 1st of every month at 1:30 PM |
| 30 | 13 | * | * | 1-5 | Executes on all weekdays(Monday-Friday) at 1:30 PM | Executes on 01 of every month at 1:30 PM |
| */5 | * | * | * | * | echo 'Executes every 5 mins' | Executes every 5 mins |
| * | */5 | * | * | * | echo 'Executes every 5 hours' | Executes every 5 hours |
| DES (Data Encryption Standard) | Old Crypto algorithm. 64 Bits, 56 are effectively used, easy to break.3DES - derived from DES, works by cascading 3 instances of DES. This is slow |
| 3DES | derived from DES, works by cascading 3 instances of DES. This is slow |
| AES (Advanced Encryption Standard) | Successor of DES. Accepts 128, 192, 256 bits. When in doubt use AES. This is supported after JDK 1.4 onwards |
| Encryption Code | Decryption Code |
| Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes())); return encryptedString; | Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING"); SecretKeySpec secretKey = new SecretKeySpec(key, "AES"); cipher.init(Cipher.DECRYPT_MODE, secretKey); String decryptedString = new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt))); return decryptedString; |
package cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.codec.binary.Base64;
public class CipherUtils
{
private static byte[] key = {
0x74, 0x68, 0x69, 0x73, 0x49, 0x73, 0x41, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x4b, 0x65, 0x79
};//"thisIsASecretKey";
public static String encrypt(String strToEncrypt)
{
try
{
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
final String encryptedString = Base64.encodeBase64String(cipher.doFinal(strToEncrypt.getBytes()));
return encryptedString;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public static String decrypt(String strToDecrypt)
{
try
{
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
final String decryptedString = new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt)));
return decryptedString;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
public static void main(String args[])
{
CommandLineParser parser = new PosixParser();
Options options = new Options();
Option help = new Option("help", "Display help");
Option encrypt = new Option("encrypt", true, " - string to encrypt");
Option decrypt = new Option("decrypt", true, " - string to decrypt");
options.addOption(help);
options.addOption(encrypt);
options.addOption(decrypt);
try
{
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("encrypt"))
{
final String strToEncrypt = cmd.getOptionValue("encrypt");
final String encryptedStr = CipherUtils.encrypt(strToEncrypt.trim());
System.out.println("String to Encrypt : " + strToEncrypt);
System.out.println("Encrypted : " + encryptedStr);
}
else if (cmd.hasOption("decrypt"))
{
final String strToDecrypt = cmd.getOptionValue("decrypt");
final String decryptedStr = CipherUtils.decrypt(strToDecrypt.trim());
System.out.println("String To Decrypt : " + strToDecrypt);
System.out.println("Decrypted : " + decryptedStr);
}
else
{
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("[-h] [-encrypt ]", options);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Dependencies:
Required: commons-cli 1.2 and commons-codec 1.7
Eclipse Maven project to run this
https://www.dropbox.com/s/rg8tfz1mf592b92/cipher-project.zip