Skip to content

Commit

Permalink
added all servlets
Browse files Browse the repository at this point in the history
  • Loading branch information
abdo643-HULK committed Dec 22, 2021
1 parent b508150 commit 7e090e9
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 27 deletions.
13 changes: 13 additions & 0 deletions EX2/.config/detekt-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
naming:
LambdaParameterNaming:
parameterPattern: '_[a-z][A-Za-z0-9]*'
ConstructorParameterNaming:
parameterPattern: '_[a-z][A-Za-z0-9]*'
FunctionParameterNaming:
parameterPattern: '_[a-z][A-Za-z0-9]*'
VariableNaming:
privateVariablePattern: 'm[A-Z][A-Za-z0-9]*'

exceptions:
TooGenericExceptionCaught:
exceptionNames: []
6 changes: 3 additions & 3 deletions EX2/.idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions EX2/.idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions EX2/.idea/modules/servlets/EX2.servlets.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion EX2/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="severity" value="error"/>
<property name="tabWidth" value="4"/>

<property name="fileExtensions" value="java, properties, xml, kt"/>
<property name="fileExtensions" value="java, properties, xml"/>

<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
Expand Down
22 changes: 13 additions & 9 deletions EX2/rmi/server/src/main/kotlin/Server.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import java.rmi.server.UnicastRemoteObject

//@Throws(RemoteException::class)
const val SECONDS_DIVISOR = 1000

@Suppress("MagicNumber")
val SENSOR_VALUES_RANGE= (0..200)

