1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.platform.camel.ihe.ws;
17
18 import org.apache.cxf.endpoint.ClientImpl;
19 import org.apache.cxf.frontend.ClientProxy;
20 import org.openehealth.ipf.commons.ihe.ws.JaxWsClientFactory;
21 import org.openehealth.ipf.commons.ihe.ws.WsTransactionConfiguration;
22 import org.openehealth.ipf.commons.ihe.ws.cxf.audit.WsAuditDataset;
23
24 import javax.jws.WebMethod;
25 import java.lang.reflect.Method;
26
27
28
29
30
31 public class SimpleWsProducer<
32 AuditDatasetType extends WsAuditDataset,
33 ConfigType extends WsTransactionConfiguration<AuditDatasetType>,
34 InType, OutType> extends AbstractWsProducer<AuditDatasetType, ConfigType, InType, OutType> {
35 private final String operationName;
36
37
38
39
40
41
42
43
44
45
46
47
48 public SimpleWsProducer(
49 AbstractWsEndpoint<AuditDatasetType, ConfigType> endpoint,
50 JaxWsClientFactory<AuditDatasetType> clientFactory,
51 Class<InType> requestClass,
52 Class<OutType> responseClass)
53 {
54 super(endpoint, clientFactory, requestClass, responseClass);
55
56 for (Method method : endpoint.getComponent().getWsTransactionConfiguration().getSei().getDeclaredMethods()) {
57 WebMethod annotation = method.getAnnotation(WebMethod.class);
58 if (annotation != null) {
59 this.operationName = annotation.operationName();
60 return;
61 }
62 }
63 throw new IllegalStateException("the SEI does not contain any methods annotated with @WebMethod");
64 }
65
66
67 @SuppressWarnings("unchecked")
68 @Override
69 protected OutType callService(Object clientObject, InType request) throws Exception {
70 ClientImpl client = (ClientImpl) ClientProxy.getClient(clientObject);
71 Object[] result = client.invoke(operationName, request);
72 return (result != null) ? (OutType) result[0] : null;
73 }
74 }