diff --git a/Sda2/P/JaxRs/Intro/pom.xml b/Sda2/P/JaxRs/Intro/pom.xml index dcddbeb4ccf63951552015dfef1da1a1b5791476..128bcffcaf9d62bd4e7cd62b260ddb5ae043c684 100644 --- a/Sda2/P/JaxRs/Intro/pom.xml +++ b/Sda2/P/JaxRs/Intro/pom.xml @@ -1,131 +1,135 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>de.hdm-stuttgart.mi.sda2</groupId> - <artifactId>jaxrs-intro</artifactId> - <version>2.0</version> - <packaging>war</packaging> - <name>jaxrs-intro</name> - <description/> - - <properties> - <resteasy.version>3.0.10.Final</resteasy.version> - </properties> + <modelVersion>4.0.0</modelVersion> + <groupId>de.hdm-stuttgart.mi.sda2</groupId> + <artifactId>jaxrs-intro</artifactId> + <version>2.0</version> + <packaging>war</packaging> + <name>jaxrs-intro</name> + <description /> - <dependencies> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>resteasy-jaxrs</artifactId> - <version>${resteasy.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>resteasy-client</artifactId> - <version>${resteasy.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>async-http-servlet-3.0</artifactId> - <version>${resteasy.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>jaxrs-api</artifactId> - <version>${resteasy.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>resteasy-servlet-initializer</artifactId> - <version>${resteasy.version}</version> - </dependency> - <dependency> - <groupId>org.jboss.resteasy</groupId> - <artifactId>resteasy-jaxb-provider</artifactId> - <version>${resteasy.version}</version> - </dependency> - <!-- - --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.1</version> - <scope>test</scope> - </dependency> - </dependencies> + <properties> + <resteasy.version>3.0.10.Final</resteasy.version> + </properties> - <build> - <finalName>ex03_1</finalName> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.8</source> - <target>1.8</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <skip>true</skip> - </configuration> - <executions> - <execution> - <id>surefire-it</id> - <phase>integration-test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <skip>false</skip> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-maven-plugin</artifactId> - <version>8.1.13.v20130916</version> - <configuration> - <webApp> - <contextPath>/</contextPath> - </webApp> - <scanIntervalSeconds>2</scanIntervalSeconds> - <stopKey>foo</stopKey> - <stopPort>9999</stopPort> - </configuration> - <executions> - <execution> - <id>start-jetty</id> - <phase>pre-integration-test</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <scanIntervalSeconds>0</scanIntervalSeconds> - <daemon>true</daemon> - </configuration> - </execution> - <execution> - <id>stop-jetty</id> - <phase>post-integration-test</phase> - <goals> - <goal>stop</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-deploy-plugin</artifactId> - <configuration> - <skip>true</skip> - </configuration> - </plugin> - </plugins> - </build> + <dependencies> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-jaxrs</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-client</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>async-http-servlet-3.0</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>jaxrs-api</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-servlet-initializer</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.jboss.resteasy</groupId> + <artifactId>resteasy-jaxb-provider</artifactId> + <version>${resteasy.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-http</artifactId> + <version>9.2.7.v20150116</version> + </dependency> + + <!-- --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.1</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <finalName>ex03_1</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + <executions> + <execution> + <id>surefire-it</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>false</skip> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>8.1.13.v20130916</version> + <configuration> + <webApp> + <contextPath>/</contextPath> + </webApp> + <scanIntervalSeconds>2</scanIntervalSeconds> + <stopKey>foo</stopKey> + <stopPort>9999</stopPort> + </configuration> + <executions> + <execution> + <id>start-jetty</id> + <phase>pre-integration-test</phase> + <goals> + <goal>run</goal> + </goals> + <configuration> + <scanIntervalSeconds>0</scanIntervalSeconds> + <daemon>true</daemon> + </configuration> + </execution> + <execution> + <id>stop-jetty</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/Sda2/P/JaxRs/Intro/src/main/java/de/hdm_stuttgart/mi/sda2/MyClient.java b/Sda2/P/JaxRs/Intro/src/main/java/de/hdm_stuttgart/mi/sda2/MyClient.java index 3bc36d0739697ae228c169cff0bef5c1f95f1fd8..c1f269b34d7dcc737cdbe279131f0fc6cd47793a 100644 --- a/Sda2/P/JaxRs/Intro/src/main/java/de/hdm_stuttgart/mi/sda2/MyClient.java +++ b/Sda2/P/JaxRs/Intro/src/main/java/de/hdm_stuttgart/mi/sda2/MyClient.java @@ -6,7 +6,7 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.jboss.resteasy.client.ClientResponse; +import org.eclipse.jetty.http.HttpStatus; import com.restfully.shop.domain.Customer; @@ -29,7 +29,8 @@ public class MyClient { "http://localhost:8080/services/customers") .request().post(Entity.entity(goik, MediaType.APPLICATION_XML_TYPE)); - if (response.getStatus() != 201) { + + if (response.getStatus() != HttpStatus.CREATED_201) { throw new RuntimeException("Failed to create entity"); } @@ -50,8 +51,9 @@ public class MyClient { .request() .put(Entity.entity(goik, MediaType.APPLICATION_XML_TYPE)); - if (response.getStatus() != 204) + if (response.getStatus() != HttpStatus.NO_CONTENT_204){ throw new RuntimeException("Failed to update"); + } response.close(); System.out.println("**** After Update ***"); customer = client.target(location).request().get(String.class); @@ -64,6 +66,5 @@ public class MyClient { } finally { client.close(); } - } }