Recent Notes
Displaying keyword search results 1 - 10
Created by Dr. Xi on May 02, 2011 15:59:37
Last update: February 25, 2012 09:16:37
This code snippet gets the default keystore used by the Java keytool and displays the list of aliases along with the key type (certificate or private key).
import java.io.File;
import java.io.FileInputSt...
The default keystore used by the above code is: $HOME/.keystore .
Created by freyo on May 20, 2011 09:25:20
Last update: May 23, 2011 12:11:42
The javax.xml.crypto and javax.xml.crypto.dsig packages are not available in Android (as of version 2.3). Therefore, standard Java API does not work. But you can use the Apache Santuario library to do that. Here are the steps:
Download the xml security source distribution (curently version 1.4.4).
Build with ant.
Create your own library jar (only the apache classes, no javax):
jar -cf xmlsec-1.4.4.jar -C build/classes org
Copy xmlsec-1.4.4.jar to the libs directory of your Android project.
Here's the Java code:
import java.io.*;
import javax.xml.parsers.*;
...
Created by alfa on April 08, 2011 11:05:24
Last update: April 08, 2011 11:05:24
Key points:
Use java.awt.Robot to capture a screen region as java.awt.image.BufferedImage .
Use javax.imageio.ImageIO to write image out to a file.
import java.awt.AWTException;
import java.awt.R...
Created by Dr. Xi on April 05, 2011 08:04:37
Last update: April 05, 2011 08:11:37
There's no difference between a Java HTTP client and a Java HTTPS client. Ignore JavaWorld Java Tip 96 , it's way too old. The following code gets an HTTP page as well as an HTTPS page.
import java.io.*;
import java.net.*;
pub...
There's one catch . If you are using the code on a test server with a self-signed certificate, it fails. In that case, I would suggest that you download the certificate from the server and import it to your keystore as a trusted key. You may also need to add a subject alternative name to the certificate if the host name does not match the certificate.
You may also choose to use a custom TrustManager and HostnameVerifier to ignore the certificate verification errors.
Created by Dr. Xi on October 16, 2008 20:45:40
Last update: March 28, 2011 20:23:22
Java's built-in classes are way too complex/flexible for a simple protocol like HTTP. This is a wrapper to simplify HTTP GET and POST.
import java.io.*;
import java.net.*;
imp...
A simple test:
import java.io.*;
import java.util.*;
...
Created by Dr. Xi on October 26, 2010 16:07:40
Last update: October 26, 2010 16:07:40
This is a more generic version, which can be expanded to accommodate additional file signatures.
import java.io.*;
import java.util.*;
pu...
Created by Fang on August 03, 2010 19:50:51
Last update: August 03, 2010 19:50:51
The tags <fmt:message> Writes out a formatted message for the current locale and resource bundle, or stores the resulting message to a scoped variable (when the var attribute is specified). Syntax:
<fmt:message key="messageKey" [bundle="resourc... Or, with parameters in body: <fmt:message key="messageKey" [bundle="resourc... <fmt:bundle> Creates a resource bundle for the contained body. Syntax: <fmt:bundle basename="basename" [prefix="prefi... <fmt:setBundle> Sets a resource bundle in a scoped variable, which may be used later by <fmt:message> . Syntax: <fmt:setBundle basename="basename" [var="varNa... <fmt:param> This is used inside a <fmt:message> tag to specify a replacement parameter. <fmt:param value="theParameterValue"/> or <fmt:param>The Parameter Value</fmt:param> Test it Make these additions to the expanded test application : Create 3 resource bundles and place them under src\main\resources . messages_en.properties : label.login=Login label.username=User Name ... messages_es.properties :...
Created by Dr. Xi on July 19, 2010 21:58:34
Last update: July 23, 2010 21:37:23
Parsing XML in Java is really simple:
import java.io.*; import javax.xml.parsers.Docu... The parser implementation details are hidden behind the JAXP API. In case you want to know which parser implementation is used, this is what the JavaDoc for DocumentBuilderFactory.newInstance says: Use the javax.xml.parsers.DocumentBuilderFactory system property. Use the properties file " lib/jaxp.properties " in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to...
Created by Fang on April 04, 2010 04:12:14
Last update: July 21, 2010 14:52:58
The tags <c:if> The <c:if> tag may be used with or without body content:
<!-- Without body content, used to export vari... In my opinion, the version without body content is pretty much useless (the <c:set> tag is a lot more meaningful for this purpose). If body content exists, it is inserted into the page if the testCondition is true . Optional attributes var and scope may be specified. If var is specified, a variable whose name is the value of var is exported to the associated scope ( pageScope if no scope is specified). The type of the exported variable is Boolean and its value is the value of the testCondition . <c:choose>, <c:when>, <c:otherwise> These tags imitate the Java control structure if...else...
Created by Dr. Xi on June 20, 2010 14:35:17
Last update: June 20, 2010 14:35:17
This XML signature validator comes from the Apache XML Security project. It validates the signature according to the core validation processing rules .
It does not verify that the key used to generate the signature is a trusted key. You can override the KeySelector class to make sure that the signing key is from a trusted store.
import javax.xml.crypto.*;
import javax.xml.cry...