aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-30 13:44:44 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-30 13:44:44 +0200
commit2b6e1ed4f45645797b2874a7cb3be6070265be43 (patch)
treefb4b287147c5e9ff452b8f02b41bbd3870617ecc
parent4592b1fac0ebef1d0ee2ff650ea0c46514539dfc (diff)
downloadmoa-zs-2b6e1ed4f45645797b2874a7cb3be6070265be43.tar.gz
moa-zs-2b6e1ed4f45645797b2874a7cb3be6070265be43.tar.bz2
moa-zs-2b6e1ed4f45645797b2874a7cb3be6070265be43.zip
Generate SoapFault instead of DRStatus/Error Message
- App2MZS Server: Instead of generating a DeliveryRequestStatus/Error Message, we throw an exception. This will generate a SoapFault (including a 500 http status code), which is more appropriate. - Fix possible NPE of deliveryRequest.getMetadata().getAppDeliveryID() by moving appDeliveryID initialization into the TimeOutException catch block - pom.xml: Remove hamcrest dependency, as not needed for now.
-rw-r--r--pom.xml8
-rw-r--r--src/main/java/at/gv/egiz/moazs/App2MzsService.java29
-rw-r--r--src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java6
3 files changed, 8 insertions, 35 deletions
diff --git a/pom.xml b/pom.xml
index a2ba3a5..4a8a1cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,6 @@
<jedisclient.version>2.9.3</jedisclient.version>
<guava.version>27.1-jre</guava.version>
<immutable-xjc-plugin.version>1.5</immutable-xjc-plugin.version>
- <hamcrest.version>1.3</hamcrest.version>
</properties>
<dependencies>
@@ -83,13 +82,6 @@
<artifactId>javax.jws-api</artifactId>
<version>${jwsapi.version}</version>
</dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <version>${hamcrest.version}</version>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
diff --git a/src/main/java/at/gv/egiz/moazs/App2MzsService.java b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
index 03d99fe..c89083f 100644
--- a/src/main/java/at/gv/egiz/moazs/App2MzsService.java
+++ b/src/main/java/at/gv/egiz/moazs/App2MzsService.java
@@ -9,12 +9,14 @@ import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs.App2MzsPort
import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType;
import at.gv.egiz.moazs.pipeline.DeliveryPipeline;
import at.gv.egiz.moazs.repository.DeliveryRepository;
+import org.apache.cxf.binding.soap.SoapFault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.jws.WebParam;
+import javax.xml.XMLConstants;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -50,22 +52,22 @@ public class App2MzsService implements App2MzsPortType {
targetNamespace = MZSTNS)
DeliveryRequestType deliveryRequest) {
- final var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
-
var future = supplyAsync(() -> preprocessor.preProcess(deliveryRequest))
- .thenApply((request) -> process(request));
+ .thenApply(this::process);
try {
return future.get(TIMEOUT_FOR_ANWSER, TimeUnit.SECONDS);
} catch (TimeoutException e) {
future.thenAccept(appClient::sendNotification);
logger.info("Answer Timed Out", e);
+
+ var appDeliveryID = deliveryRequest.getMetaData().getAppDeliveryID();
return generatePartialSuccessResponse(appDeliveryID);
} catch (Exception e ) {
logger.error("Could not deliver request.", e);
- var message = format("An error occured while delivering request: {0}", e.getMessage());
- return generateErrorResponse(appDeliveryID, message);
+ var message = format("An error occurred while processing DeliveryRequest");
+ throw new RuntimeException(message, e);
}
}
@@ -94,21 +96,4 @@ public class App2MzsService implements App2MzsPortType {
.build();
}
- private DeliveryRequestStatusType generateErrorResponse(String appDeliveryId, String message) {
-
- var info = new ErrorInfoTypeBuilder()
- .withCode("500")
- .withText(message)
- .build();
-
- var error = new ErrorBuilder()
- .withAppDeliveryID(appDeliveryId)
- .withErrorInfo(info)
- .build();
-
- return new DeliveryRequestStatusTypeBuilder()
- .withError(error)
- .build();
- }
-
} \ No newline at end of file
diff --git a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
index 03992ae..bdf00d5 100644
--- a/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
+++ b/src/test/java/at/gv/egiz/moazs/App2MzsServiceTest.java
@@ -25,11 +25,8 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Paths;
-import java.util.Arrays;
import static java.net.http.HttpClient.Version;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class)
@@ -82,8 +79,7 @@ public class App2MzsServiceTest {
@Test
public void rejectRequestWithoutAppDeliveryID() throws IOException, InterruptedException {
var response = sendDeliveryRequestFile("missingAppDeliveryId.soap");
- assertEquals(200, response.statusCode());
- assertThat(response.body(), stringContainsInOrder(Arrays.asList("Code>", "500", "/", "Code>")));
+ assertEquals(500, response.statusCode());
}
@Test