Skip to content

Commit

Permalink
fixed the imports
Browse files Browse the repository at this point in the history
  • Loading branch information
abdo643-HULK committed Jan 18, 2022
1 parent ce3e65e commit ec51560
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 65 deletions.
12 changes: 0 additions & 12 deletions EX3/jaxb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))

implementation(project(":lib"))

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
implementation("com.sun.xml.bind:jaxb-core:3.0.2")
// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
implementation("com.sun.xml.bind:jaxb-impl:3.0.2")

// https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
implementation("org.eclipse.persistence:org.eclipse.persistence.moxy:3.0.2")
// https://mvnrepository.com/artifact/org.glassfish/jakarta.json
implementation("org.glassfish:jakarta.json:2.0.1")
}

tasks.getByName<Test>("test") {
Expand Down
1 change: 0 additions & 1 deletion EX3/jaxb/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fun main() {
try {
val props = Properties(10)
props.load(FileInputStream(File("gradle.properties")))
println(Constants.OWM_KEY)

val factory = SAXParserFactory.newInstance()
val saxParser = factory.newSAXParser()
Expand Down
14 changes: 12 additions & 2 deletions EX3/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
api(kotlin("stdlib"))

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
api("com.sun.xml.bind:jaxb-core:3.0.2")
// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
api("com.sun.xml.bind:jaxb-impl:3.0.2")
// https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt
implementation("com.sun.xml.ws:jaxws-rt:3.0.2")
api("com.sun.xml.ws:jaxws-rt:3.0.2")

// https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
api("org.eclipse.persistence:org.eclipse.persistence.moxy:3.0.2")
// https://mvnrepository.com/artifact/org.glassfish/jakarta.json
api("org.glassfish:jakarta.json:2.0.1")
}

tasks.getByName<Test>("test") {
Expand Down
12 changes: 6 additions & 6 deletions EX3/lib/src/main/java/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Properties;

public class Constants {
private static Properties mProperties = new Properties();
private static final Properties mProperties = new Properties();

static {
try {
Expand All @@ -13,11 +13,11 @@ public class Constants {
}
}

public static String USER_LANG = System.getProperty("user.language");
public static final String USER_LANG = System.getProperty("user.language");

public static String ENV_SERVER_URL = "http://localhost:5000/Environment";
public static final String ENV_SERVER_URL = "http://localhost:5000/Environment";

public static String OWM_URL = "http://api.openweathermap.org/data/2.5/weather";
public static String OWM_UNIT = "metric";
public static String OWM_KEY = mProperties.getProperty("OWM_KEY");
public static final String OWM_URL = "http://api.openweathermap.org/data/2.5/weather";
public static final String OWM_UNIT = "metric";
public static final String OWM_KEY = mProperties.getProperty("OWM_KEY");
}
4 changes: 2 additions & 2 deletions EX3/lib/src/main/kotlin/classes/EnvData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ data class EnvData(
val mSensor: String,
@field:XmlElementWrapper(name = "values")
@field:XmlElement(name = "value")
val mValues: FloatArray
val mValues: IntArray
) : Serializable {
companion object {
const val serialVersionUID = 123L
}

constructor() : this("", "", floatArrayOf())
constructor() : this("", "", intArrayOf())
}
7 changes: 7 additions & 0 deletions EX3/lib/src/main/kotlin/interfaces/IEnvironmentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import classes.EnvData
import jakarta.jws.WebMethod
import jakarta.jws.WebParam
import jakarta.jws.WebService
import jakarta.xml.soap.SOAPException
import kotlin.jvm.Throws

@WebService
interface IEnvironmentService {
companion object {
const val ENVIRONMENT_SERVICE_KEY = "EnvironmentService"
}

@WebMethod
fun requestEnvironmentDataTypes(): Array<String>

@Throws(SOAPException::class)
@WebMethod
fun requestData(
@WebParam(name = "city") _city: String
Expand Down
18 changes: 14 additions & 4 deletions EX3/rest/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
plugins {
kotlin("jvm")
java
kotlin("jvm")
}

version = "1.0.0"
group = "com.shehatamilo"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))
// https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api
implementation("javax.ws.rs:javax.ws.rs-api:2.1.1")
implementation(project(":lib"))

// https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api
implementation("jakarta.xml.bind:jakarta.xml.bind-api:3.0.1")

// https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-jaxb
implementation("org.glassfish.jersey.media:jersey-media-jaxb:3.0.3")
// https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet
implementation("org.glassfish.jersey.containers:jersey-container-servlet:3.0.3")

// https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
}

tasks.getByName<Test>("test") {
Expand Down
16 changes: 2 additions & 14 deletions EX3/soap/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
kotlin("jvm")
java
kotlin("jvm")
}

version = "1.0.0"
Expand All @@ -11,19 +11,7 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))

// https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt
implementation("com.sun.xml.ws:jaxws-rt:3.0.2")

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
implementation("com.sun.xml.bind:jaxb-core:3.0.2")
// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
implementation("com.sun.xml.bind:jaxb-impl:3.0.2")
// https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
implementation("org.eclipse.persistence:org.eclipse.persistence.moxy:3.0.2")
// https://mvnrepository.com/artifact/org.glassfish/jakarta.json
implementation("org.glassfish:jakarta.json:2.0.1")
implementation(project(":lib"))
}

