title: Timeout error while connecting org.apache.http.conn.HttpHostConnect
body: <p>I am trying to make a SOAP activity with digest authorization. When i am trying to connect to the test service, I get the below error:</p>
  <pre><code>Exception in thread &quot;main&quot; org.apache.http.conn.HttpHostConnectException: Connect to httpbin.org:135 [httpbin.org/34.231.30.52, httpbin.org/54.166.163.67, httpbin.org/54.91.118.50, httpbin.org/34.199.75.4] failed: Connection timed out: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
    at SOAPClientApache.run(SOAPClientApache.java:94)
    at Main.main(Main.java:4)
  Caused by: java.net.ConnectException: Connection timed out: connect
    at java.base/java.net.PlainSocketImpl.connect0(Native Method)
    at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.base/java.net.Socket.connect(Socket.java:609)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
      ... 10 more
  </code></pre>
  <p>What I did for the solution:</p>
  <ol>
  <li>Changed the port number</li>
  <li>Changed the URL</li>
  <li>Changed the PC on which the project was launched...Nothing helped me :(</li>
  </ol>
  <p>I would be grateful for any help. Code:</p>
  <p><strong>SOAPClientApache</strong></p>
  <pre><code>import java.io.Serializable;
  import java.security.KeyManagementException;
  import java.security.NoSuchAlgorithmException;
  import java.security.cert.CertificateException;
  import java.security.cert.X509Certificate;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Map;
  import java.util.stream.Collectors;
  
  import org.apache.commons.io.IOUtils;
  import org.apache.http.*;
  import org.apache.http.auth.AuthScope;
  import org.apache.http.auth.UsernamePasswordCredentials;
  import org.apache.http.client.*;
  import org.apache.http.client.methods.CloseableHttpResponse;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.protocol.HttpClientContext;
  import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
  import org.apache.http.conn.ssl.NoopHostnameVerifier;
  import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
  import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
  import org.apache.http.impl.auth.DigestScheme;
  import org.apache.http.impl.client.*;
  import org.apache.http.ssl.SSLContextBuilder;
  import org.testng.Assert;
  
  import javax.net.ssl.*;
  
  public class SOAPClientApache {
  
  
  private static final String URL = &quot;http://httpbin.org/digest-auth/auth/user/passwd&quot;;
  //private static final String URL = &quot;https://www.google.com/&quot;;
  
  private static final String PASSWORD = &quot;&quot;;
  
  private static final String USER = &quot;&quot;;
  
  public void run() throws Exception {
  
      HttpGet httpget = new HttpGet(URL);
  
      HttpHost target
              = new HttpHost(httpget.getURI().getHost(), 135, &quot;https&quot;);
      CredentialsProvider credsProvider = new BasicCredentialsProvider();
  
      UsernamePasswordCredentials credentials
              = new UsernamePasswordCredentials(USER, PASSWORD);
      credsProvider.setCredentials(
              new AuthScope(target.getHostName(), target.getPort()),
              credentials);
  
      CookieStore cookieStore = new BasicCookieStore();
  
      //Start fix SSL (убиваем проверку сертификатов)
      SSLContextBuilder builder = new SSLContextBuilder();
      builder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
          @Override
          public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
              return true;
          }
      });
      SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(),
              SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      //End fix SSL
  
      //SSL solution (ДО обхода проверки SSL)
      /*CloseableHttpClient httpclient
              = HttpClients.custom().setDefaultCookieStore(cookieStore)
              .setDefaultCredentialsProvider(credsProvider).build();*/
  
  
      CloseableHttpClient httpclient
              = HttpClients.custom().setDefaultCookieStore(cookieStore)
              .setDefaultCredentialsProvider(credsProvider).setSSLSocketFactory(sslSF).build();
  
      try {
  
          DigestScheme digestAuth = new DigestScheme();
  
          digestAuth.overrideParamter(&quot;qop&quot;, &quot;auth&quot;);
          digestAuth.overrideParamter(&quot;nc&quot;, &quot;0&quot;);
          digestAuth.overrideParamter(&quot;cnonce&quot;, DigestScheme.createCnonce());
  
          AuthCache authCache = new BasicAuthCache();
          authCache.put(target, digestAuth);
  
          HttpClientContext localContext = HttpClientContext.create();
          localContext.setAuthCache(authCache);
  
          CloseableHttpResponse response;
  
          response = httpclient.execute(target, httpget, localContext);
          Map&lt;String, String&gt; wwwAuth = Arrays
                  .stream(response.getHeaders(&quot;WWW-Authenticate&quot;)[0]
                          .getElements())
                  .collect(Collectors.toMap(HeaderElement::getName,
                          HeaderElement::getValue));
  
          // the first call ALWAYS fails with a 401
          Assert.assertEquals(response.getStatusLine().getStatusCode(), 401);
  
          digestAuth.overrideParamter(&quot;opaque&quot;, wwwAuth.get(&quot;opaque&quot;));
          digestAuth.overrideParamter(&quot;nonce&quot;, wwwAuth.get(&quot;nonce&quot;));
          digestAuth.overrideParamter(&quot;realm&quot;, wwwAuth.get(&quot;Digest realm&quot;));
          Header authenticate = digestAuth.authenticate(credentials, httpget,
                  localContext);
          httpget.addHeader(authenticate);
  
          response = httpclient.execute(target, httpget, localContext);
  
          // the 2nd call is the real deal
          Assert.assertEquals(response.getStatusLine().getStatusCode(), 200);
  
          System.out.println(IOUtils
                  .toString(response.getEntity().getContent(), &quot;utf-8&quot;));
  
  
      } finally {
          httpclient.close();
      }
  }
  </code></pre>
  <p>}</p>
  <p><strong>Main</strong></p>
  <pre><code>public class Main {
      public static void main(String[] args) throws Exception {
          SOAPClientApache soapClientApache = new SOAPClientApache();
          soapClientApache.run();
      }
  }
  </code></pre>