title: upgrading commons-httpclient-3.1.jar to httpclient-4.5.2.jar
body: <p>Well due to some vulnerability we need to move from commons-httpclient-3.1.jar to httpclient-4.5.2.jar</p>
  
  <p>Now  have a code base which was working before on 3.1, but the methods are depreceted in 4.5.2. Do you have any idea or came across on how to overcome these errors</p>
  
  <p>Error I get is 
  1) The import org.apache.commons.httpclient.HostConfiguration cannot be resolved
  2) The method getState() is undefined for the type HttpClient</p>
  
  <p>Here is the source code. Let me know if you have any information. </p>
  
  <pre><code>import org.apache.axis.MessageContext;
  
  import org.apache.axis.components.net.TransportClientProperties;
  import org.apache.axis.components.net.TransportClientPropertiesFactory;
  import org.apache.http.auth.Credentials;
  import org.apache.commons.httpclient.HostConfiguration;
  import org.apache.http.client.HttpClient;
  import org.apache.http.auth.NTCredentials;
  import org.apache.http.auth.UsernamePasswordCredentials;
  import org.apache.http.auth.AuthScope;
  import java.net.URL;
  
  
  public class CommonsHTTPSender extends
          org.apache.axis.transport.http.CommonsHTTPSender {
  
      public static final String PROPERTY_PROXY_HOST = "https.proxyHost";
      public static final String PROPERTY_PROXY_PORT = "https.proxyPort";
      public static final String PROPERTY_PROXY_USERNAME = "https.proxyUser";
      public static final String PROPERTY_PROXY_PASSWORD = "https.proxyPassword";
  
      public CommonsHTTPSender() {
      }
  
      protected HostConfiguration getHostConfiguration(HttpClient client,
              MessageContext context, URL targetURL) {
  
          HostConfiguration config = new HostConfiguration();
          if ( targetURL.getProtocol().equalsIgnoreCase("https") )
          {
              //Jli: our changes start from here. There is a defect in the DefaultHTTPSTransportClientProperties.
              // The class is only called once to get the proxy setttings from the system properties. If users
              // Change the proxy settings, the class will not pick up the changes. On our DMDI GUI, users
              // can make the changes as often as they can. This will create an issue that when the apache axis
              // reconnect, it only picks up the proxy setup that users put in the GUI the first time.
              // We only use the HTTPS, so this change is only valid for the https.  
  
              int urlPort = targetURL.getPort();
              if (urlPort == -1) {
                  urlPort = 443; // default port for https being 443
              }
              String proxyHost = (String)System.getProperty(PROPERTY_PROXY_HOST);
              String proxyPort = (String)System.getProperty(PROPERTY_PROXY_PORT);
              String proxyUsername = (String)System.getProperty(PROPERTY_PROXY_USERNAME);
              String proxyPassword = (String)System.getProperty(PROPERTY_PROXY_PASSWORD);
  
              if ( proxyHost == null || proxyPort == null ||
                      proxyHost.length() == 0  || proxyPort.length() == 0) {
                    config.setHost(targetURL.getHost(), urlPort, targetURL
                            .getProtocol());
              } else {
                   if ( proxyUsername != null &amp;&amp;  proxyPassword != null &amp;&amp; proxyUsername.length() != 0) {
                      Credentials proxyCred = new UsernamePasswordCredentials(proxyUsername,
                              proxyPassword);
                      // if the username is in the form "user\domain"
                      // then use NTCredentials instead.
                      int domainIndex = proxyUsername.indexOf("\\");
                      if (domainIndex &gt; 0) {
                          String domain = proxyUsername.substring(0,
                                  domainIndex);
                          if (proxyUsername.length() &gt; domainIndex + 1) {
                              String user = proxyUsername.substring(
                                      domainIndex + 1);
                              proxyCred = new NTCredentials(user, proxyPassword, proxyHost,
                                      domain);
                          }
                      }
                      client.getState().setProxyCredentials(AuthScope.ANY,
                              proxyCred);
  
  
  
                  }
                  int proxyPortInt = new Integer(proxyPort).intValue();
                  config.setProxy(proxyHost, proxyPortInt);
              }     
          }
          else
          {
              config = super.getHostConfiguration(client, context, targetURL);
          }
          return config;
      }
  
  }
  </code></pre>