View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Test Continua HRN Route Builder.
29   * 
30   * @author Stefan Ivanov
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  }