How To get ServletContext inside Filter

I was coding last night and I have to get some information from Manifest file in filters. In order to read the Manifest I need the ServletContext. Using below code you can get the ServletContext inside Filter.

public class SomeFilter implements Filter {
FilterConfig config;

public void setFilterConfig(FilterConfig config) {
this.config = config;
}

public FilterConfig getFilterConfig() {
return config;
}

public void init(FilterConfig config) throws ServletException {
setFilterConfig(config);
}

// doFilter and destroy methods…
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {

ServletContext context = getFilterConfig().getServletContext();
Manifest mManifest=new Manifest();
System.out.println(“Manifest “+mManifest.getBuildInfo(context));

}
}

XStream: Cannot parse date

I was sending date “06-14-2011” in XML request, during it’s processing i got this parse error

Cannot parse date 06-14-2011 com.thoughtworks.xstream.converters.basic.DateConverter.fromString(DateConverter.java:97)

this is because Xstream by default don’t handle MM-dd-yyyy format. So we need to add one in order to make our format working.

String[] formats ={“MM-dd-yyyy”}; XStream xstream = new XStream(); xstream.registerConverter(new DateConverter(“MM-dd-yyyy”,formats)); Object obj=xstream.fromXML(inputXML)

This will resolve the issue. =)

Mainframe CICS DB2 : Security mechanism not supported

I was writing a code to access DB2 in CICS where I encountered this error. This error encounters when you are trying to access a secured Db with default options. In order to get this working, you have to specify ‘securityMechanism’ property in your connection string with value as supported by server, see below:

jdbc:db2://SERVERNAME:3700/DB:securityMechanism=7;

Continue reading “Mainframe CICS DB2 : Security mechanism not supported”

Mainframe CICS DB2 : java.lang.NoClassDefFoundError: com/ibm/crypto/provider/IBMJCE

I was trying to access Mainframe () DB2 using standalone application with “com.ibm.db2.jcc.DB2Driver” driver where I encountered the below error

java.lang.NoClassDefFoundError: com/ibm/crypto/provider/IBMJCE

Problem was that ibmjceprovider.jar was missing from my classpath and java.security file I added the jar file and then added below line in security file..it works.

security.provider.10=com.ibm.crypto.provider.IBMJCE