hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <mbe...@gmail.com>
Subject Re: HttpClient NOT to use NTLM
Date Thu, 07 Jul 2005 01:34:48 GMT
Hi Gabor,

You need to call
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs) on the actualy instance of HttpClient you are using to
execute the method.

Mike

On 7/6/05, Gábor SEBESTYÉN <segabor@gmail.com> wrote:
> 
> On 2005.07.06., at 17:43, pavan kumar wrote:
> 
> > Hi Gabor,
> >
> > Please send the complete log file and the sample code which you are
> > trying to..
> 
> The appropriate source:
> ==================
> 
>      protected void prepareClient(HttpClient client) {
>          Map conf = (Map) Globals.getGlobals().get("proxy.current");
>          if (conf != null) {
>              String proxyHost = (String) conf.get("host");
>              int proxyPort = ((Integer) conf.get("port")).intValue();
>              String user = (String) conf.get("user");
>              String pwd = (String) conf.get("passwd");
> 
>              client.getHostConfiguration().setProxy(proxyHost,
> proxyPort);
>              if (user != null && pwd != null) {
>                  client.getState().setProxyCredentials(
>                      // FIXME: no NTLM detection, please
>                      new AuthScope(proxyHost, proxyPort, null,
> org.apache.commons.httpclient.auth.AuthPolicy.BASIC),
>                      new UsernamePasswordCredentials(user, pwd));
>              }
> 
>              List authPrefs = new ArrayList(1);
>              authPrefs.add(AuthPolicy.BASIC);
>              client.getParams().setParameter
> (AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
>          }
>      }
> 
>      //
>      // main entry to process a http request
>      //
>      public boolean post(String actionName, NameValuePair[] params) {
>          boolean ret = false;
> 
>          synchronized(commLock) {
>              HttpClient client = new HttpClient();
>              prepareClient(client);    // see above
> 
>              PostMethod method = new PostMethod(baseURL + "/" +
> actionName);
>              method.setRequestBody(params);
> 
>              method.getParams().setParameter
> (HttpMethodParams.RETRY_HANDLER,
>                      new DefaultHttpMethodRetryHandler(3, false));
>              method.getParams().setContentCharset("UTF-8");
> 
>              try {
>                  int statusCode = client.executeMethod(method);
> 
>                  if (statusCode != HttpStatus.SC_OK) {
>                      System.err.println("Method failed: " +
> method.getStatusLine());
> 
>                      handler.showHTTPError(new String
> (method.getResponseBody(), "UTF-8"), statusCode);
>                  } else {
>                      StringBuffer sb = new StringBuffer();
>                      BufferedReader in = new BufferedReader(new
> InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
>                      String line;
>                      try {
>                          while ((line = in.readLine()) != null) {
>                              sb.append(line);
>                          }
>                      } catch (IOException exc) {
>                      }
>                      lastResult = sb.toString();
>                      sb = null;
>                  }
> 
>                  processClientState(client.getState());
> 
>                  ret = true; //true
>              } catch (HttpException e) {
>                  System.err.println("Fatal protocol violation: " +
> e.getMessage());
>                  // e.printStackTrace();
>              } catch (IOException e) {
>                  System.err.println("Fatal transport error: " +
> e.getMessage());
>                  // e.printStackTrace();
>              } catch (SecurityException e) {
>                  System.err.println("Security error: " + e.getMessage
> ());
>              } finally {
>                  // Release the connection.
>                  method.releaseConnection();
>              }
>          }
>          return ret;
>      }
> 
> 
> Partial log sent by customer:
> ======================
> 
> class com.netforum.talk2me.ProxyPanel.getParams(): USING PROXY:
> {user=HUADM\ruttkail, passwd=***********, host=10.0.10.xxx,
> port=3128} class
> com.netforum.talk2me.ProxyPanel.getParams(): USING PROXY:
> {user=HUADM\ruttkail, passwd=***********, host=10.0.10.xxx, port=3128}
> Modality popped Loaded Root CA certificates from
> C:\PROGRA~1\Java\J2RE14~2.2_0\lib\security\cacerts Loaded JPI
> certificates
> from C:\Documents and Settings\ruttkail\Application
> Data\Sun\Java\Deployment\security\deployment.certs Loading
> certificates from
> JPI session certificate store Loaded certificates from JPI session
> certificate store Checking if certificate is in JPI permanent
> certificate
> store Checking if certificate is in JPI session certificate store
> 2005.07.05. 16:59:45
> org.apache.commons.httpclient.auth.AuthChallengeProcessor
> selectAuthScheme
> INFO: ntlm authentication scheme selected
> 2005.07.05. 16:59:45 org.apache.commons.httpclient.HttpMethodDirector
> processProxyAuthChallenge INFO: No credentials available for NTLM <any
> realm>@10.0.10.111:3128
> Method failed: HTTP/1.0 407 Proxy Authentication Required
> java.lang.NullPointerException
> at com.netforum.talk2me.comm.CommController.login(CommController.java:
> 227)
> at com.netforum.talk2me.OperatorApplet.start(OperatorApplet.java:116)
> at sun.applet.AppletPanel.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source) Exception:
> java.lang.NullPointerException
> 
> 
> 
> So that's all.
> Thanks in advance,
> 
>      Gábor
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message