Skip to content

Commit 1de2c18

Browse files
author
Hariharan Ramanathan
committed
Fixing encoded url issue for retrieve command
1 parent 3972bd4 commit 1de2c18

File tree

5 files changed

+22
-39
lines changed

5 files changed

+22
-39
lines changed

build.sbt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
scalaVersion := "2.12.4"
22

3-
name := "delphi"
3+
name := "delphi-cli"
44
version := "1.0.0-SNAPSHOT"
55
maintainer := "Ben Hermann <[email protected]>"
66

@@ -28,10 +28,12 @@ libraryDependencies += "de.vandermeer" % "asciitable" % "0.3.2"
2828
libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.5"
2929
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
3030
libraryDependencies += "au.com.bytecode" % "opencsv" % "2.4"
31+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test"
3132

32-
33-
libraryDependencies += "com.softwaremill.sttp" %% "core" % "1.5.4"
34-
33+
libraryDependencies ++= Seq(
34+
"com.softwaremill.sttp" %% "core" % "1.5.4",
35+
"com.softwaremill.sttp" %% "spray-json" % "1.5.4"
36+
)
3537

3638

3739
debianPackageDependencies := Seq("java8-runtime-headless")
@@ -45,7 +47,7 @@ lazy val cli = (project in file(".")).
4547
enablePlugins(WindowsPlugin).
4648
enablePlugins(GraalVMNativeImagePlugin).
4749
settings(
48-
graalVMNativeImageOptions++=Seq(
50+
graalVMNativeImageOptions ++= Seq(
4951
"--enable-https",
5052
"--enable-http",
5153
"--enable-all-security-services",

src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package de.upb.cs.swt.delphi.cli
1818

19-
import com.softwaremill.sttp.{HttpURLConnectionBackend, Id, SttpBackend}
2019
import de.upb.cs.swt.delphi.cli.commands._
2120

2221
/**
@@ -39,6 +38,9 @@ object DelphiCLI {
3938
cliParser.parse(args, Config()) match {
4039
case Some(c) =>
4140

41+
import com.softwaremill.sttp._
42+
import scala.concurrent.duration._
43+
4244
implicit val config: Config = c
4345
implicit val backend: SttpBackend[Id, Nothing] = HttpURLConnectionBackend()
4446

src/main/scala/de/upb/cs/swt/delphi/cli/commands/Command.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ trait Command {
3333

3434

3535
/**
36-
* Generic http GET request
36+
* Http GET request template
3737
*
3838
* @param target Sub url in delphi server
3939
* @param parameters Query params
4040
* @return GET response
4141
*/
42-
protected def executeGet(target: String, parameters: Map[String, String] = Map())
42+
protected def executeGet(paths: Seq[String], parameters: Map[String, String] = Map())
4343
(implicit config: Config, backend: SttpBackend[Id, Nothing]): Option[String] = {
44-
45-
val request = sttp.get(uri"${config.server}/$target?$parameters")
44+
val serverUrl = uri"${config.server}"
45+
val oldPath = serverUrl.path
46+
val reqUrl = serverUrl.path(oldPath ++ paths).params(parameters)
47+
val request = sttp.get(reqUrl)
4648
config.consoleOutput.outputInformation(s"Sending request ${request.uri}")
4749
val response = request.send()
4850
response.body match {

src/main/scala/de/upb/cs/swt/delphi/cli/commands/RetrieveCommand.scala

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ object RetrieveCommand extends Command with DefaultJsonProtocol {
4545
}
4646
}
4747

48+
println(config.id)
4849
val result = executeGet(
49-
s"retrieve/$checkTarget",
50+
Seq("retrieve", checkTarget),
5051
Map("pretty" -> "")
5152
)
5253

@@ -57,7 +58,8 @@ object RetrieveCommand extends Command with DefaultJsonProtocol {
5758
if (!config.raw || !config.csv.equals("")) {
5859
import artifacts.SearchResultJson._
5960

60-
//TODO: convertTo[List[RetrieveResult]] not working ???
61+
//TODO: Direct convertTo[List[RetrieveResult]] not working ???
62+
6163

6264
val jsonArr = s.parseJson.asInstanceOf[JsArray].elements
6365
val retrieveResults = jsonArr.map(r => r.convertTo[RetrieveResult])
@@ -69,31 +71,6 @@ object RetrieveCommand extends Command with DefaultJsonProtocol {
6971
information.apply("Results written to file '" + config.csv + "'")
7072
}
7173
}
72-
73-
7474
})
7575
}
7676
}
77-
78-
/* if (!config.raw || !config.csv.equals("")) {
79-
val unmarshalledFuture = Unmarshal(s).to[List[RetrieveResult]]
80-
81-
unmarshalledFuture.transform {
82-
case Success(unmarshalled) => {
83-
val unmarshalled = Await.result(unmarshalledFuture, Duration.Inf)
84-
success.apply(s"Found ${unmarshalled.size} item(s).")
85-
reportResult.apply(unmarshalled)
86-
87-
if (!config.csv.equals("")) {
88-
exportResult.apply(unmarshalled)
89-
information.apply("Results written to file '" + config.csv + "'")
90-
}
91-
92-
Success(unmarshalled)
93-
}
94-
case Failure(e) => {
95-
error.apply(s)
96-
Failure(e)
97-
}
98-
}
99-
}*/

src/main/scala/de/upb/cs/swt/delphi/cli/commands/TestCommand.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import de.upb.cs.swt.delphi.cli.Config
2424
* Tries to connect to the Delphi server and reports on the results of the version call.
2525
*/
2626
object TestCommand extends Command {
27-
override def execute(implicit config: Config,backend: SttpBackend[Id, Nothing]): Unit = {
28-
executeGet("version")
27+
override def execute(implicit config: Config, backend: SttpBackend[Id, Nothing]): Unit = {
28+
executeGet(Seq("version"))
2929
.foreach(s => {
3030
success.apply("Successfully contacted Delphi server. ")
3131
information.apply("Server version: " + s)

0 commit comments

Comments
 (0)