Wednesday, November 2, 2016

Kernel panic after ubuntu update

I recently did ubuntu update and then after reboot i got following screen related to kernel panic. The problem for me was that my /boot ran out of space.



Solution:

Restart your machine and go to grub loader
Select "Advanced options for Ubuntu"

Then you will be listed with list of kernels, select one of them and press enter [at least one of them should allow to you boot and login  into your ubuntu machine]

Then go to terminal and run:
 aptitude search ~ilinux-image
this should list all the kernel images u have in /boot

run
uname -a

to get ur current running kernel

run
sudo apt-get <image name>
for example: sudo apt-get autoremove linux-image-4.4.0-45-generic
to remove the image that you dont need

Saturday, June 11, 2016

Ambigious mapping

Scenario:  

Need to add a spring mvc project as dependency (scope test) to other spring mvc project.

Problem: 

Ambiguous mapping. Cannot map 'xyzController' method 

Reason: 

Both projects had web controller with request mapping annotation only at method level. As the rest of it when spring tries to map / , we have ambibious maping scenario where both the controllers quality for the mapping and this result in the exception.

Solution: 

Add Requestmapping annotation at the both controller (or one of them) so that spring can map urls distinctly


Monday, April 27, 2015

Generic enum converter

  public static Enum<?> toEnum(final Class<? extends Enum> classType, final Enum<?> enumObj) {  
     if (enumObj == null) {  
       return null;  
     } else {  
       return enumObj.valueOf(classType, enumObj + "");  
     }  
   }  

Usage:

  Test1 returnedEnum = (Test1) toEnum(Test1.class, Test2.HELLO_ENUM);  

Tuesday, February 3, 2015

Documenting Spring annotated rest interface via reflection  

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, 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.