View Javadoc
1   /*
2    * Copyright 2015 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.xds.dispatch;
17  
18  import org.apache.camel.Exchange;
19  import org.apache.camel.Expression;
20  import org.apache.camel.builder.RouteBuilder;
21  import org.apache.camel.component.cxf.common.message.CxfConstants;
22  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
23  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.query.AdhocQueryResponse;
24  import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rs.RegistryResponseType;
25  import org.openehealth.ipf.platform.camel.ihe.xds.XdsCamelValidators;
26  
27  import javax.xml.namespace.QName;
28  import javax.xml.soap.SOAPFactory;
29  import javax.xml.ws.soap.SOAPFaultException;
30  
31  /**
32   * @author Dmytro Rud
33   */
34  public class DispatchRouteBuilder extends RouteBuilder {
35      @Override
36      public void configure() throws Exception {
37          from("cxf:bean:xdsRegistryEndpoint")
38              .choice()
39                  .when(header(CxfConstants.OPERATION_NAME).isEqualTo("DocumentRegistry_RegistryStoredQuery"))
40                      .to("direct:handle-iti18")
41                  .when(header(CxfConstants.OPERATION_NAME).isEqualTo("DocumentRegistry_RegisterDocumentSet-b"))
42                      .to("direct:handle-iti42")
43                  .otherwise()
44                      .to("direct:unsupportedOperation");
45  
46          from("direct:handle-iti18")
47                  .process(XdsCamelValidators.iti18RequestValidator())
48                  .transform(new Expression() {
49                      @Override
50                      public <T> T evaluate(Exchange exchange, Class<T> type) {
51                          return (T) SampleData.createQueryResponseWithObjRef();
52                      }
53                  })
54                  .convertBodyTo(AdhocQueryResponse.class)
55                  .process(XdsCamelValidators.iti18ResponseValidator());
56  
57          from("direct:handle-iti42")
58                  .process(XdsCamelValidators.iti42RequestValidator())
59                  .transform(new Expression() {
60                      @Override
61                      public <T> T evaluate(Exchange exchange, Class<T> type) {
62                          return (T) SampleData.createResponse();
63                      }
64                  })
65                  .convertBodyTo(RegistryResponseType.class)
66                  .process(XdsCamelValidators.iti42ResponseValidator());
67  
68          from("direct:unsupportedOperation")
69                  .throwException(new SOAPFaultException(SOAPFactory.newInstance().createFault(
70                          "Unknown WSDL operation",
71                          new QName("http://www.openehealth.org/ipf", "UNK"))));
72  
73      }
74  }