Hi guys....

got a problem again!!! :( :( i m told that as far as possible dont change
the httpClient jar so I will have to find a way to do as described in
previous mail without changing HTTPConnection.java class....

I think if  i do this....
Protocol stricthttps = new Protocol(SystemConstants.protocolHttps, new
MySocketFactory(), SystemConstants.socketNumber);

and this...

httpClient.getHostConfiguration().setHost(SystemConstants.connectionHostName,
SystemConstants.socketNumber, stricthttps);
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);

MySocketFactory class does this... (because i also want StrictSSL
implementation.. )

MySocketFactory  extends StrictSSLProtocolSocketFactory implements
ProtocolSocketFactory{
     MySocketFactory() throws Exception {
          super(true);
    }

    public Socket createSocket(host,port){
       //my code for creating socket....
   }
}

The problem I find now is that this createSocket method does not get called
from the HTTPConnection class... the reason being this line of code.....(i
dont wanna change the HTTPConnection if theres another way.. )

final ProtocolSocketFactory socketFactory = (isSecure() && isProxied()? new
DefaultProtocolSocketFactory() : protocolInUse.getSocketFactory());

here isSecure() and isProxied() both are true because i want both of them..
but the problem is that DefaultProtocolSocketFactory gets initiated and not
protocolInUse.getSocketFactory() so mysocketfactory class never gets
called...

is there a problem in my implementation or is there any other way to do
this??

thanks..


On 9/18/07, nitya vyas <[EMAIL PROTECTED]> wrote:
>
> I got it.. I had to call the bind and connect mathod also from my
> implementation..
>
> public Socket createSocket(String host, int port) throws IOException,
> UnknownHostException {
>         Socket s = new Socket(Proxy.NO_PROXY );
>         InetSocketAddress addr = new InetSocketAddress(host, port);
>         s.bind(new InetSocketAddress(0));
>         s.connect(addr);
>         return s;
>     }
>
> Looks to be wroking fine.. Now it goes to the PlainSocketImpl class rather
> than SocksSocketImpl.. i hope there wont be any implications of the
> commons-httpclient.jar change to other things as this method will be
> called now for every server call..
>
> cheers,
> Nitya
>
> On 9/17/07, nitya vyas < [EMAIL PROTECTED]> wrote:
> >
> > thanks Roland..
> >
> > this looks like the solution as i also saw that It was checking proxy ==
> > NO_PROXY somewhere and it didnt get it in my implementation so it threw
> > IOException.
> >
> > I still have a question regarding the implementation of the
> > socketfactory. if i use new Socket( Proxy.NO_PROXY) then i m getting
> > java.net.SocketException: Socket is not connected exception.. can u pls
> > tell me what is the reason? i guess the host and port that we get must be
> > set in the Socket class just like it happens right now by new
> > Socket(host,port) from HTTPConnection class.. but doesnt happen when i do
> > new socket( Proxy.NO_PROXY)...
> >
> > i called my implementation createSocket() method from the HTTPConnection
> > class..this class is called when i do httpClient.execute(method)...
> >
> > please help..
> >
> > thanks
> >
> >
> > On 9/14/07, Roland Weber <[EMAIL PROTECTED]> wrote:
> > >
> > > nitya vyas wrote:
> > > > I found out that the problem lies in only one line ..
> > > >
> > > > System.setProperty("java.net.useSystemProxies","true");
> > > >
> > > > if i dont do this, the server will respond. or if i immediately
> > > write
> > > > System.setProperty("java.net.useSystemProxies","false"); after that
> > > line
> > > > only nothng in between then only it works and server responds..
> > >
> > > Implement a ProtocolSocketFactory [1].
> > > Use the Socket(Proxy) constructor [2]
> > > with argument Proxy.NO_PROXY [3], then
> > > connect. Mark Claassen did that before [4].
> > >
> > > hope that helps,
> > >   Roland
> > >
> > > [1]
> > >
> > > http://jakarta.apache.org/httpcomponents/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html
> > > [2]
> > >
> > > http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#Socket(java.net.Proxy)<http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#Socket%28java.net.Proxy%29>
> > > [3] http://java.sun.com/j2se/1.5.0/docs/api/java/net/Proxy.html#NO_PROXY
> > >
> > > [4]
> > > http://mail-archives.apache.org/mod_mbox/jakarta-httpclient-user/200701.mbox/[EMAIL
> > >  PROTECTED]
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > >
> > >
> >
>

Reply via email to