Notes by Fang
Displaying notes 1 - 10
Created by Fang on April 17, 2013 08:50:04
Last update: April 17, 2013 08:50:04
I got HTTP status 406 even with explicit Accept header like this:
curl -x localhost:8088 -H 'Accept: application/jso...
The root cause was that I forgot to include Jackson JSON lib in the dependencies.
Solution: add this to pom.xml
<dependency>
<groupId>org.codehaus.jackson</gr...
Created by Fang on March 30, 2012 10:07:25
Last update: March 08, 2013 13:41:57
After a user resets a password, I want to force the user to change the password before she gets access to secured content. This is usually done with a servlet filter. But with Spring MVC, you can also use a HandlerInterceptor . According to Spring JavaDoc: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow for exchanging the request and response objects that are handed down the chain. Note that a filter gets configured in web.xml, a HandlerInterceptor in the application context. As a basic guideline, fine-grained handler-related preprocessing tasks are candidates...
Created by Fang on January 14, 2013 14:00:36
Last update: January 14, 2013 14:00:36
Cause: Hibernate reverse engineering generated a column mapping like this:
@Version
@Column(name="VERSION", nullable=false...
Fix: change the mapping to:
@Column(name="VERSION", length=20)
public Strin...
Created by Fang on January 04, 2013 14:35:14
Last update: January 04, 2013 14:35:41
You can use the runOrder parameter to control the test execution order for Maven surefire tests:
<build>
<plugins>
<plugin>
...
Other options are:
Option Meaning
alphabetical Alphabetical
reversealphabetical Reverse Alphabetical
random Randomized
hourly alphabetical on even hours, reverse alphabetical on odd hours
failedfirst Failed first will run tests that failed on previous run first, as well as new tests for this run.
balanced Balanced is only relevant with parallel=classes, and will try to optimize the run-order of the tests to make all tests complete at the same time, reducing the overall execution time.
filesystem This is the default. I guess this is the order returned by the file system: uncontrolled but deterministic.
Created by Fang on January 04, 2013 14:16:58
Last update: January 04, 2013 14:16:58
Junit does not support specifying execution order of tests until 4.11. The methods were simply invoked in the order returned by the reflection API. So, the tests are executed in a unspecified but deterministic order, i.e., you have no control over the order of execution, but if you repeat the tests, they are run in the same sequence each time. For version 4.11, you can specify the order with the FixMethodOrder annotation:
import org.junit.runners.MethodSorters; imp... From the release notes : Test execution order By design, JUnit does not specify the execution order of test method invocations. Until now, the methods were simply invoked in the order returned by the reflection API. However, using the JVM order is unwise since the Java platform does not specify...
Created by Fang on January 04, 2013 09:02:44
Last update: January 04, 2013 09:02:44
This snippet sets system properties from Maven surefire test plugin. This is useful when you want to set logging (for example, log4j) properties based on Maven project properties.
Example that sets system property testlog.dir :
<plugins>
<plugin>
<groupId>org.apach...
Example log4j.xml that uses system property testlog.dir :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYP...
Created by Fang on January 04, 2013 08:00:37
Last update: January 04, 2013 08:00:37
This is a Maven POM that prints out some built-in project properties:
<project
xmlns="http://maven.apache.org/PO...
Output:
$ mvn validate
[INFO] Scanning for projects.....
Created by Fang on October 31, 2011 12:54:05
Last update: October 23, 2012 12:31:16
In JSP you output the web application context path with:
${pageContext.request.contextPath}
Facelets are not JSPs, and there's no pageContext . So the above does not work.
But in facelets you can use request directly:
${request.contextPath}
For example, a link to the root URL:
<a href="${request.contextPath}">Home</a>
Servlet request URL:
<h2>#{request.requestURL}</h2>
Created by Fang on September 22, 2012 08:25:20
Last update: September 22, 2012 08:25:20
DataGenetics has an analysis of the most frequently used PIN codes and least frequently used PIN codes. The list is copied below. Most Frequently Used PIN codes Rank PIN Frequency #1 1234 10.713% #2 1111 6.016% #3 0000 1.881% #4 1212 1.197% #5 7777 0.745% #6 1004 0.616% #7 2000 0.613% #8 4444 0.526% #9 2222 0.516% #10 6969 0.512% #11 9999 0.451% #12 3333 0.419% #13 5555 0.395% #14 6666 0.391% #15 1122 0.366% #16 1313 0.304% #17 8888 0.303% #18 4321 0.293% #19 2001 0.290% #20 1010 0.285% Least Frequently Used PIN codes Rank PIN Frequency #9980 8557 0.001191% #9981 9047 0.001161% #9982 8438 0.001161% #9983 0439 0.001161% #9984 9539 0.001161% #9985 8196 0.001131% #9986 7063 0.001131% #9987 6093 0.001131% #9988 6827 0.001101%...
Created by Fang on July 25, 2012 12:52:40
Last update: September 14, 2012 13:37:57
Summarized from official JAX-WS documentation : Sending and Receiving SOAP Headers To send a SOAP header:
HelloService helloService = new HelloService(); ... To receive a SOAP header: List<Header> inboundHeaders = bp.getInboundHeaders... Message logging On the client side, set system property: com.sun.xml.ws.transport.http.client.HttpTransport... On the server side, set system property: com.sun.xml.ws.transport.http.HttpAdapter.dump=tru... Propagation of Server-side Stacktrace Propagation of Stack trace is on by default. The whole stacktrace (including nested exceptions) is propagated in the SOAP Fault and the complete exception stacktrace is visible to the client as cause of SOAPFaultException . To turn off stack trace propagation, set this system property on the server: com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptu... Update: At least on the client side, the property name has been changed to: com.sun.xml.internal.ws.transport.http.client.Http... The messages are dumped to stdout . For...