Forum Discussion

srikantadan's avatar
srikantadan
New Contributor
6 years ago

try to set http header using request filter implementation in proxy nd launch browser with https url

// Set Request Filter parameters

 

def requestFilter = new RequestFilterImplementation()[Class i create their i set  method implements the filterRequest method from RequestFilter]


requestFilter.setHeaderValue(headerdata)

BrowserMobProxy proxy = new BrowserMobProxyServer()
proxy.start()
proxy.addRequestFilter(requestFilter)

Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy)

DesiredCapabilities capabilities = DesiredCapabilities.chrome()
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy)
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true)
capabilities.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, false)

WebDriver driver = new ChromeDriver(capabilities)

driver.get(URL)

 

//If i am using https://www.google.com or any https url page is not loaded.

 

But for http url it is able to open.

 

2 Replies

  • UnderTest's avatar
    UnderTest
    Occasional Contributor

    How did you setup proxy? Can you show implementation of BrowserMobProxyServer class?

    • srikantadan's avatar
      srikantadan
      New Contributor

      UnderTest wrote:

      How did you setup proxy? Can you show implementation of BrowserMobProxyServer class?


      This is my RequestFilter Implementation Class Here i set all necessary things like submitter id,password domain etc.

       

      import io.netty.handler.codec.http.HttpRequest
      import io.netty.handler.codec.http.HttpResponse
      import net.lightbody.bmp.filters.RequestFilter
      import net.lightbody.bmp.util.HttpMessageContents
      import net.lightbody.bmp.util.HttpMessageInfo

      /**
      * Class implements RequestFilter to set the headers while opening the HTTPS Url
      *
      @* @version 01-September-2017
      @* @author MR030915
      */
      public class RequestFilterImplementation implements RequestFilter {

      def headerValue = ""
      def externalTransactionId = ""
      def clientDomain = ""

      /**
      * The method implements the filterRequest method from RequestFilter
      *
      * Param request HttpRequest
      * Param contents HttpMessageContents
      * Param messageInfo HttpMessageInfo
      */
      @Override
      def HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {

      request.headers().add("Authorization", headerValue)
      request.headers().add("externalTransactionId", externalTransactionId)
      request.headers().add("transactionType", "REALTIME")
      request.headers().add("usageIndicator", "T")
      request.headers().add("type", "transaction_id,external_id")
      request.headers().add("identifier", "1234567,12345678")
      request.headers().add("solutionApplication", "Millennium")
      request.headers().add("solutionVersion", "2017.05.01")
      request.headers().add("originalSolutionApplication", "Self-Pay-Remittance")
      request.headers().add("clientDomain", clientDomain)
      request.headers().add("userID", "JT011552")
      request.headers().add("userFirstName", "XYZ")
      request.headers().add("userLastName", "XYZ")
      request.headers().add("isTwoPhase", "false")

      return null
      }

      /**
      * The method sets the header value using the Submitter ID and Password
      *
      * Param Submitter ID
      * Param Submitter Password
      */
      def setHeaderValue(def submitterId, def submitterPassword) {

      headerValue = Base64.getEncoder().encodeToString((submitterId+":"+submitterPassword).getBytes());
      }

      /**
      * The method sets the header value using the Submitter ID and Password with Basic
      *
      * Param Submitter ID
      * Param Submitter Password
      */
      def headerValueSet(def submitterId, def submitterPassword) {
      def value = Base64.getEncoder().encodeToString((submitterId+":"+submitterPassword).getBytes());
      headerValue = "Basic ${value}"
      }

      /**
      * The method sets the External Transaction Identifier
      *
      * Param External Transaction ID
      */
      def setExternalTransactionId(def extId) {

      externalTransactionId = extId;
      }

      /**
      * The method sets the Client Domain
      *
      * Param Client Domain
      */
      def setClientDomain(def domainName) {

      clientDomain = domainName;
      }
      }