use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class ServiceLocatorImpl method lookup.
/**
* {@inheritDoc}
*/
@Override
public synchronized List<String> lookup(QName serviceName, SLPropertiesMatcher matcher) throws ServiceLocatorException, InterruptedException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Looking up endpoints of service " + serviceName + "...");
}
List<String> liveEndpoints;
RootNode rootNode = getBackend().connect();
ServiceNode serviceNode = rootNode.getServiceNode(serviceName);
if (serviceNode.exists()) {
liveEndpoints = new ArrayList<String>();
List<EndpointNode> endpointNodes = serviceNode.getEndPoints();
for (EndpointNode endpointNode : endpointNodes) {
if (endpointNode.isLive()) {
byte[] content = endpointNode.getContent();
SLEndpoint endpoint = transformer.toSLEndpoint(serviceName, content, true);
SLProperties props = endpoint.getProperties();
if (LOG.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder();
for (String prop : props.getPropertyNames()) {
sb.append(prop + " : ");
for (String value : props.getValues(prop)) {
sb.append(value + " ");
}
sb.append("\n");
}
LOG.fine("Lookup of service " + serviceName + " props = " + sb.toString());
LOG.fine("matcher = " + matcher.toString());
}
if (matcher.isMatching(props)) {
liveEndpoints.add(endpointNode.getEndpointName());
if (LOG.isLoggable(Level.FINE))
LOG.fine("matched = " + endpointNode.getEndpointName());
} else if (LOG.isLoggable(Level.FINE))
LOG.fine("not matched = " + endpointNode.getEndpointName());
}
}
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Lookup of service " + serviceName + " failed, service is not known.");
}
liveEndpoints = Collections.emptyList();
}
return liveEndpoints;
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class GetEndpointsTest method getEndpointExistsNot.
@Test
public void getEndpointExistsNot() throws Exception {
expect(backend.connect()).andReturn(rootNode);
expect(rootNode.getServiceNode(SERVICE_QNAME_1)).andReturn(serviceNode);
expect(serviceNode.getEndPoint(ENDPOINT_1)).andReturn(endpointNode);
expect(endpointNode.exists()).andReturn(false);
replayAll();
ServiceLocatorImpl slc = new ServiceLocatorImpl();
slc.setBackend(backend);
SLEndpoint endpoint = slc.getEndpoint(SERVICE_QNAME_1, ENDPOINT_1);
assertNull(endpoint);
verifyAll();
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class LocatorFeatureTest method initializeServer.
@Test
public void initializeServer() throws EndpointException {
LocatorClientEnabler enabler = new LocatorClientEnabler();
enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
ServerLifeCycleManager slcm = new ServerLifeCycleManagerImpl();
expect(busMock.getExtension(ServerLifeCycleManager.class)).andStubReturn(slcm);
replayAll();
Map<String, String> locatorProps = new HashMap<String, String>();
locatorProps.put("key1", "value1");
locatorProps.put("key2", "value2");
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceName(SERVICE_NAME);
factory.setEndpointName(new QName(SERVICE_NS, "HelloWorldImplServiceInstance1"));
factory.setServiceClass(HelloWorld.class);
factory.setAddress("som.address/service");
Server srv = factory.create();
srv.getEndpoint().put(LocatorFeature.LOCATOR_PROPERTIES, locatorProps);
srv.getEndpoint().put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
LocatorRegistrar registrar = new LocatorRegistrar();
ServiceLocator serviceLocator = new ServiceLocatorMock();
registrar.setServiceLocator(serviceLocator);
Bus bus = BusFactory.newInstance().createBus();
EndpointInfo ei = new EndpointInfo();
Service service = new org.apache.cxf.service.ServiceImpl();
EndpointImpl endpoint = new EndpointImpl(busMock, service, ei);
LocatorTargetSelector selector = new LocatorTargetSelector();
selector.setEndpoint(endpoint);
LocatorFeatureImpl lf = new LocatorFeatureImpl();
lf.setLocatorRegistrar(registrar);
lf.setClientEnabler(enabler);
lf.initialize(srv, bus);
SLEndpoint slEp = null;
try {
slEp = serviceLocator.getEndpoint(SERVICE_NAME, "HelloWorldImplServiceInstance1");
} catch (Throwable t) {
t.printStackTrace();
Assert.fail(t.getMessage());
}
Assert.assertNotNull(slEp);
SLProperties slProps = slEp.getProperties();
Assert.assertNotNull(slProps);
Assert.assertTrue(slProps.getPropertyNames().contains("key1"));
Assert.assertTrue(slProps.getPropertyNames().contains("key2"));
}
Aggregations