Hello Arturo,

what exactly do you chance when it works?
>From a quick look at the code, I suggest the
following modifications:
- don't recycle the method, create a new one
- invoke releaseConnection() in a finally block,
  no matter whether there was an exception or not

The "unable to find line starting with HTTP" has
been mentioned in other recent posts. Are you
by any chance using the HttpClient from
different threads, without having installed the
MultiThreadedConnectionManager ?

cheers,
  Roland





"Arturo Esquivel Sanchez" <[EMAIL PROTECTED]> 
10.06.2004 12:19
Please respond to
"Commons HttpClient Project"


To
<[EMAIL PROTECTED]>
cc

Subject
HttpClient 2.0 problems









Hi,

The problem that im having is that sometimes i get the following error
when trying to connect to url, and then i change something in my code and
suddenly works fine, then i change something again and i get again the
same error (¿?), if a loop in my code in order to get a response other
than -1 it doesn´t work and i get a lots of the error.
This is the error:

[INFO] HttpMethodBase - -Recoverable exception caught when processing
request [WARN] HttpMethodBase - -Recoverable exception caught but
MethodRetryHandler.ret ryMethod() returned false, rethrowing exceptionA
recoverableexception occurred,  retrying.
org.apache.commons.httpclient.Http RecoverableException: Error in parsing
the status  line from the response: unabl e to find line starting with
"HTTP"
This is the code that im using:

      boolean retry=false;

      do{

        statusCode = Procesa_Get_Url(url, client, config, state,
        urlToConnect2, respHTML1);
        if (statusCode != -1 && urlToConnect2.toString().trim() != "" &&
        urlToConnect2.toString().trim().length() != 0){
        retry=true;        }
      }while (retry==false);


 private int Procesa_Get_Url(String urlProc, HttpClient clientProc,
 HostConfiguration configProc, HttpState stateProc, StringBuffer urlTC,
 StringBuffer respHTML) throws Exception {    int statusCode=-1;
    String redirectLocation=null;

    clientProc.setTimeout(60*30*1000);
    clientProc.setHttpConnectionFactoryTimeout(60*30*1000);
    clientProc.setConnectionTimeout(60*30*1000);

    //try{

      //URI uri = new URI(urlProc.toCharArray());
      URI uri = new URI(urlProc.toCharArray());

      HttpMethod method = new GetMethod(uri.toString());

      String schema = uri.getScheme();

      if ((schema == null) || (schema.equals(""))){
            schema = "http";
      }

      Protocol protocol = Protocol.getProtocol(schema);

      String host = uri.getHost();
      int port = uri.getPort();

      configProc.setHost(host,port,protocol);
 
configProc.setProxy(System.getProperty("http.proxyHost"),Integer.parseInt(System.getProperty("http.proxyPort","80")));
 
          stateProc.setProxyCredentials(null, null,
        new UsernamePasswordCredentials(
          System.getProperty("http.proxyUserName"),
          System.getProperty("http.proxyPassword")));

      int attempt=0;
      boolean retry=false;

      //do{
      //for (attempt = 0; statusCode == -1 && attempt < 3; attempt++) {
        try{
              statusCode =
              clientProc.executeMethod(configProc,method,stateProc); //if
              (statusCode != -1){              //  retry=true;
              //}

        } catch (HttpRecoverableException e) {
                  method.recycle();
                  method.releaseConnection();
                  System.out.println("A recoverable exception occurred,
                  retrying.  " + e.getMessage());        } catch
                  (IOException e) {
                  System.err.println("Failed to download file.");
                  e.printStackTrace();
        }catch (Exception e) {
                  System.err.println("Errorsote.");
                  e.printStackTrace();
        }

      //}while (retry=false);

      if (statusCode == -1) {
        System.err.println("Numero de Intentos:" + attempt);
        System.err.println("Failed to recover from exception.");
      }

      switch (statusCode){
        case 200 :  stateProc.setCookiePolicy(CookiePolicy.RFC2109);
                    Cookie[] cookies =  stateProc.getCookies();
                    System.out.println("Present cookies: ");
                    for (int i = 0; i < cookies.length; i++) {
                      System.out.println(" - " +
                      cookies[i].toExternalForm());                    }
                    urlTC.append(method.getURI().toString());
                    respHTML.append(method.getResponseBodyAsString());
                    break;

        case 302 :  stateProc.setCookiePolicy(CookiePolicy.RFC2109);
                    Cookie[] cookies2 =  stateProc.getCookies();
                    System.out.println("Present cookies: ");
                    for (int i = 0; i < cookies2.length; i++) {
                      System.out.println(" - " +
                      cookies2[i].toExternalForm());                    }
                    Header locationHeader =
                    method.getResponseHeader("location"); if
                    (locationHeader != null) {
                    redirectLocation                    =
                    locationHeader.getValue();
                      urlTC.append(redirectLocation);
                      }else{
                      urlTC.append(method.getURI().toString());
                    }
                    respHTML.append(method.getResponseBodyAsString());
                    break;


      }
      method.recycle();
      method.releaseConnection();

    //} catch (Exception e) {
    //    System.err.println("Failed to download file.");
    //    e.printStackTrace();
    //}
      return (statusCode);

  }


Thanks in advance for your help

Best Regards,
Arturo


Saludos,
Arturo



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


Reply via email to