alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (Config.scala)

This example Play Framework source code file (Config.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

api, classloader, configuration, defaultsslconfigparser, defaultwsclientconfig, defaultwsconfigparser, lib, library, none, option, play, play framework, ws, wsclientconfig

The Config.scala Play Framework example source code

/*
 *
 *  * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 *
 */
package play.api.libs.ws

import play.api.libs.ws.ssl.{ DefaultSSLConfig, DefaultSSLConfigParser, SSLConfig }
import play.api.Configuration

/**
 * A WSConfiguration trait.  This provides bindings that can be passed into any implementation of WSClient.
 */
trait WSClientConfig {

  def connectionTimeout: Option[Long]

  def idleTimeout: Option[Long]

  def requestTimeout: Option[Long]

  def followRedirects: Option[Boolean]

  def useProxyProperties: Option[Boolean]

  def userAgent: Option[String]

  def compressionEnabled: Option[Boolean]

  def acceptAnyCertificate: Option[Boolean]

  def ssl: Option[SSLConfig]
}

/**
 * Default client config option.
 */
case class DefaultWSClientConfig(connectionTimeout: Option[Long] = None,
  idleTimeout: Option[Long] = None,
  requestTimeout: Option[Long] = None,
  followRedirects: Option[Boolean] = None,
  useProxyProperties: Option[Boolean] = None,
  userAgent: Option[String] = None,
  compressionEnabled: Option[Boolean] = None,
  acceptAnyCertificate: Option[Boolean] = None,
  ssl: Option[SSLConfig] = None) extends WSClientConfig

/**
 * This class creates a DefaultWSClientConfig object from the play.api.Configuration.
 */
class DefaultWSConfigParser(configuration: Configuration, classloader: ClassLoader) {

  def parse(): WSClientConfig = {
    // .getOrElse(120000L)
    val connectionTimeout = configuration.getMilliseconds("ws.timeout.connection")
    val idleTimeout = configuration.getMilliseconds("ws.timeout.idle")
    val requestTimeout = configuration.getMilliseconds("ws.timeout.request")

    // default: true
    val followRedirects = configuration.getBoolean("ws.followRedirects")

    // default: true
    val useProxyProperties = configuration.getBoolean("ws.useProxyProperties")

    val userAgent = configuration.getString("ws.useragent")

    val compressionEnabled = configuration.getBoolean("ws.compressionEnabled")

    val acceptAnyCertificate = configuration.getBoolean("ws.acceptAnyCertificate")

    val sslConfig = configuration.getConfig("ws.ssl").map { sslConfig =>
      val sslContextParser = new DefaultSSLConfigParser(sslConfig, classloader)
      sslContextParser.parse()
    }

    DefaultWSClientConfig(
      connectionTimeout = connectionTimeout,
      idleTimeout = idleTimeout,
      requestTimeout = requestTimeout,
      followRedirects = followRedirects,
      useProxyProperties = useProxyProperties,
      userAgent = userAgent,
      compressionEnabled = compressionEnabled,
      acceptAnyCertificate = acceptAnyCertificate,
      ssl = sslConfig)
  }
}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework Config.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.