Re: The abort operation is close the socket

2008-03-24 Thread Oleg Kalnichevski

On Thu, 2008-03-20 at 10:49 +0800, hjw wrote:
 Hi,all:
I find HttpMethod#abort() will close socket, but I only want to interrupt
 the IO operation which is using the network.
My case is that some important message must post at once when data I get
 from the same site is match some condition.So , I need to interrupt the IO
 operation and let the post action has the highest priority.
Could you tell me whether abort the is the only way to do for the case,or
 has a better one?
 
 Raymond

Raymond,

I do not think classic I/O model is applicable for this scenario.
Consider using NIO (non-blocking I/O) instead.

Oleg 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Handling proxies and modifying request header fields

2008-03-24 Thread Oleg Kalnichevski

On Thu, 2008-03-20 at 10:31 +0530, Biju P wrote:
 Hi,
 
 I am writing an Applet. The applet must be accessed by users from 
 different domains and networks which are controlled by proxies and 
 firewalls.
 
 My concerns are,
 i) The applet should be able to send requests to external websites thru 
 the proxy (if any proxy exists).
 ii) The applet should be able to modify the request header fields, such as 
 User-agent field.
 
 When I try using normal URLConnection from java.io package, the applet is 
 able to inherit the proxy settings from the browser and send the requests 
 thru that proxy. But, I am getting response code 403 for some of the 
 sites. 
 
 Can anybody tell me, is this possible by using Apache HttpClient?.

No, it is not. You have configure HttpClient manually either using
system properties or ProxySelector class if running on JRE 5.0 or newer.

Oleg

  And if 
 so, please specify the version.
 
 It would be a great help, if somebody could advise on this.
 
 Biju P M
 Mailto: [EMAIL PROTECTED]
 =-=-=
 Notice: The information contained in this e-mail
 message and/or attachments to it may contain 
 confidential or privileged information. If you are 
 not the intended recipient, any dissemination, use, 
 review, distribution, printing or copying of the 
 information contained in this e-mail message 
 and/or attachments to it are strictly prohibited. If 
 you have received this communication in error, 
 please notify us by reply e-mail or telephone and 
 immediately and permanently delete the message 
 and any attachments. Thank you
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Getting the response time for multithreaded client

2008-03-24 Thread Oleg Kalnichevski

On Thu, 2008-03-20 at 18:19 +0100, Uwe Kubosch wrote:
 Hi all!
 
 We are using the Commons HttpClient in a multithreaded application, and
 frequently there are more threads trying to use the client than the
 limit set by setMaxConnectionsPerHost.
 
 In this situation we still need to log the response time from the
 server.  How can we do that?  Measuring the Method.executeMethod call
 includes the time the thread sleeps before actually submitting the
 request.
 
 We are currently using Commons HttpClient 3.1 which I believe is the
 latest stable release.
 

Uwe,

There is no way around either upgrading to HttpClient 4.0, which has a
massively better, modular architecture or hacking the source code of
HttpClient 3.x  

Oleg

 Any help is greatly appreciated, even quick fixes and hacks :)
 
 
 Uwe
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: httpclient proxy problem

2008-03-24 Thread Oleg Kalnichevski

On Thu, 2008-03-20 at 20:38 +0200, Mehmet Kuzu wrote:
 Hİ ,
 
 I have a problem about  getting response behind proxy which requires
 authentication using apache httpclient .  Proxy server is squid and it
 uses ntlm protocol. I am new to httpclient 
 API and i may miss something.  
  
 Thanks very much,
  
 Best regards,
  

Mehmet,

The code seems okay. The wirelog seems to indicate an authentication
failure due to invalid credentials. Please double-check values of the
username, password, domain and host.

