java - Mysterious ClasscastException from apache httpclient code -
we using apache's commons-httpclient-3.1 library in our project. however, due legacy , other project specific dependencies not using of implementations of secureprotocolsocketfactory interface provided apache (like sslprotocolsocketfactory,strictsslprotocolsocketfactory) have created our own socketfactory called httpclient3xsocketfactory implements secureprotocolsocketfactory interface.this factory registered apache calling protocol.registerprotocol method of org.apache.commons.httpclient.protocol.protocol.java. given below snippet of our code
public class httpclient3xsocketfactory implements secureprotocolsocketfactory { . . . private static final protocolsocketfactory socketfactory = new httpclient3xsocketfactory(); private static final protocol httpsproto = new protocol("https", socketfactory, 443);
and registered below
protocol.registerprotocol("https", httpsproto);
however generates mysterious classcastexception tunnelcreated() method of apache's httpconnection last line
if (usingsecuresocket) { throw new illegalstateexception("already using secure socket"); } if (log.isdebugenabled()) { log.debug("secure tunnel " + this.hostname + ":" + this.portnumber); } secureprotocolsocketfactory socketfactory = (secureprotocolsocketfactory) protocolinuse.getsocketfactory();
the exception says --
caused by: java.lang.classcastexception: com.vmware.vdi.common.saml.httpclient3xsocketfactory cannot cast org.apache.commons.httpclient.protocol.secureprotocolsocketfactory @ org.apache.commons.httpclient.httpconnection.tunnelcreated(httpconnection.java:791) @ org.apache.commons.httpclient.httpmethoddirector.executeconnect(httpmethoddirector.java:528) @ org.apache.commons.httpclient.httpmethoddirector.executewithretry(httpmethoddirector.java:404) @ org.apache.commons.httpclient.httpmethoddirector.executemethod(httpmethoddirector.java:178) @ org.apache.commons.httpclient.httpclient.executemethod(httpclient.java:408) @ org.apache.commons.httpclient.httpclient.executemethod(httpclient.java:327)
but com.vmware.vdi.common.saml.httpclient3xsocketfactory implement org.apache.commons.httpclient.protocol.secureprotocolsocketfactory interface. have verified using getclassloader method both loaded using same class loader. used reflection @ run time check com.vmware.vdi.common.saml.httpclient3xsocketfactory implement org.apache.commons.httpclient.protocol.secureprotocolsocketfactory interface. @ loss understand why classcaseexception generated.
Comments
Post a Comment