Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on August 15, 2012 12:05:39    Last update: August 15, 2012 12:05:39
Use OpenSSL's s_client command to fetch a page manually: $ openssl s_client -connect localhost:443 -state -... Sample session for Google: $ openssl s_client -connect www.google.com:443 -st... Resource: SSL/TLS Strong Encryption: FAQ
Created by Fang on February 27, 2012 12:19:19    Last update: February 27, 2012 12:19:19
Mapping Java objects to Jackson JSON is pretty simple. But if you name a JSON field wrong, you'll get the "Unrecognized field ... (Class ...), not marked as ignorable" error. The rule for mapping a Java bean attribute name to a JSON field name is: lower all leading capital letters until the first lower case letter . For example, this Java class: package com.example; public class Person { ... maps to this JSON string: { "firstName": "Jane", "lastName": "... Test code: package com.example; import java.net.URL; ...
Created by nogeek on November 03, 2010 20:52:49    Last update: November 23, 2011 08:54:44
My problem is simple: in my XML data, a timestamp is provided as a long integer (number of milliseconds since the "the epoch"). When I do XSLT, I want to display it as a readable string, such as "Mon Nov 01 18:08:48 CDT 2010". After hours of struggle, I found: It's not so easy to get the job done with JDK 1.6 There are tons of garbage on the web in this space (suggestions, code snippets that simply don't work) Simple Xalan extension functions was the only resource that's somewhat informative. Even there some of the examples don't work. Below is a list of what worked and what didn't. This works: <xsl:stylesheet version="1.0" xmlns:xsl="h... This does not (providing long value to Date constructor): <xsl:stylesheet version="1.0" xmlns:xsl="h......
Created by Fang on November 10, 2011 20:33:46    Last update: November 10, 2011 20:33:46
The stack trace is like this: java.lang.IllegalArgumentException: Component prop... You get this error because you are using the class attribute with a JSF UI component, for which the class attribute cannot be altered. Of course you meant CSS class, not Java class! You can use the styleClass attribute instead of the class attribute. The styleClass attribute becomes the class attribute when the component is rendered. If you can add a tag handler to the UI component, you can alias class to styleClass , which will allow you to use the class attribute on the UI component: import javax.faces.view.facelets.*; pub...
Created by Fang on October 22, 2011 19:51:05    Last update: October 22, 2011 20:31:48
I built a very basic JSF application and deployed to Tomcat 7.0.22, but it failed with this error: Caused by: java.lang.ClassFormatError: Absent Code... That looks weird and I wasn't able to find a sensible explanation! So I copied the jsf-api-2.1.jar , which was downloaded from the java.net Maven repository by Maven, into a temp folder. And tested it with this simple program: public class ClassFormatErrorTest { public ... I also copied servlet-api.jar from Tomcat's lib folder to the temp folder. Sure enough it failed with the same error: C:\tmp>java -cp .;jsf-api-2.1.jar;servlet-api.jar ... But when I replaced the javax.faces.webapp.FacesServlet class with one I compiled from source, the error disappears! Conclusions: The jar file jsf-api-2.1.jar from java.net Maven repository is good for compilation only (cannot be used...
Created by freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by Dr. Xi on July 11, 2011 12:24:10    Last update: July 11, 2011 12:25:44
This code snippet import java.util.*; public class UncheckedCast ... fails with a compilation error and a warning: $ javac -Xlint:unchecked UncheckedCast.java Unc... Because List<String> is not a reifiable type, the Java Runtime does not have enough information to verify the type or do the type casting. This is fixed by changing List<String> to List<?> (or to the raw type List ): public static void main(String[] args) { Ob...
Created by Dr. Xi on June 27, 2011 13:12:36    Last update: June 27, 2011 13:12:36
Parameterized types are considered different at compile time but not at runtime. This program fails compilation because List<Foo> is not the same as List<Bar> : import java.util.ArrayList; import java.util.Li... Error: $ javac SameErasure.java SameErasure.java:8: do... This also fails because List<Foo> and List<Bar> are considered the same: import java.util.ArrayList; import java.util.Li... Error: $ javac SameErasure.java SameErasure.java:11: n...
Created by freyo on May 17, 2011 11:13:17    Last update: May 17, 2011 11:13:17
This is an odd-ball content provider in that it doesn't provide database records, but provides a resource as a stream. It can be used to provide media files or XML resources. Start the project with: tools/android create project --package com.android... Create assets directory and add an XML file ( assets/demo.xml ): <? xml version="1.0" encoding="UTF-8"?> <people... Edit the layout ( res/layout/main.xml ): <?xml version="1.0" encoding="utf-8"?> <LinearL... Edit src/com/android/cptest/Dummy.java : package com.android.cptest; import java.io.... Add content provider ( src/com/android/cptest/XmlResource.java ): package com.android.cptest; import java.io.... Update AndroidManifest.xml : <?xml version="1.0" encoding="utf-8"?> <manifes... Add this section to the end of build.xml : <target name="-package-resources"> <ech... Build and install: ant install Screenshot: Remove the Dummy activity ( AndroidManifest.xml ): <?xml version="1.0" encoding="utf-8"?> <manifes... Create a new project for...
Created by jinx on April 29, 2011 15:03:10    Last update: April 29, 2011 15:04:02
The PHP function is_callable verifies that a variable can be invoked as a function. Example: <?php define('F', 'f'); function... Output: var_dump: string(1) "f" is_callable: 1 Calla...
Previous  1 2 Next