praktikum1/aufgabe1

This commit is contained in:
2026-04-17 10:23:25 +02:00
parent 32f7cd07d9
commit b6de6840d3
9 changed files with 62 additions and 5 deletions

View File

@@ -3,6 +3,6 @@
# deploy the server # deploy the server
# #
# usage: # usage:
# deploy server/target/ejb-uebung-1.0-SNAPSHOT.jar # deploy server/target/ejb-server-1.0-SNAPSHOT.jar
cp -v "$1" "$WILDFLY_BASE_DIR/deployments/" cp -v "$1" "$WILDFLY_BASE_DIR/deployments/"

View File

@@ -13,7 +13,7 @@
<!-- Abhängigkeit zu den EJB-Interfaces des Server-Moduls --> <!-- Abhängigkeit zu den EJB-Interfaces des Server-Moduls -->
<dependency> <dependency>
<groupId>de.componentware</groupId> <groupId>de.componentware</groupId>
<artifactId>ejb-uebung</artifactId> <artifactId>ejb-server</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- BOM für alle WildFly EJB-Client Abhängigkeiten --> <!-- BOM für alle WildFly EJB-Client Abhängigkeiten -->

View File

@@ -0,0 +1,22 @@
package org.example.demo.praktikum1.aufgabe1;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Properties;
public class Client {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.wildfly.naming.client.WildFlyInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080");
InitialContext ctx = new InitialContext(props);
String jndiName = "ejb:/ejb-server-1.0-SNAPSHOT/Calculator!org.example.demo.praktikum1.aufgabe1.CalculatorRemote";
var calc = (CalculatorRemote) ctx.lookup(jndiName);
System.out.println("6 + 7 = " + calc.addiere(6, 7));
System.out.println("6 - 7 = " + calc.subtrahiere(6, 7));
System.out.println("6 * 7 = " + calc.multipliziere(6, 7));
System.out.println("6 / 7 = " + calc.dividiere(6, 7));
}
}

View File

@@ -11,7 +11,7 @@ public class Client {
props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080"); props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080");
InitialContext ctx = new InitialContext(props); InitialContext ctx = new InitialContext(props);
String jndiName = "ejb:/ejb-uebung-1.0-SNAPSHOT/Encryptor!org.example.demo.uebung1.aufgabe16.EncryptorRemote"; String jndiName = "ejb:/ejb-server-1.0-SNAPSHOT/Encryptor!org.example.demo.uebung1.aufgabe16.EncryptorRemote";
EncryptorRemote encryptor = (EncryptorRemote) ctx.lookup(jndiName); EncryptorRemote encryptor = (EncryptorRemote) ctx.lookup(jndiName);
String original = "Hallo Welt"; String original = "Hallo Welt";

View File

@@ -11,7 +11,7 @@ public class Client {
props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080"); props.setProperty(Context.PROVIDER_URL, "http-remoting://localhost:8080");
InitialContext ctx = new InitialContext(props); InitialContext ctx = new InitialContext(props);
String jndiName = "ejb:/ejb-uebung-1.0-SNAPSHOT/Counter!org.example.demo.uebung1.aufgabe17.CounterRemote?stateful"; String jndiName = "ejb:/ejb-server-1.0-SNAPSHOT/Counter!org.example.demo.uebung1.aufgabe17.CounterRemote?stateful";
CounterRemote counter = (CounterRemote) ctx.lookup(jndiName); CounterRemote counter = (CounterRemote) ctx.lookup(jndiName);
System.out.println(counter.getAndIncrement()); System.out.println(counter.getAndIncrement());

6
package-lock.json generated Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "itc.componentware",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}

View File

@@ -7,7 +7,7 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>ejb-uebung</artifactId> <artifactId>ejb-server</artifactId>
<packaging>ejb</packaging> <packaging>ejb</packaging>
<dependencies> <dependencies>
<!-- Jakarta EE 10 API (wird von WildFly bereitgestellt) --> <!-- Jakarta EE 10 API (wird von WildFly bereitgestellt) -->

View File

@@ -0,0 +1,19 @@
package org.example.demo.praktikum1.aufgabe1;
import jakarta.ejb.Stateless;
@Stateless
public class Calculator implements CalculatorRemote {
public double addiere(float zahl1, float zahl2) {
return zahl1 + zahl2;
}
public double subtrahiere(float zahl1, float zahl2) {
return zahl1 - zahl2;
}
public double multipliziere(float zahl1, float zahl2) {
return zahl1 * zahl2;
}
public double dividiere(float zahl1, float zahl2) {
// todo: division by 0 exception?
return zahl1 / zahl2;
}
}

View File

@@ -0,0 +1,10 @@
package org.example.demo.praktikum1.aufgabe1;
import jakarta.ejb.Remote;
@Remote
public interface CalculatorRemote {
double addiere(float zahl1, float zahl2);
double subtrahiere(float zahl1, float zahl2);
double multipliziere(float zahl1, float zahl2);
double dividiere(float zahl1, float zahl2);
}