Support Article

How do we support multiple proxy servers?

SA-20370

Summary



Customer has multiple connectors and currently the connector calls are going through a single proxy server (with jvm settings http.proxyHost and http.proxyPort). They want to know if it is possible to configure PRPC to go through different proxies server based on certain criteria.


Error Messages



Not Applicable 

Steps to Reproduce



Configure more than one connectors and have each connector go through its own proxy server.

Root Cause



Need a solution to work with multi proxies from 1 JVM for http connector.

Resolution

Recommend customer to try out the changes below in step 12 of pyInovkeRESTConnector,
……….
    /////////////////////////////////////////////////////////////////////////////////////
    //
    // Execute the HTTP Call
    //
    com.pega.apache.http.HttpResponse httpResponse = null;
    try
    {
        svcUtil.startConnectClientResponseElapsedStat();
        // Execute the method.
     
        // new proxy selector
        class MyProxySelector extends java.net.ProxySelector {
       
        java.net.ProxySelector defsel = null;
    
       
           public MyProxySelector(java.net.ProxySelector def) {
               oLog.infoForced("selector constructor...");
                defsel = def;
           }
       
        public java.util.List<java.net.Proxy> select(java.net.URI uri) {
          oLog.infoForced("inside select....");
         
          List<java.net.Proxy> ret = new java.util.ArrayList<java.net.Proxy>();
          List<java.net.Proxy> proxyList = new java.util.ArrayList<java.net.Proxy>();
 
           // below is just example (setting different proxies based on protocol) but you should modify according to your requirement
          if ("http".equalsIgnoreCase(uri.getScheme())) {
            java.net.SocketAddress proxyAddress1 = new java.net.InetSocketAddress("localhost", 8888);
            proxyList.add(new java.net.Proxy(java.net.Proxy.Type.HTTP, proxyAddress1));
          ret = proxyList;
          } else if("https".equalsIgnoreCase(uri.getScheme())) {
            java.net.SocketAddress proxyAddress2 = new java.net.InetSocketAddress("localhost", 9999);
            proxyList.add(new java.net.Proxy(java.net.Proxy.Type.HTTP, proxyAddress2));
          ret = proxyList;           
          }
         
          return ret;
        }
       
         public void connectFailed(java.net.URI uri, java.net.SocketAddress sa, java.io.IOException ioe) {
           oLog.infoForced("inside connectFailed...");
         }
      }
     
      java.net.ProxySelector.setDefault(new MyProxySelector(java.net.ProxySelector.getDefault()));
     
     
        // don't need to check type of httpRequest here...
        httpResponse = client.execute(httpRequest, (com.pega.apache.http.protocol.BasicHttpContext)localContext);
………..
 

Suggest Edit

Published March 4, 2016 - Updated October 8, 2020

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.