Oleg


 My code is below:
  
 *
 public static void main(String args[]) {
  
   Provider prov = new BouncyCastleProvider();
   Security.addProvider(prov);
   
  String url = http://www.google.com;; 
  HttpClient client = new HttpClient();
  
  client.getHostConfiguration().setProxy(proxyHost, proxyPort);
  Credentials defaultcreds = new
 NTCredentials(userName,password,proxyhost,domain);
 
 client.getState().setProxyCredentials(AuthScope.ANY,defaultcreds);

   
  HttpMethod method = new GetMethod(url);
  method.setDoAuthentication( true );

  int statusCode;
   try {
statusCode = client.executeMethod( client.getHostConfiguration(),
 method,client.getState());
 System.out.println(Stat= +HttpStatus.getStatusText(statusCode));
   } catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
   } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
   } 
  }
  
 
 ***
 log is here 
  
 2008/03/20 20:34:52:921 EET [DEBUG] HttpClient - Java version:
 1.5.0_03
 
 2008/03/20 20:34:52:921 EET [DEBUG] HttpClient - Java vendor: Sun
 Microsystems Inc.
 
 2008/03/20 20:34:52:921 EET [DEBUG] HttpClient - Java class path: C:
 \Documents and Settings\Owner\Desktop\setup\eclipse\workspace
 \Deneme;C:\Documents and Settings\Owner\Desktop\setup\eclipse
 \workspace\Deneme\xmlrpc-client-3.0.jar;C:\Documents and Settings
 \Owner\Desktop\setup\eclipse\workspace\Deneme\xmlrpc-common-3.0.jar;C:
 \Documents and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme
 \mail.jar;C:\Documents and Settings\Owner\Desktop\setup\eclipse
 \workspace\Deneme\hibernate3.jar;C:\Documents and Settings\Owner
 \Desktop\setup\eclipse\workspace\Deneme
 \mysql-connector-java-5.0.8-bin.jar;C:\Documents and Settings\Owner
 \Desktop\setup\eclipse\workspace\Deneme\xerces-2.6.2.jar;C:\Documents
 and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme
 \dom4j-1.6.1.jar;C:\Documents and Settings\Owner\Desktop\setup\eclipse
 \workspace\Deneme\commons-logging-1.0.4.jar;C:\Documents and Settings
 \Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \commons-collections-2.1.1.jar;C:\Documents and Settings\Owner\Desktop
 \setup\eclipse\workspace\Deneme\lib\asm.jar;C:\Documents and Settings
 \Owner\Desktop\setup\eclipse\workspace\Deneme\lib\asm-attrs.jar;C:
 \Documents and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme
 \lib\c3p0-0.9.1.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\cglib-2.1.3.jar;C:\Documents and
 Settings\Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \checkstyle-all.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\cleanimports.jar;C:\Documents and
 Settings\Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \concurrent-1.3.2.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\connector.jar;C:\Documents and Settings
 \Owner\Desktop\setup\eclipse\workspace\Deneme\lib\ehcache-1.2.3.jar;C:
 \Documents and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme
 \lib\jaas.jar;C:\Documents and Settings\Owner\Desktop\setup\eclipse
 \workspace\Deneme\lib\jacc-1_0-fr.jar;C:\Documents and Settings\Owner
 \Desktop\setup\eclipse\workspace\Deneme\lib\javassist.jar;C:\Documents
 and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \jaxen-1.1-beta-7.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\jdbc2_0-stdext.jar;C:\Documents and
 Settings\Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \jgroups-2.2.8.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\jta.jar;C:\Documents and Settings\Owner
 \Desktop\setup\eclipse\workspace\Deneme\lib\oscache-2.1.jar;C:
 \Documents and Settings\Owner\Desktop\setup\eclipse\workspace\Deneme
 \lib\proxool-0.8.3.jar;C:\Documents and Settings\Owner\Desktop\setup
 \eclipse\workspace\Deneme\lib\swarmcache-1.0rc2.jar;C:\Documents and
 Settings\Owner\Desktop\setup\eclipse\workspace\Deneme\lib
 \syndiag2.jar;C:\Documents and Settings\Owner\Desktop\setup\eclipse
 \workspace\Deneme\lib\versioncheck.jar;C:\Documents and Settings\Owner
 

Re: Apache HttpClient - Using custom socket factory for failover support

2008-03-24 Thread Oleg Kalnichevski

On Thu, 2008-03-20 at 22:05 -0700, Ankur Shah wrote:
 I am using httpclient to connect to a remote server. Now for each primary
 server there's also a backup failover server that i must talk to if
 connection attempts with the primary server fails. To achieve
 this what i'd ideally like to do is have HttpClient use a custom factory
 that tries to create a socket connection with the primary server and if that
 fails (or times out), it'll go about  talking to backup server (and retry a
 few times before giving up altogether).
 
 Now, searching on the web, i did find references to a
 MultiHomeProtocolSocketFactory (that extends DefaultSocketFactory) that is
 presumably in apache contrib package. But what that does is that in the
 overriden
 createSocket method, it takes host as a param (among other thing) and then
 simply does a InetAddress.getAllByName which is not what i want. From what i
 understand this caters to a DNS based failover which is not the case here.
 
 What i'd ideally like to do is create a factory and have a createSocket
 method that takes primary and secondary host and port as args and then tries
 both. I am not sure though how can i make HttpConnection class
 invoke my method.

Ankur,

What's the point of trying to implement the failover support on the
ProtocolSocketFactory level? What's wrong with just retrying failed
requests against a secondary server in case the primary one is
unavailable?  

Oleg


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



httpclient3 takes 3 minutes to catch IOException, why so long?

2008-03-24 Thread ever friend
 Greeting...
   
  I use httpclient3 to communicate with a web server application.
  
when I test an error handling, it takes 3 minutes to catch the IOException (I 
manually unplug the internet connection). I assumed it takes couple ms to catch 
IOException since only one line of code/function-call there 
(client.executeMethod(method) to cause the IOException, but it takes 3 minutes. 
It seems sth. inside executeMethod is doing sth.
  
Could some experters provide an inside about why it taks so long, and how to 
make it quicker to catch the exception?
  
(note: I have set the retryhandler to 0 retry. I just want to find the IO 
problem asap.)
   
  the code is sth. like:
.
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(http://www.x.com;);

NameValuePair[] data = {
  
};
method.setRequestBody(data);
  
// do not want to retry, so set to 0.
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
  new DefaultHttpMethodRetryHandler(0, false));
   
  try {
  // Execute the method.
  int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
 
  }else{
...
  }
} catch (HttpException e) {
...
  
} catch (IOException e) {
  ...
} finally {
  // Release the connection.
  method.releaseConnection();
} 
   
  Thank you,
  Ever

   
-
Never miss a thing.   Make Yahoo your homepage.