class Server : UnicastRemoteObject(), IEnvService, ICookiesService {
private val sensorTypes = mapOf("air" to 3u)
private val mSensorTypes = mapOf("air" to 3u)

override fun requestEnvironmentDataTypes(): Array<String> {
return sensorTypes.keys.toTypedArray()
return mSensorTypes.keys.toTypedArray()
}

override fun requestEnvironmentData(_type: String?): EnvData {
val time = System.currentTimeMillis() / 1000
val values = IntArray(3) { (0..200).random() }
val time = System.currentTimeMillis() / SECONDS_DIVISOR

return sensorTypes[_type]?.let {
return mSensorTypes[_type]?.let {
val values = IntArray(it.toInt()) { SENSOR_VALUES_RANGE.random() }
EnvData(time.toString(), _type, values)
} ?: EnvData(time.toString(), "none", intArrayOf())
}

override fun requestAll(): Array<EnvData> {
val time = System.currentTimeMillis() / 1000
val time = System.currentTimeMillis() / SECONDS_DIVISOR

return sensorTypes.map {
val values = IntArray(it.value.toInt()) { (0..200).random() }
return mSensorTypes.map {
val values = IntArray(it.value.toInt()) { SENSOR_VALUES_RANGE.random() }
EnvData(time.toString(), it.key, values)
}.toTypedArray()
}
Expand Down
9 changes: 4 additions & 5 deletions EX2/rmi/server/src/main/kotlin/ServiceMgmt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import java.rmi.NotBoundException
import java.rmi.RemoteException
import java.rmi.registry.LocateRegistry
import java.rmi.registry.Registry
import java.rmi.server.RemoteObject
import java.rmi.server.UnicastRemoteObject

const val ENV_SERVICE = "EnvService"

class ServiceMgmt {
private val registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT)
private val mRegistry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT)
private val mServer by lazy { Server() }

init {
Expand Down Expand Up @@ -44,7 +43,7 @@ class ServiceMgmt {

private fun startRmi() {
try {
registry.rebind(ENV_SERVICE, mServer)
mRegistry.rebind(ENV_SERVICE, mServer)
println("RMI SERVICE STARTED")
} catch (_e: RemoteException) {
System.err.println("ERROR STARTING SERVER: $_e")
Expand All @@ -53,7 +52,7 @@ class ServiceMgmt {

private fun stopRmi() {
try {
registry.unbind(ENV_SERVICE)
mRegistry.unbind(ENV_SERVICE)
UnicastRemoteObject.unexportObject(mServer, true)
println("RMI SERVICE STOPPED")
} catch (_e: Exception) {
Expand All @@ -68,7 +67,7 @@ class ServiceMgmt {
private fun quit() {
stopRmi()
try {
UnicastRemoteObject.unexportObject(registry, true)
UnicastRemoteObject.unexportObject(mRegistry, true)
} catch (_e: Exception) {
System.err.println("ERROR QUITTING SERVICE MGMT: $_e")
}
Expand Down
8 changes: 3 additions & 5 deletions EX2/servlets/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
plugins {
kotlin("jvm")
java
war
kotlin("jvm")
}

group = "at.fh-ooe.shehata-milo"
version = "0.1"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))

compileOnly("org.apache.tomcat:tomcat-servlet-api:10.0.14")
compileOnly("org.apache.tomcat:tomcat-servlet-api:8.5.73")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
Expand Down
11 changes: 11 additions & 0 deletions EX2/servlets/src/main/kotlin/EnvironmentServiceServlet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import javax.servlet.annotation.WebServlet
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@WebServlet(name = "HelloWorldServlet", urlPatterns = ["/"])
class EnvironmentServiceServlet: HttpServlet() {
override fun doGet(_req: HttpServletRequest, _res: HttpServletResponse) {

}
}
20 changes: 20 additions & 0 deletions EX2/servlets/src/main/kotlin/HelloWorldServlet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import javax.servlet.annotation.WebServlet
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

@WebServlet(name = "HelloWorldServlet", urlPatterns = ["/"])
class HelloWorldServlet : HttpServlet() {
var mCalls = 0

override fun doGet(_req: HttpServletRequest, _res: HttpServletResponse) {
val defaultHtml = "<body><div>hello world</div></body>";
_res.contentType = "text/html"
val htmlFile = servletContext.getResource("/WEB-INF/classes/template.html")
?.readText()
?.replace("%counter%", "${++mCalls}")
?: defaultHtml
_res.writer.println(htmlFile)
_res.writer.close()
}
}
2 changes: 2 additions & 0 deletions EX2/servlets/src/main/kotlin/InfoServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class InfoServlet {
}
3 changes: 0 additions & 3 deletions EX2/servlets/src/main/kotlin/Main.kt

This file was deleted.

2 changes: 2 additions & 0 deletions EX2/servlets/src/main/kotlin/SessionServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class SessionServlet {
}
21 changes: 21 additions & 0 deletions EX2/servlets/src/main/resources/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="description" content="Servlet Request Counter"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<title>Request Counter</title>
<style>
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1 class="badge blue">
%counter%
</h1>
</body>
</html>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# DIS - Distributed Information SystemsThis repo contains all the exercises/assignments my partner, and I had to do for this lecture done my Mr.Krösche Jens.If you want to avoid loosing points because of the style guidelinesthen I would recommend following the coming instructions.Those ## Instruction to set up Clang-tidy for C++1. Open the Settings ![File menu from CLion](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/open-settings.png)2. Copy the "clang-tidy-intellij.xml" from the root of this repo onto your system3. Open the `Setting > Editor > Code Style > C/C++` ![Settings of the code styles in the editor section of the settings.](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/code-style-settings.png)4. Click on the `⚙` Icon and then on `Import Scheme` ![The Checkstyle dialog for the config file](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/import-styles.png)5. Click `OK` after finding the file6. Click `Apply` and then `OK`7. That's it## Instruction to set up Checkstyle for Kotlin/Java1. Open the Settings![File menu from IntelliJ IDEA](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/open-settings.png)2. Go to Plugins and search for "Checkstyle"![Checkstyle plugin in the marketplace](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/checkstyle-download.png)3. Install the Plugin and restart your IDE4. Copy the "checkstyle.xml" from the root this repo onto your system5. Open the `Setting > Tools > Checkstyle`![Setting of Checkstyle in the tools section of the settings.](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/checkstyle-config.png)6. Now below `Configuration File` click on the `+` button7. In the dialog that opens up add a description and import the file![The Checkstyle dialog for the config file](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/import-checkstyle.png)8. Click `Next` and `Next` again and then `Finish`9. Click `Apply` and then `OK`10. That's it
# DIS - Distributed Information SystemsThis repo contains all the exercises/assignments my partner, and I had to do for this lecture done my Mr.Krösche Jens.If you want to avoid loosing points because of the style guidelinesthen I would recommend following the coming instructions.Those ## Instruction to set up Clang-tidy for C++1. Open the Settings ![File menu from CLion](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/open-settings.png)2. Copy the "clang-tidy-intellij.xml" from the root of this repo onto your system3. Open the `Setting > Editor > Code Style > C/C++` ![Settings of the code styles in the editor section of the settings.](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/code-style-settings.png)4. Click on the `⚙` Icon and then on `Import Scheme` ![The Checkstyle dialog for the config file](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/import-styles.png)5. Click `OK` after finding the file6. Click `Apply` and then `OK`7. That's it## Instruction to set up Checkstyle for Java1. Open the Settings![File menu from IntelliJ IDEA](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/open-settings.png)2. Go to Plugins and search for "Checkstyle"![Checkstyle plugin in the marketplace](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/checkstyle-download.png)3. Install the Plugin and restart your IDE4. Copy the "checkstyle.xml" from the root this repo onto your system5. Open the `Setting > Tools > Checkstyle`![Setting of Checkstyle in the tools section of the settings.](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/checkstyle-config.png)6. Now below `Configuration File` click on the `+` button7. In the dialog that opens up add a description and import the file![The Checkstyle dialog for the config file](https://raw.githubusercontent.com/abdo643-HULK/DIS-Exercies/main/images/import-checkstyle.png)8. Click `Next` and `Next` again and then `Finish`9. Click `Apply` and then `OK`10. That's it
Expand Down

0 comments on commit 7e090e9

Please sign in to comment.