Recent Notes
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 Dr. Xi on October 08, 2012 11:56:29
Last update: October 08, 2012 11:56:29
This example gets the annotation attributes of of a web service client generated by JAX-WS RI.
The generated web service client looks like this:
import javax.xml.ws.Service;
import javax.xml.w...
This is how to get the attributes for annotation @WebServiceClient :
WebServiceClient wsc = MyTestWebService.class.getA...
Note that even though name , targetNamespace and wsdlLocation are attributes, you get them using a method call.
Also, annotations are available at runtime only when they have RetentionPolicy.RUNTIME .
Created by voodoo on August 15, 2012 11:23:44
Last update: August 15, 2012 11:23:44
By default Linux pipe output is buffered. For example, you can't see the most recent stdout on screen with tee :
$ ./mycommand | tee /tmp/mycommand.log
Here are two ways to make the pipe unbuffered.
Method 1: use the unbuffer command from expect
$ sudo apt-get install expect-dev
$ unbuffer ./...
Method 2: use stdbuf
# Make output line buffered:
$ stdbuf -oL ./myc...
Created by James on August 01, 2012 14:26:53
Last update: August 01, 2012 14:26:53
The jQuery size() function returns the number of elements in the jQuery object.
According to jQuery doc:
The .size() method is functionally equivalent to the .length property; however, the .length property is preferred because it does not have the overhead of a function call.
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 May 03, 2012 15:07:17
Last update: May 03, 2012 15:07:52
Scaling an image with default Java API loses quality (horribly!):
public static BufferedImage resizeImage(Buffer...
The imgscalr library does the job beautifully. And its' very easy to do:
// import org.imgscalr.Scalr;
public static...
To import the library in Maven:
<dependency>
<groupId>org.imgscalr</groupId>
...
Created by James on April 25, 2012 08:38:05
Last update: April 25, 2012 08:38:05
With no parameters, the .toggle() method simply toggles the visibility of elements. Example:
$(function() {
$('body').click(function() {
...
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 12:28:47
Last update: March 30, 2012 12:28:47
The HandlerMapping bean for @RequestMapping annotated @Controller is:
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping for Spring MVC prior to 3.1
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping for Spring MVC 3.1
This info might be handy if you want to add an interceptor:
<beans>
<bean id="handlerMapping"
...