1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.continua.hrn;
17
18 import org.apache.camel.Processor;
19 import org.apache.camel.builder.RouteBuilder;
20 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Document;
21 import org.openehealth.ipf.commons.ihe.xds.core.requests.ProvideAndRegisterDocumentSet;
22 import org.openehealth.ipf.commons.ihe.xds.core.responses.Response;
23 import org.openehealth.ipf.commons.ihe.xds.core.responses.Status;
24
25 import javax.activation.DataHandler;
26
27
28
29
30
31
32 public class ContinuaHrnRouteBuilder extends RouteBuilder {
33
34 private static final Processor CHECK_PROCESSOR = exchange -> {
35 Object body = exchange.getIn().getBody();
36 if (! (body instanceof ProvideAndRegisterDocumentSet)) {
37 throw new Exception("wrong body type");
38 }
39
40 Class<?>[] expectedContentTypes = new Class<?>[] {
41 DataHandler.class,
42 byte[].class,
43 String.class
44 };
45 Document document = exchange.getIn().getBody(ProvideAndRegisterDocumentSet.class).getDocuments().get(0);
46 for (Class<?> contentType : expectedContentTypes) {
47 if (! document.hasContent(contentType)) {
48 throw new Exception("Missing content type: " + contentType);
49 }
50 }
51
52 if (document.getContentsCount() != expectedContentTypes.length) {
53 throw new Exception("Expected " + expectedContentTypes.length +
54 " content types, found " + document.getContentsCount());
55 }
56 };
57
58
59 @Override
60 public void configure() throws Exception {
61
62 from("xds-iti41:continuaHRNService")
63 .onException(Exception.class)
64 .maximumRedeliveries(0)
65 .end()
66 .process(ContinuaHrnCamelProcessors.continuaHrnRequestTransformerAndValidator())
67 .process(CHECK_PROCESSOR)
68 .setBody(constant(new Response(Status.SUCCESS)))
69 .process(ContinuaHrnCamelProcessors.continuaHrnResponseValidator());
70 }
71
72 }