tasks.getByName<Test>("test") {
Expand Down
3 changes: 0 additions & 3 deletions EX3/soap/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ plugins {
kotlin("jvm")
}



version = "1.0.0"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))
implementation(project(":lib"))

// https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt
Expand Down
11 changes: 8 additions & 3 deletions EX3/soap/client/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import interfaces.IEnvironmentService
import jakarta.xml.soap.SOAPException
import jakarta.xml.ws.Service
import java.net.URI
import javax.xml.namespace.QName

fun main() {
val url = URI("${Constants.ENV_SERVER_URL}?wsdl")
val name = QName("http://classes/", "EnvironmentService")
val name = QName("http://classes/", IEnvironmentService.ENVIRONMENT_SERVICE_KEY)
val service = Service.create(url.toURL(), name)

val soap: IEnvironmentService = service.getPort(IEnvironmentService::class.java)

println(soap.requestEnvironmentDataTypes().contentToString())

val res = soap.requestData(_city = "Linz")
println(res)
try {
val res = soap.requestData("Wien")
println(res)
} catch (_e: Exception) {
println(_e.localizedMessage)
}
}
15 changes: 1 addition & 14 deletions EX3/soap/server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
java
idea
war
checkstyle
application
kotlin("jvm")
Expand All @@ -14,21 +15,7 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
implementation(project(":lib"))

// https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt
implementation("com.sun.xml.ws:jaxws-rt:3.0.2")

// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core
implementation("com.sun.xml.bind:jaxb-core:3.0.2")
// https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
implementation("com.sun.xml.bind:jaxb-impl:3.0.2")

// https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.moxy
implementation("org.eclipse.persistence:org.eclipse.persistence.moxy:3.0.2")
// https://mvnrepository.com/artifact/org.glassfish/jakarta.json
implementation("org.glassfish:jakarta.json:2.0.1")
}

tasks.getByName<Test>("test") {
Expand Down
18 changes: 14 additions & 4 deletions EX3/soap/server/src/main/kotlin/classes/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Constants
import interfaces.IEnvironmentService
import jakarta.jws.WebService
import jakarta.xml.bind.JAXBContext
import jakarta.xml.soap.SOAPException
import org.eclipse.persistence.jaxb.UnmarshallerProperties
import org.eclipse.persistence.oxm.MediaType
import java.io.BufferedReader
Expand All @@ -19,10 +20,12 @@ const val SECONDS_DIVISOR = 1000
class Environment : IEnvironmentService {

init {
System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory")
System.setProperty("jakarta.xml.bind.JAXBContextFactory", "org.eclipse.persistence.jaxb.JAXBContextFactory")
// System.setProperty("jakarta.xml.bind.JAXBContextFactory", "org.glassfish.jaxb.runtime.v2.JAXBContextFactory")
}

private val mSupportedCities = arrayOf("Wien", "Linz")
private val mSupportedCities = setOf("Wien", "Linz")

private val mJC by lazy { JAXBContext.newInstance(WeatherResponse::class.java) }

Expand Down Expand Up @@ -75,14 +78,21 @@ class Environment : IEnvironmentService {
}

override fun requestEnvironmentDataTypes(): Array<String> {
return mSupportedCities;
return mSupportedCities.toTypedArray();
}

override fun requestData(_city: String): EnvData {
val repsonse = requestJSONData(_city)
if (!mSupportedCities.contains(_city))
throw SOAPException(
"Invalid city provided as input, for more information about the available cities " +
"call the following method: 'requestEnvironmentDataTypes()'"
)

val response = requestJSONData(_city)
val time = (System.currentTimeMillis() / SECONDS_DIVISOR).toString()

return EnvData(time, "humidity", floatArrayOf(repsonse.mMain?.mHumidity ?: 0f))

return EnvData(time, "humidity", intArrayOf(response.mMain?.mHumidity?.toInt() ?: 0))
}
}

Expand Down

0 comments on commit ec51560

Please sign in to comment.