Revision 47406
Added by Antonis Lempesis almost 7 years ago
CompatibilityServiceLocatorFactory.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.clients.utils.ws; |
2 | 2 |
|
3 | 3 |
//import deltix.qsrv.comm.xml.ThrowableTransientAnnotationReaderBuilder; |
4 |
|
|
4 | 5 |
import eu.dnetlib.api.DriverService; |
5 |
import eu.dnetlib.api.DriverServiceEndpoint; |
|
6 | 6 |
import eu.dnetlib.api.enabling.A2Service; |
7 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
8 |
import eu.dnetlib.enabling.tools.DynamicServiceLocator; |
|
9 |
import eu.dnetlib.enabling.tools.DynamicServiceLocatorLocationScorer; |
|
7 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
10 | 8 |
import eu.dnetlib.enabling.tools.ServiceResolver; |
11 | 9 |
import eu.dnetlib.enabling.tools.registration.ServiceNameResolver; |
12 | 10 |
import eu.dnetlib.soap.cxf.StandaloneCxfEndpointReferenceBuilder; |
... | ... | |
16 | 14 |
import gr.uoa.di.driver.util.RefreshingServiceLocator; |
17 | 15 |
import gr.uoa.di.driver.util.ServiceLocator; |
18 | 16 |
import gr.uoa.di.driver.util.ServiceLocatorFactory; |
17 |
import org.apache.log4j.Logger; |
|
19 | 18 |
|
20 | 19 |
import java.util.Map; |
21 | 20 |
import java.util.concurrent.Executors; |
22 | 21 |
import java.util.concurrent.ScheduledExecutorService; |
23 | 22 |
|
24 |
import org.apache.log4j.Logger; |
|
25 |
|
|
26 | 23 |
/** |
27 | 24 |
* This is an implementation of ServiceLocatorFactory for web service transport |
28 | 25 |
* layer. This implementation assumes that all service interfaces are part of |
29 | 26 |
* the DriverService hierarchy, but does not require that the web service |
30 | 27 |
* interfaces belong to the DriverWebService hierarchy. |
31 | 28 |
* |
32 |
* This implementation is created for dnet1.1, where there is no common API for
|
|
29 |
* This implementation is created for dnet45, where there is no common API for
|
|
33 | 30 |
* all partners and the only transport layer is SOAP based for all services. |
34 | 31 |
* |
35 | 32 |
* @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a> |
... | ... | |
43 | 40 |
private Map<Class<?>, ServiceClientFactory<?>> clientMap = null; |
44 | 41 |
private CompatibilityEndpointResolver endpointResolver = null; |
45 | 42 |
private StandaloneCxfEndpointReferenceBuilder eprBuilder = null; |
46 |
private eu.dnetlib.enabling.tools.ServiceLocator<ISLookUpService> lookUpLocator = null; |
|
47 |
private DynamicServiceLocatorLocationScorer scorer = null; |
|
48 | 43 |
private ServiceNameResolver serviceNameResolver = null; |
49 | 44 |
private ServiceResolver serviceResolver = null; |
50 | 45 |
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(2); |
51 | 46 |
private long locatorRefreshPeriod = 5*60*1000; // 5 minutes |
52 | 47 |
|
48 |
private UniqueServiceLocator serviceLocator = null; |
|
49 |
|
|
53 | 50 |
public void init() { |
54 | 51 |
logger.debug("Init..."); |
55 | 52 |
} |
... | ... | |
106 | 103 |
private <S extends DriverService> ServiceLocator<S> newDynamicServiceLocator( |
107 | 104 |
Class<S> serviceClass) { |
108 | 105 |
CompatibilityServiceLocator<S> locator = new CompatibilityServiceLocator<S>(); |
109 |
DynamicServiceLocator<DriverServiceEndpoint<S>> serviceLocator = |
|
110 |
new DynamicServiceLocator<DriverServiceEndpoint<S>>(); |
|
111 |
|
|
112 |
serviceLocator.setClazz((Class<DriverServiceEndpoint<S>>) configuration.getEndpointClass(serviceClass)); |
|
113 |
serviceLocator.setEprBuilder(eprBuilder); |
|
114 |
serviceLocator.setLookUpLocator(lookUpLocator); |
|
115 |
serviceLocator.setScorer(scorer); |
|
116 |
serviceLocator.setServiceNameResolver(serviceNameResolver); |
|
117 |
serviceLocator.setServiceResolver(serviceResolver); |
|
118 |
|
|
119 |
|
|
120 | 106 |
ServiceClientFactory<S> clientFactory = (ServiceClientFactory<S>) clientMap.get(serviceClass); |
121 | 107 |
|
122 | 108 |
locator.setClientFactory(clientFactory); |
123 | 109 |
locator.setServiceClass(serviceClass); |
124 |
locator.setServiceLocator(serviceLocator); |
|
110 |
locator.setServiceLocator(this.serviceLocator);
|
|
125 | 111 |
|
126 | 112 |
return locator; |
127 | 113 |
} |
128 | 114 |
|
129 |
/* private ServiceLocator<A2Service> newA2ServiceLocator(String serviceUrl) { |
|
130 |
// get the endpoint |
|
131 |
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); |
|
132 |
factory.setServiceClass(eu.dnetlib.enabling.aas.rmi.A2Service.class); |
|
133 |
factory.setAddress(serviceUrl); |
|
134 |
|
|
135 |
// annotation reader support required to handle A2Error's stacktrace |
|
136 |
JAXBDataBinding dataBinding = new JAXBDataBinding(); |
|
137 |
Map<String, Object> contextProperties = new HashMap<String, Object>(); |
|
138 |
|
|
139 |
try { |
|
140 |
contextProperties.put( |
|
141 |
com.sun.xml.bind.api.JAXBRIContext.ANNOTATION_READER, |
|
142 |
new ThrowableTransientAnnotationReaderBuilder() |
|
143 |
.buildInstance()); |
|
144 |
} catch (Exception e) { |
|
145 |
throw new RuntimeException(e); |
|
146 |
} |
|
147 |
|
|
148 |
dataBinding.setContextProperties(contextProperties); |
|
149 |
factory.setDataBinding(dataBinding); |
|
150 |
|
|
151 |
eu.dnetlib.enabling.aas.rmi.A2Service endpoint = (eu.dnetlib.enabling.aas.rmi.A2Service) factory |
|
152 |
.create(); |
|
153 |
|
|
154 |
// create the client |
|
155 |
AASClient client = new AASClient(); |
|
156 |
|
|
157 |
client.setA2Service(endpoint); |
|
158 |
|
|
159 |
StaticServiceLocator<A2Service> locator = new StaticServiceLocator<A2Service>(client); |
|
160 |
|
|
161 |
return locator; |
|
162 |
} |
|
163 |
*/ |
|
164 | 115 |
public StandaloneCxfEndpointReferenceBuilder getEprBuilder() { |
165 | 116 |
return eprBuilder; |
166 | 117 |
} |
... | ... | |
169 | 120 |
this.eprBuilder = eprBuilder; |
170 | 121 |
} |
171 | 122 |
|
172 |
public eu.dnetlib.enabling.tools.ServiceLocator<ISLookUpService> getLookUpLocator() { |
|
173 |
return lookUpLocator; |
|
174 |
} |
|
175 | 123 |
|
176 |
public void setLookUpLocator( |
|
177 |
eu.dnetlib.enabling.tools.ServiceLocator<ISLookUpService> lookUpLocator) { |
|
178 |
this.lookUpLocator = lookUpLocator; |
|
179 |
} |
|
180 |
|
|
181 |
public DynamicServiceLocatorLocationScorer getScorer() { |
|
182 |
return scorer; |
|
183 |
} |
|
184 |
|
|
185 |
public void setScorer(DynamicServiceLocatorLocationScorer scorer) { |
|
186 |
this.scorer = scorer; |
|
187 |
} |
|
188 |
|
|
189 | 124 |
public ServiceNameResolver getServiceNameResolver() { |
190 | 125 |
return serviceNameResolver; |
191 | 126 |
} |
... | ... | |
225 | 160 |
public void setClientMap(Map<Class<?>, ServiceClientFactory<?>> clientMap) { |
226 | 161 |
this.clientMap = clientMap; |
227 | 162 |
} |
163 |
|
|
164 |
public UniqueServiceLocator getServiceLocator() { |
|
165 |
return serviceLocator; |
|
166 |
} |
|
167 |
|
|
168 |
public void setServiceLocator(UniqueServiceLocator serviceLocator) { |
|
169 |
this.serviceLocator = serviceLocator; |
|
170 |
} |
|
228 | 171 |
} |
Also available in: Unified diff
moved to dnet45