Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class is not getting instantiated in java 5 and the same works fine in java 6

 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to instantiate inner class in java 5.0.11, but getting the below exception:

java.lang.NoClassDefFoundError: com/test/security/websso/sp/MobileRequestWrapper$MobileWrapperHttpServletRequest
com.test.security.websso.sp.MobileRequestWrapper.doFilter(MobileRequestWrapper.java:33)

The same works fine in Java 6.

Here is my code:


import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.lang.StringUtils;


public class MobileRequestWrapper implements Filter {



/** {@inheritDoc} */
public void init(FilterConfig filterConfig) throws ServletException {

}

/** {@inheritDoc} */
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
String output = com.thl.gsk.DeviceDetectionUtil.processRequest((HttpServletRequest)servletRequest,(HttpServletResponse)servletResponse);
if(StringUtils.isNotBlank(output) && "mobile".equalsIgnoreCase(output))
{
System.out.println("----------------> in do filter of new class start");
HttpServletRequest wrappedRequest = new MobileWrapperHttpServletRequest(
(HttpServletRequest) servletRequest);
filterChain.doFilter(wrappedRequest, servletResponse);
}
else
{
filterChain.doFilter(servletRequest, servletResponse);
}


}

public void destroy() {
}


private static class MobileWrapperHttpServletRequest extends
HttpServletRequestWrapper {

public MobileWrapperHttpServletRequest(HttpServletRequest request) {
super(request);
}


@Override
public String getParameter(String name) {

System.out.println("----------------> in do filter of new class get parameter");
String originalValue = super.getParameter("cmd");
if (originalValue == null) {
return null;
} else {
String newVal = fixup(originalValue);
System.out.println("newVal in the brand new servlet ------------------------>"+newVal);
return fixup(originalValue);
}
}
private String fixup(String value) {
String newValue = null;
if("Home".equalsIgnoreCase(value)){
newValue = "MProductsByName";
}
return newValue;
}



}
}
 
Winston Gutkowski
Bartender
Pie
Posts: 10427
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagaraj Shivaklara wrote:Here is my code:...

Nagaraj,

Please UseCodeTags (←click) when posting code; you'll get a lot more response. I'm surprised you haven't worked this out after 70 posts.

And BEFORE you post again, I'd suggest you also read the DontWriteLongLines page and break up some of those enormous lines, because many of them are far too long.

Thanks.

Winston

 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this bug exists in JDK 5 then it is fairly fundamental and I would have expected developers the world over to have been yelling at Sun ( I don't think Oracle were on the scene for Java 5 ). I use inner classes though all my code and it all works well in Java 5 , 6 and 7.

It sounds to me like you have a bug in your build system. You could check the 'classes' directory ( or whatever you have called it ) after the compile step to see whether or not the class file has been created. If it has been created then you can check the jar file to see whether or not it contains the class file. In other words - check the build at each stage to make sure it is correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic