aspose file tools*
The moose likes Java in General and the fly likes Inner class is not getting instantiated in java 5 and the same works fine in java 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inner class is not getting instantiated in java 5 and the same works fine in java 6" Watch "Inner class is not getting instantiated in java 5 and the same works fine in java 6" New topic
Author

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

Nagaraj Shivaklara
Ranch Hand

Joined: Dec 16, 2008
Posts: 78
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;
}



}
}

Thanks n Regards,
Nagaraj S K
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1111
    
  10

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class is not getting instantiated in java 5 and the same works fine in java 6