1: for (Method method : YourClass.class.getMethods()) {
2: // url
3: if (method.isAnnotationPresent(RequestMapping.class)) {
4: RequestMapping parms = method.getAnnotation(RequestMapping.class);
5: String[] val = parms.value();
6: RequestMethod[] methodType = parms.method();
7: for (int i = 0; i < val.length; i++) {
8: System.out.println(val[i] + " METHOD TYPE:" + methodType[i]);
9: }
10: //parameter
11: Class<?>[] paramsTypes = method.getParameterTypes();
12: Annotation[][] annot = method.getParameterAnnotations();
13: for (int i = 0; i < annot.length; i++) {
14: if (annot[i].length > 0 && annot[i][0] instanceof RequestParam) {
15: RequestParam new_name = (RequestParam) annot[i][0];
16: System.out.println("Request: " + new_name.value() + " = " + paramsTypes[i]);
17: }
18: }
19: //return type
20: if (method.getReturnType().getCanonicalName().equals(List.class.getCanonicalName())) {
21: Type listType = method.getGenericReturnType();
22: if (listType instanceof ParameterizedType) {
23: Type elementType = ((ParameterizedType) listType).getActualTypeArguments()[0];
24: System.out.println("Response: [" + elementType + "]");
25: }
26: } else {
27: System.out.println("Response: " + method.getReturnType().getCanonicalName());
28: }
29: }
Tuesday, February 3, 2015
Documenting Spring annotated rest interface via reflection
Tuesday, September 9, 2014
Problem in getting post parameter in Spring MVC via REST request
@RequestMapping(value = "/api/login", method = RequestMethod.POST)
public WelcomeMessage getHelloWorld(@RequestParam(value = "username") final String username, @RequestParam(value = "password") final String password) {
// do some thing
}
I was having the problem to get post parameter via REST request. Adding the header "Content-Type:application/x-www-form-urlencoded" fixed the issue
Saturday, July 26, 2014
A* Algorithm optimality proof
This video from me describes the A* algorithm optimality proof. You can also see the slides from the link provided in description.
Wednesday, June 11, 2014
Thursday, March 27, 2014
java.lang.IllegalArgumentException: badly formated directory string
it is based on invalid format, try to give correct name structure for instance:
new X500Name("C=DE,O=Organiztion");
new X500Name("C=DE,O=Organiztion");
Tuesday, March 4, 2014
convert grails project to grails eclipse project
grails integrate-with --eclipse
Sunday, February 23, 2014
Design patterns
Design pattern are solutions to a class of problem which is proven to be good. It's like following the big guys. The attached project contains easy to learn example for Factory, observer listener and strategy design patterns. This project will be updated with further patterns. Each if the downloadable project is an eclipse project , you can simply import it in eclipse if you wish.
Download all Project
Description of project via sample problems:
PROBLEM 1:
Say you want to create people in a computer game. People can be of type enemy army, friendly army or civilians (Also further more addition in future should be also possible). In this kind of problem you can use Factory pattern to create these game people.
PROBLEM 2:
Say in same game scenario you want to create Aeroplanes with different capability. Say 5 aeroplanes with military capability and 1 civilian (In future you should be also able to add more capabilities like speeds, payload types). In this kind of problem you can use Strategy pattern. You can create different capabilities and inject them in aeroplane.
PROBLEM 3:
Now say you have a game window. There are different buttons. You want to do different action in your Window class based to the location of the button clicked (Say button is developed by some other developer in his own way). In this problem you can use observer listener pattern.Window can be listener of button click event. Developer of the button should define a interface to add listeners.
Download all Project
Description of project via sample problems:
PROBLEM 1:
Say you want to create people in a computer game. People can be of type enemy army, friendly army or civilians (Also further more addition in future should be also possible). In this kind of problem you can use Factory pattern to create these game people.
PROBLEM 2:
Say in same game scenario you want to create Aeroplanes with different capability. Say 5 aeroplanes with military capability and 1 civilian (In future you should be also able to add more capabilities like speeds, payload types). In this kind of problem you can use Strategy pattern. You can create different capabilities and inject them in aeroplane.
PROBLEM 3:
Now say you have a game window. There are different buttons. You want to do different action in your Window class based to the location of the button clicked (Say button is developed by some other developer in his own way). In this problem you can use observer listener pattern.Window can be listener of button click event. Developer of the button should define a interface to add listeners.
Subscribe to:
Posts (Atom)