diff --git a/gemeinsamforschen/pom.xml b/gemeinsamforschen/pom.xml index 1fa9a00521ad94d5e557bf69eb9c35cbc5ec409f..118c01043f448c8d8065fa6d17d43e9ff49f987a 100644 --- a/gemeinsamforschen/pom.xml +++ b/gemeinsamforschen/pom.xml @@ -34,6 +34,17 @@ <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>2.11.0</version> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> <dependency> <groupId>mysql</groupId> @@ -113,10 +124,16 @@ <version>3.0.1</version> <scope>provided</scope> </dependency> - - - - + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-servlet</artifactId> + <version>${jersey.version}</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-json-provider</artifactId> + <version>2.9.5</version> + </dependency> </dependencies> </project> \ No newline at end of file diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java new file mode 100644 index 0000000000000000000000000000000000000000..06243fbdd5f169de45d6f13e9b9d41f3a94c1b5c --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/model/SampleAnswer.java @@ -0,0 +1,25 @@ +package unipotsdam.gf.communication.model; + + +public class SampleAnswer { + + private String answer; + + public SampleAnswer() { + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + @Override + public String toString() { + return "SampleAnswer{" + + "answer='" + answer + '\'' + + '}'; + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java new file mode 100644 index 0000000000000000000000000000000000000000..ee150d867ae69c2b06e9aed1614b5b12919fabc0 --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/service/SampleService.java @@ -0,0 +1,12 @@ +package unipotsdam.gf.communication.service; + +import unipotsdam.gf.communication.model.SampleAnswer; + +public class SampleService { + + public SampleAnswer provideSampleAnswer(String name) { + SampleAnswer sampleAnswer = new SampleAnswer(); + sampleAnswer.setAnswer("Hello " + name); + return sampleAnswer; + } +} diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java new file mode 100644 index 0000000000000000000000000000000000000000..6c89444315f388a03029b0d08c2e27bc3c6b44fc --- /dev/null +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/communication/view/SampleView.java @@ -0,0 +1,28 @@ +package unipotsdam.gf.communication.view; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import unipotsdam.gf.communication.model.SampleAnswer; +import unipotsdam.gf.communication.service.SampleService; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/example") +public class SampleView { + + Logger log = LoggerFactory.getLogger(SampleView.class); + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{name}") + public SampleAnswer helloWorld(@PathParam("name") String name) { + SampleService sampleService = new SampleService(); + SampleAnswer sampleAnswer = sampleService.provideSampleAnswer(name); + log.info("HelloWorldview helloWorld Method answered: {}",sampleAnswer); + return sampleAnswer; + } +} diff --git a/gemeinsamforschen/src/main/resources/log4j2.xml b/gemeinsamforschen/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..fccc9f408e851d4bf039588024aba0cea9771354 --- /dev/null +++ b/gemeinsamforschen/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="WARN"> + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%level] %logger{35} - %msg%n"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="Console"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d19745c81aebbb1b411c530cffcca45359e5a71d --- /dev/null +++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/communication/service/SampleServiceTest.java @@ -0,0 +1,19 @@ +package unipotsdam.gf.communication.service; + + +import org.junit.Test; +import unipotsdam.gf.communication.model.SampleAnswer; + +import static org.junit.Assert.assertEquals; + + +public class SampleServiceTest { + + @Test + public void returnCorrectMessage() { + SampleService sampleService = new SampleService(); + SampleAnswer sampleAnswer = sampleService.provideSampleAnswer("test"); + + assertEquals(sampleAnswer.getAnswer(), "Hello test"); + } +}