Notes by Fang

Displaying keyword search results 1 - 10
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 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 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:59:47    Last update: July 25, 2012 12:59:47
Example code: import javax.xml.ws.BindingProvider; import jav... Wierdly, even though the response context ( ctx ) itself is a Map, you cannot iterate through the keys. This: for (String key: ctx.keySet()) { logger.inf... fails: WARN : InternalError - Handler execution resulted ...
Created by Fang on March 30, 2012 15:04:04    Last update: March 30, 2012 15:04:04
Spring MVC 3.1 can send either JSON or HTML response on the same URL, depending on the type of response requested. With this mechanism, a page can be sent when directly requested from a link, but a JSON response can be sent in response to an AJAX request. This is the controller code: package com.example; import java.util.Map; ... In the above example, JSON response will be sent when the HTTP request contains header "Accept: application/json". HTML response will be sent then the header is "Accept: */*", or "Accept: text/html", or anything else. You can add a limitation that the HTML response does not produce "application/json". But then the question is which response will be sent when the HTTP header is "Accept: */*"? Both methods will...
Created by Fang on March 30, 2012 10:23:21    Last update: March 30, 2012 10:23:21
These bean types are essential for the Spring MVC framework. I copied them here from the Spring Documentation for quick reference. Bean type Explanation HandlerMapping Maps incoming requests to handlers and a list of pre- and post-processors (handler interceptors) based on some criteria the details of which vary by HandlerMapping implementation. The most popular implementation supports annotated controllers but other implementations exists as well. HandlerAdapter Helps the DispatcherServlet to invoke a handler mapped to a request regardless of the handler is actually invoked. For example, invoking an annotated controller requires resolving various annotations. Thus the main purpose of a HandlerAdapter is to shield the DispatcherServlet from such details. HandlerExceptionResolver Maps exceptions to views also allowing for more complex exception handling code. ViewResolver Resolves logical String-based...
Created by Fang on March 06, 2012 14:38:52    Last update: March 06, 2012 15:56:45
This may or may not be useful, but I did the research so here's the code. import org.springframework.beans.factory.annotatio...
Created by Fang on February 23, 2012 14:25:57    Last update: March 01, 2012 13:53:59
Some example snippets for Spring message configuration and usage. To configure a message source in Spring context (basename=messages): <bean id="messageSource" class="org.springf... Locale change interceptor can also be setup with: <?xml version="1.0" encoding="UTF-8"?> <beans x... The messages file should be named messages.properties (or messages_en.properties , etc.) and located on CLASSPATH , for example: WEB-INF/classes . To use a message resource in JSP: <%@ taglib prefix="spring" uri="http://www.springf...
Created by Fang on March 01, 2012 13:52:14    Last update: March 01, 2012 13:52:14
Step 1: define the message code: code.with.arg=arg1: {0}, arg2: {1}, arg3: {2} Step 2: use it in the JSP with comma separated arguments: <%@ taglib uri="http://www.springframework.org/tag... If the argument itself contains a comma: <%@ taglib uri="http://www.springframework.org/tag...
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; ...
Previous  1 2 3 4 Next