Displaying keyword search results 1 - 12
Created by Dr. Xi on April 29, 2013 09:00:48 Last update: April 29, 2013 09:00:48
In the case proposed by Diony , signing multiple elements by id, simply change the newSignedInfo to:
// Create the SignedInfo final List transforms0...I must admit that I don't understand transformations, so take my example code with a grain of salt. Also, signing a doc fragment by PATH does not work, simply because there's no way to identify the fragment with a URI without referring to it by id. Reference ode from org.jcp.xml.dsig.internal.dom.DOMURIDereferencer :
// Check if same-document URI and register...
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 January 14, 2010 00:28:27 Last update: March 30, 2011 15:37:44
A task that a Java developer does so frequently is to find out where a certain class can be found - to resolve compilation errors, classpath issues, or version conflicts of the same class introduced by multiple class loaders. A long while back I wrote a simple Perl script to perform the task. Later I was informed that there are Swing based Jar Browser and Jars Browser . Then, there are a couple of shell one-liners:
# one liner 1 find -name "*.jar" -print0 | xarg...But all of them share the same problem: if a class is in a jar nested in another jar, it cannot be found. Such is the case for a class inside a jar under the WEB-INF/lib directory of a...
Created by woolf on February 10, 2011 13:16:34 Last update: February 10, 2011 13:16:49
%PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of " str1 " in the expanded result with " str2 ". " str2 " can be the empty string to effectively delete all occurrences of " str1 " from the expanded output. " str1 " can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first occurrence of the remaining portion of str1. %PATH:~10,5% would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value. If either number (offset or length) is negative,...
Created by Dr. Xi on August 27, 2010 22:35:53 Last update: August 27, 2010 22:35:53
This example decompresses a gzip compressed file with java.util.zip.GZIPInputStream . The input is assumed to be Base64 encoded after being gzipped (such would be the case when binary data is transmitted within an XML file). You don't need the Base64InputStream if the data is not Base64 encoded.
import java.io.*; import java.util.zip.GZIPInpu...
Created by Fang on August 23, 2010 22:55:58 Last update: August 24, 2010 15:45:04
The tags XML flow control tags are exactly the same as their Core flow control equivalents, except that the test condition with a boolean EL expression is replaced by the select condition with an XPath expression. In the case of the forEach tag, the items attribute is replaced with the select attribute. In a test condition, the XPath expression is evaluated to a boolean value by the rules of the XPath boolean() function, which converts its argument to a boolean as follows: a number is true if and only if it is neither positive or negative zero nor NaN. a node-set is true if and only if it is non-empty. a string is true if and only if its length is non-zero. an object of...
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 Dr. Xi on June 19, 2010 04:34:01 Last update: June 19, 2010 04:39:13
Java SE 6 contains built-in utilities to generate XML signatures. This is an example that generates XML signatures using a Java keystore. It has options to generate signature for the whole document, for an element with a specific ID, or for elements matched by an XPATH expression. The XML document used to test is taken from Getting Started with XML Security :
<?xml version="1.0"?> <PatientRecord> ...This is the Java code:
import java.io.FileInputStream; import java.io....However, it looks like the XPATH transform is not working. The digest generated with XPATH filter is exactly the same as that without it (i.e., the whole document)! Another reference: Programming With the Java XML Digital Signature API
Created by Dr. Xi on January 07, 2010 23:40:28 Last update: February 09, 2010 03:24:35
This is a utility to generate SQL insert statements for Oracle for one table, or a set of tables. It doesn't cover all possibilities but should be good enough for most cases.
import java.io.*; import java.sql.*; import ...To generate insert statements for multiple tables, simply put the table names in a file, one per line, and use the -f switch.
Created by Dr. Xi on November 19, 2008 00:22:27 Last update: January 07, 2010 23:00:36
There is a open source project named [ini4j] for processing Windows .ini configuration files. However, I found it an overkill for my purposes. So here is my simple implementation of a .ini parser. It mimics the standard java.util.Properties class with enhancements to get and set properties by section name. There are only a few simple rules: Leading and trailing spaces are trimmed from section names, property names and property values. Section names are enclosed between [ and ] . Properties following a section header belong to that section Properties defined before the appearance of any section headers are considered global properties and should be set and get with no section names. You can use either equal sign ( = ) or colon ( : )...
Created by James on August 10, 2009 04:02:25 Last update: August 10, 2009 04:16:31
Function Description Examples length This is actually a property. 'abcd'.length == 4 charAt(int) Return character at given index 'abcd'.charAt(2) == 'c' (index starts from 0) indexOf(string) Return first index of given string 'abcdcdcd'.indexOf('cd') == 2 lastIndexOf(string) Return last index of given string 'abcdcdcd'.lastIndexOf('cd') == 6 substring(beginIndex, endIndex) Return substring starting from beginIndex and ending at endIndex 'abcdcdcd'.substring(1, 3) == 'bc' 'abcdcdcd'.substring(1, 300) == 'bcdcdcd' split(string) Split string into array of strings using given string as delimiter '/home/jsmith/download/js/'.split('/') == ['', 'home', 'jsmith', 'download', 'js', ''] toLowerCase() Convert string to lower case 'AbCd'.toLowerCase() == 'abcd' toUpperCase() Convert string to upper case 'AbCd'.toUpperCase() == 'ABCD'