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

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

This example Play Framework source code file (package.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

amlya9vc8_uij4-y4k_x2e_mdv-123-abc, api, lib, library, map, mwrsjz/9aomqt9gh6ztzifijk6g, params, play, play framework, richurl, seq, string, url

The package.scala Play Framework example source code

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

import io.Source
import org.jboss.netty.handler.codec.http.QueryStringDecoder
import java.net.{MalformedURLException, URL}
import util.control.Exception._
import collection.JavaConverters._

import scala.language.implicitConversions


package object openid {
  type Params = Map[String, Seq[String]]

  implicit def stringToSeq(s: String): Seq[String] = Seq(s)

  implicit def urlToRichUrl(url: URL) = new RichUrl[URL] {
    def hostAndPath = new URL(url.getProtocol, url.getHost, url.getPort, url.getPath).toExternalForm
  }

  def readFixture(filePath: String) = this.synchronized {
    Source.fromInputStream(this.getClass.getResourceAsStream(filePath)).mkString
  }

  def parseQueryString(url: String): Params = {
    catching(classOf[MalformedURLException]) opt new URL(url) map {
      url =>
        new QueryStringDecoder(url.toURI.getRawQuery, false).getParameters.asScala.mapValues(_.asScala.toSeq).toMap
    } getOrElse Map()
  }

  // See 10.1 - Positive Assertions
  // http://openid.net/specs/openid-authentication-2_0.html#positive_assertions
  def createDefaultResponse(claimedId: String,
                            identity: String,
                            defaultSigned: String = "op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle"): Map[String, Seq[String]] = Map(
    "openid.ns" -> "http://specs.openid.net/auth/2.0",
    "openid.mode" -> "id_res",
    "openid.op_endpoint" -> "https://www.google.com/a/example.com/o8/ud?be=o8",
    "openid.claimed_id" -> claimedId,
    "openid.identity" -> identity,
    "openid.return_to" -> "https://example.com/openid?abc=false",
    "openid.response_nonce" -> "2012-05-25T06:47:55ZEJvRv76xQcWbTG",
    "openid.assoc_handle" -> "AMlYA9VC8_UIj4-y4K_X2E_mdv-123-ABC",
    "openid.signed" -> defaultSigned,
    "openid.sig" -> "MWRsJZ/9AOMQt9gH6zTZIfIjk6g="
  )

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework package.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.