Skip to content

Commit 5e6c410

Browse files
committed
Fix file issue
1 parent 9fb41c6 commit 5e6c410

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main/resources/logback.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<logger name="akka" level="DEBUG"/>
3333
<!-- Turn down Docker noise -->
3434
<logger name="com.github.dockerjava" level="INFO"/>
35+
<!-- Turn down http client noise -->
36+
<logger name="org.apache.hc.client5.http.wire" level="INFO"/>
3537

3638
<!-- Turn up Eclipse Paho logging in MqttPahoEcho
3739
<logger name="org.eclipse.paho" level="DEBUG"/> -->

src/main/scala/alpakka/env/FileServer.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.apache.pekko.http.scaladsl.server.{ExceptionHandler, Route}
1010
import org.slf4j.{Logger, LoggerFactory}
1111

1212
import java.io.File
13+
import java.nio.file.Paths
1314
import scala.concurrent.duration.*
1415
import scala.util.{Failure, Success}
1516

@@ -38,6 +39,7 @@ object FileServer extends App {
3839

3940
def server(address: String, port: Int): Unit = {
4041
val resourceFileName = "payload.zip"
42+
val payloadFile = new File(Paths.get("src/main/resources", resourceFileName).toAbsolutePath.toString)
4143

4244
val cache: Cache[String, String] =
4345
Scaffeine()
@@ -61,8 +63,7 @@ object FileServer extends App {
6163
path("download" / Segment) { id =>
6264
logger.info(s"TRACE_ID: $id Server received download request")
6365
get {
64-
// for testing: use the same file, independent of the TRACE_ID
65-
getFromFile(new File(getClass.getResource(s"/$resourceFileName").toURI), MediaTypes.`application/zip`)
66+
getFromFile(payloadFile, MediaTypes.`application/zip`)
6667
}
6768
} ~ path("downloadflaky" / Segment) { id =>
6869
logger.info(s"TRACE_ID: $id Server received flaky download request")
@@ -72,9 +73,9 @@ object FileServer extends App {
7273
} else if (id.toInt % 5 == 0) { // 5, 15, 25
7374
// Causes TimeoutException on client if sleep time > 5 sec
7475
randomSleeper()
75-
getFromFile(new File(getClass.getResource(s"/$resourceFileName").toURI), MediaTypes.`application/zip`)
76+
getFromFile(payloadFile, MediaTypes.`application/zip`)
7677
} else {
77-
getFromFile(new File(getClass.getResource(s"/$resourceFileName").toURI), MediaTypes.`application/zip`)
78+
getFromFile(payloadFile, MediaTypes.`application/zip`)
7879
}
7980
}
8081
} ~ path("downloadni" / Segment) { id =>
@@ -88,7 +89,7 @@ object FileServer extends App {
8889
cache.put(id, "downloading") // to simulate blocking on concurrent requests
8990
get {
9091
randomSleeper()
91-
val response = getFromFile(new File(getClass.getResource(s"/$resourceFileName").toURI), MediaTypes.`application/zip`)
92+
val response = getFromFile(payloadFile, MediaTypes.`application/zip`)
9293
cache.put(id, "downloaded")
9394
response
9495
}
@@ -125,4 +126,4 @@ object FileServer extends App {
125126
logger.info(s" -> Complete with HTTP status code: $statusCode")
126127
statusCodes(finalRnd)
127128
}
128-
}
129+
}

0 commit comments

Comments
 (0)