Skip to content

Commit

Permalink
Upgrade to ssl-config 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed May 15, 2019
1 parent 41e8579 commit 1400690
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 88 deletions.
59 changes: 21 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,19 @@ val javacSettings = Seq(
"-Xlint:unchecked"
)

def scalacOptionsFor(scalaBinVersion: String): Seq[String] = scalaBinVersion match {
case "2.11" => Seq(
"-target:jvm-1.8",
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",

// The next two flags are not supported by 2.13
"-Ywarn-unused-import",
"-Ywarn-nullary-unit",

"-Xfatal-warnings",
"-Xlint",
"-Ywarn-dead-code"
)
case _ => Seq(
"-target:jvm-1.8",
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",

// The next two flags are not supported by 2.11
"-Ywarn-unused:imports",
"-Xlint:nullary-unit",

"-Xfatal-warnings",
"-Xlint",
"-Ywarn-dead-code",

// Work around 2.12 bug which prevents javadoc in nested java classes from compiling.
"-no-java-comments"
)
}
def scalacOpts: Seq[String] = Seq(
"-target:jvm-1.8",
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",

"-Ywarn-unused:imports",
"-Xlint:nullary-unit",

"-Xlint",
"-Ywarn-dead-code",
)

lazy val mimaSettings = mimaDefaultSettings ++ Seq(
mimaPreviousArtifacts := {
Expand All @@ -87,7 +65,13 @@ lazy val commonSettings = Seq(
organization := "com.typesafe.play",
scalaVersion := scala212,
crossScalaVersions := Seq(scala213, scala212),
scalacOptions in (Compile, doc) ++= scalacOptionsFor(scalaBinaryVersion.value),
scalacOptions ++= scalacOpts,
scalacOptions in (Compile, doc) ++= Seq(
"-Xfatal-warnings",

// Work around 2.12 bug which prevents javadoc in nested java classes from compiling.
"-no-java-comments",
),
pomExtra := (
<url>https://github.com/playframework/play-ws</url>
<licenses>
Expand All @@ -108,9 +92,8 @@ lazy val commonSettings = Seq(
<url>http://playframework.com/</url>
</developer>
</developers>),
javacOptions in (Compile, doc) ++= javacSettings,
javacOptions in Compile ++= javacSettings,
javacOptions in Test ++= javacSettings,
javacOptions in IntegrationTest ++= javacSettings,
headerLicense := {
val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue
Some(HeaderLicense.Custom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv) extends Specifica
"not keep cookie when repeating the request" in {
withClientFollowingRedirect() { client =>
// First let's do a request that sets a cookie
val res1 = Await.result(client.url(s"http://localhost:$testServerPort/cookie").get().map(res => res.body[String]), defaultTimeout)
Await.result(client.url(s"http://localhost:$testServerPort/cookie").get().map(res => res.body[String]), defaultTimeout)

// Then run a request to a url that checks the cookie, but without setting it
val res2 = Await.result(client.url(s"http://localhost:$testServerPort/cookie-destination").get().map(res => res.body[String]), defaultTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CachingSpec(implicit val executionEnv: ExecutionEnv) extends Specification

"work once" in {
val cache = mock[Cache]
cache.get(any()) returns Future.successful(None)
cache.get(any[EffectiveURIKey]()) returns Future.successful(None)

val cachingAsyncHttpClient = new CachingAsyncHttpClient(asyncHttpClient, new AhcHttpCache(cache))
val ws = new StandaloneAhcWSClient(cachingAsyncHttpClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv) extends Specifica
dbf.setCoalescing(true)
dbf.setIgnoringElementContentWhitespace(true)
dbf.setIgnoringComments(true)
val db = dbf.newDocumentBuilder
dbf.newDocumentBuilder

val responseXml = response.getBody(xml())
responseXml.normalizeDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import akka.util.ByteString;
import akka.util.ByteStringBuilder;
import com.typesafe.sslconfig.ssl.SystemConfiguration;
import com.typesafe.sslconfig.ssl.debug.DebugConfiguration;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
Expand Down Expand Up @@ -171,11 +170,6 @@ public static StandaloneAhcWSClient create(AhcWSClientConfig ahcWSClientConfig,
public static StandaloneAhcWSClient create(AhcWSClientConfig ahcWSClientConfig, AhcHttpCache cache, Materializer materializer) {
AhcLoggerFactory loggerFactory = new AhcLoggerFactory(LoggerFactory.getILoggerFactory());

// Set up debugging configuration
if (ahcWSClientConfig.wsClientConfig().ssl().debug().enabled()) {
new DebugConfiguration(loggerFactory).configure(ahcWSClientConfig.wsClientConfig().ssl().debug());
}

// Configure the AsyncHttpClientConfig.Builder from the application.conf file...
final AhcConfigBuilder builder = new AhcConfigBuilder(ahcWSClientConfig);
final DefaultAsyncHttpClientConfig.Builder ahcBuilder = builder.configure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import play.shaded.ahc.io.netty.buffer.ByteBuf;
import play.shaded.ahc.io.netty.buffer.Unpooled;
import play.shaded.ahc.io.netty.handler.codec.http.DefaultHttpHeaders;
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames;
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders;
import play.shaded.ahc.io.netty.handler.codec.http.cookie.Cookie;
import play.shaded.ahc.io.netty.handler.codec.http.cookie.DefaultCookie;
Expand Down Expand Up @@ -43,9 +44,9 @@
import java.util.concurrent.CompletionStage;

import static java.util.Collections.singletonList;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
import static play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED;

/**
* Provides the User facing API for building a WS request.
Expand Down Expand Up @@ -231,12 +232,12 @@ public StandaloneAhcWSRequest setRequestTimeout(Duration timeout) {

@Override
public StandaloneAhcWSRequest setContentType(String contentType) {
return addHeader(CONTENT_TYPE, contentType);
return addHeader(CONTENT_TYPE.toString(), contentType);
}

@Override
public Optional<String> getContentType() {
return getHeader(CONTENT_TYPE);
return getHeader(CONTENT_TYPE.toString());
}

@Override
Expand All @@ -263,8 +264,8 @@ public StandaloneAhcWSRequest setBody(BodyWritable bodyWritable) {
this.bodyWritable = bodyWritable;

String contentType = bodyWritable.contentType();
if (!headers.containsKey(HttpHeaders.Names.CONTENT_TYPE) && contentType != null) {
this.addHeader(HttpHeaders.Names.CONTENT_TYPE, bodyWritable.contentType());
if (!headers.containsKey(HttpHeaderNames.CONTENT_TYPE.toString()) && contentType != null) {
this.addHeader(HttpHeaderNames.CONTENT_TYPE.toString(), bodyWritable.contentType());
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import play.libs.ws.BodyReadable;
import play.libs.ws.StandaloneWSResponse;
import play.libs.ws.WSCookie;
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames;
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders;
import play.shaded.ahc.org.asynchttpclient.HttpResponseBodyPart;
import scala.collection.Seq;
Expand Down Expand Up @@ -88,7 +89,7 @@ public Optional<WSCookie> getCookie(String name) {

@Override
public String getContentType() {
return getSingleHeader(HttpHeaders.Names.CONTENT_TYPE).orElse("application/octet-stream");
return getSingleHeader(HttpHeaderNames.CONTENT_TYPE.toString()).orElse("application/octet-stream");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import com.typesafe.sslconfig.ssl.SystemConfiguration
import com.typesafe.sslconfig.ssl.debug.DebugConfiguration
import org.reactivestreams.Publisher
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription
Expand Down Expand Up @@ -211,10 +210,6 @@ object StandaloneAhcWSClient {
config: AhcWSClientConfig = AhcWSClientConfigFactory.forConfig(),
httpCache: Option[AhcHttpCache] = None
)(implicit materializer: Materializer): StandaloneAhcWSClient = {
if (config.wsClientConfig.ssl.debug.enabled) {
new DebugConfiguration(StandaloneAhcWSClient.loggerFactory)
.configure(config.wsClientConfig.ssl.debug)
}
val ahcConfig = new AhcConfigBuilder(config).build()
val asyncHttpClient = new DefaultAsyncHttpClient(ahcConfig)
val wsClient = new StandaloneAhcWSClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import org.specs2.mutable.Specification
import org.specs2.specification.AfterAll
import play.api.libs.oauth.{ ConsumerKey, OAuthCalculator, RequestToken }
import play.api.libs.ws._
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaders
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames
import play.shaded.ahc.org.asynchttpclient.Realm.AuthScheme
import play.shaded.ahc.io.netty.handler.codec.http.cookie.{ Cookie => AHCCookie }
import play.shaded.ahc.org.asynchttpclient.{ Param, RequestBuilderBase, SignatureCalculator, Request => AHCRequest }

import play.shaded.ahc.org.asynchttpclient.{ Param, SignatureCalculator, Request => AHCRequest }
import scala.collection.JavaConverters._
import scala.concurrent.duration._
import scala.language.implicitConversions

class AhcWSRequestSpec extends Specification with Mockito with AfterAll with DefaultBodyReadables with DefaultBodyWritables {

Expand Down Expand Up @@ -257,7 +254,7 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
.withBody("I am a text/plain body")
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
req.getHeaders.getAll(HttpHeaders.Names.CONTENT_TYPE).asScala must_== Seq("fake/contenttype; charset=utf-8")
req.getHeaders.getAll(HttpHeaderNames.CONTENT_TYPE.toString()).asScala must_== Seq("fake/contenttype; charset=utf-8")
}
}

Expand Down Expand Up @@ -372,9 +369,8 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def

"Have form body for content type text/plain" in {
withClient { client =>
val formEncoding = java.net.URLEncoder.encode("param1=value1", "UTF-8")
val req: AHCRequest = client.url("http://playframework.com/")
.withHttpHeaders(HttpHeaders.Names.CONTENT_TYPE -> "text/plain")
.withHttpHeaders(HttpHeaderNames.CONTENT_TYPE.toString() -> "text/plain")
.withBody("HELLO WORLD")
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
Expand All @@ -388,7 +384,7 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
"Have form body for content type application/x-www-form-urlencoded explicitly set" in {
withClient { client =>
val req: AHCRequest = client.url("http://playframework.com/")
.withHttpHeaders(HttpHeaders.Names.CONTENT_TYPE -> "application/x-www-form-urlencoded") // set content type by hand
.withHttpHeaders(HttpHeaderNames.CONTENT_TYPE.toString() -> "application/x-www-form-urlencoded") // set content type by hand
.withBody("HELLO WORLD") // and body is set to string (see #5221)
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
Expand All @@ -399,7 +395,7 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
"Send binary data as is" in withClient { client =>
val binData = ByteString((0 to 511).map(_.toByte).toArray)
val req: AHCRequest = client.url("http://playframework.com/")
.addHttpHeaders(HttpHeaders.Names.CONTENT_TYPE -> "application/x-custom-bin-data")
.addHttpHeaders(HttpHeaderNames.CONTENT_TYPE.toString() -> "application/x-custom-bin-data")
.withBody(binData)
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
Expand Down Expand Up @@ -475,7 +471,7 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
}
}
withClient { client =>
val req = client.url("http://playframework.com/").sign(calc)
client.url("http://playframework.com/").sign(calc)
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
called must beTrue
Expand Down Expand Up @@ -538,9 +534,6 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
}

"Not remove a user defined content length header" in withClient { client =>
val consumerKey = ConsumerKey("key", "secret")
val requestToken = RequestToken("token", "secret")
val calc = OAuthCalculator(consumerKey, requestToken)
val req: AHCRequest = client.url("http://playframework.com/").withBody(Map("param1" -> Seq("value1")))
.withHttpHeaders("Content-Length" -> "9001") // add a meaningless content length here...
.asInstanceOf[StandaloneAhcWSRequest]
Expand Down Expand Up @@ -572,11 +565,11 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def
"Verify Content-Type header is passed through correctly" in withClient { client =>
import scala.collection.JavaConverters._
val req: AHCRequest = client.url("http://playframework.com/")
.withHttpHeaders(HttpHeaders.Names.CONTENT_TYPE -> "text/plain; charset=US-ASCII")
.withHttpHeaders(HttpHeaderNames.CONTENT_TYPE.toString() -> "text/plain; charset=US-ASCII")
.withBody("HELLO WORLD")
.asInstanceOf[StandaloneAhcWSRequest]
.buildRequest()
req.getHeaders.getAll(HttpHeaders.Names.CONTENT_TYPE).asScala must_== Seq("text/plain; charset=US-ASCII")
req.getHeaders.getAll(HttpHeaderNames.CONTENT_TYPE.toString()).asScala must_== Seq("text/plain; charset=US-ASCII")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.specs2.mock.Mockito
import org.specs2.mutable._
import play.libs.oauth.OAuth
import play.libs.ws._
import play.shaded.ahc.io.netty.handler.codec.http.{ HttpHeaderNames, HttpHeaders }
import play.shaded.ahc.io.netty.handler.codec.http.HttpHeaderNames
import play.shaded.ahc.org.asynchttpclient.{ Request, RequestBuilderBase, SignatureCalculator }

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -60,8 +60,6 @@ class AhcWSRequestSpec extends Specification with Mockito with DefaultBodyReadab

"set text/plain content-types for text bodies" in {
val client = mock[StandaloneAhcWSClient]
val formEncoding = java.net.URLEncoder.encode("param1=value1", "UTF-8")

val req = new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
.setBody(body("HELLO WORLD"))
.asInstanceOf[StandaloneAhcWSRequest]
Expand Down Expand Up @@ -152,7 +150,7 @@ class AhcWSRequestSpec extends Specification with Mockito with DefaultBodyReadab
called = true
}
}
val req = new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
.sign(calc)
.buildRequest()
called must beTrue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package play.libs.ws.ahc

import java.nio.charset.StandardCharsets

import org.specs2.mock.Mockito
import org.specs2.mutable._
import play.libs.ws._
Expand All @@ -17,8 +15,6 @@ import scala.compat.java8.OptionConverters._

class AhcWSResponseSpec extends Specification with Mockito with DefaultBodyReadables with DefaultBodyWritables {

private val emptyMap = new java.util.HashMap[String, java.util.Collection[String]]

"getUnderlying" should {

"return the underlying response" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import play.api.libs.json.jackson.PlayJsonModule$;
import play.api.libs.json.JsonParserSettings;
import play.api.libs.json.jackson.PlayJsonModule;

/**
*
*/
public class DefaultObjectMapper {

public static final ObjectMapper instance = new ObjectMapper()
.registerModule(PlayJsonModule$.MODULE$)
.registerModule(new PlayJsonModule(JsonParserSettings.apply()))
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ default BodyWritable<ByteString> body(ByteBuffer buffer, String contentType) {
* @return a {@link SourceBodyWritable} instance.
*/
default BodyWritable<Source<ByteString, ?>> body(File file) {
return new SourceBodyWritable(FileIO.fromFile(file));
return new SourceBodyWritable(FileIO.fromPath(file.toPath()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Dependencies {

val javaxInject = Seq("javax.inject" % "javax.inject" % "1")

val sslConfigVersion = "0.3.7"
val sslConfigVersion = "0.4.0"
val sslConfigCore = Seq("com.typesafe" %% "ssl-config-core" % sslConfigVersion)

val scalaXmlVersion = "1.1.1"
Expand Down

0 comments on commit 1400690

Please sign in to comment.