use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class GetEndpointsTest method getEndpoint.
@Test
public void getEndpoint() 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(true);
expect(endpointNode.isLive()).andReturn(false);
expect(endpointNode.getContent()).andReturn(CONTENT_ENDPOINT_1);
replayAll();
ServiceLocatorImpl slc = new ServiceLocatorImpl();
slc.setBackend(backend);
SLEndpoint endpoint = slc.getEndpoint(SERVICE_QNAME_1, ENDPOINT_1);
assertFalse(endpoint.isLive());
assertEquals(SERVICE_QNAME_1, endpoint.forService());
assertEquals(LAST_TIME_STARTED, endpoint.getLastTimeStarted());
verifyAll();
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class GetEndpointsTest method getEndpointsEndpointIsLive.
@Test
public void getEndpointsEndpointIsLive() throws Exception {
expect(backend.connect()).andReturn(rootNode);
expect(rootNode.getServiceNode(SERVICE_QNAME_1)).andReturn(serviceNode);
expect(serviceNode.exists()).andReturn(true);
expect(serviceNode.getEndPoints()).andReturn(Arrays.asList(endpointNode));
expect(endpointNode.isLive()).andReturn(true);
expect(endpointNode.getContent()).andReturn(CONTENT_ENDPOINT_1);
replayAll();
ServiceLocatorImpl slc = new ServiceLocatorImpl();
slc.setBackend(backend);
List<SLEndpoint> endpoints = slc.getEndpoints(SERVICE_QNAME_1);
SLEndpoint endpoint = endpoints.get(0);
assertTrue(endpoint.isLive());
verifyAll();
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class LocatorRestServiceImpl method buildEndpoint.
/**
* Build Endpoint Reference for giving service name and address
*
* @param serviceName
* @param adress
* @return
*/
private W3CEndpointReference buildEndpoint(QName serviceName, String adress) {
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
// builder.serviceName(serviceName);
builder.address(adress);
SLEndpoint endpoint = null;
try {
endpoint = locatorClient.getEndpoint(serviceName, adress);
} catch (ServiceLocatorException e) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
} catch (InterruptedException e) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
}
if (endpoint != null) {
SLProperties properties = endpoint.getProperties();
if (properties != null && !properties.getPropertyNames().isEmpty()) {
EndpointTransformerImpl transformer = new EndpointTransformerImpl();
DOMResult result = new DOMResult();
transformer.writePropertiesTo(properties, result);
Document docResult = (Document) result.getNode();
builder.metadata(docResult.getDocumentElement());
}
}
return builder.build();
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class ServiceLocatorImpl method register.
@Override
public synchronized void register(Endpoint epProvider, boolean persistent) throws ServiceLocatorException, InterruptedException {
QName serviceName = epProvider.getServiceName();
String endpoint = epProvider.getAddress();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Registering endpoint " + endpoint + " for service " + serviceName + "...");
}
long lastTimeStarted = System.currentTimeMillis();
long lastTimeStopped = -1;
RootNode rootNode = getBackend().connect();
ServiceNode serviceNode = rootNode.getServiceNode(serviceName);
serviceNode.ensureExists();
EndpointNode endpointNode = serviceNode.getEndPoint(endpoint);
if (endpointNode.exists()) {
byte[] content = endpointNode.getContent();
SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, content, false);
lastTimeStopped = oldEndpoint.getLastTimeStopped();
}
byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped);
endpointNode.ensureExists(content);
endpointNode.setLive(persistent);
}
use of org.talend.esb.servicelocator.client.SLEndpoint in project tesb-rt-se by Talend.
the class ServiceLocatorImpl method unregister.
@Override
public synchronized void unregister(Endpoint epProvider) throws ServiceLocatorException, InterruptedException {
QName serviceName = epProvider.getServiceName();
String endpoint = epProvider.getAddress();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Unregistering endpoint " + endpoint + " for service " + serviceName + "...");
}
long lastTimeStarted = -1;
long lastTimeStopped = System.currentTimeMillis();
RootNode rootNode = getBackend().connect();
ServiceNode serviceNode = rootNode.getServiceNode(serviceName);
EndpointNode endpointNode = serviceNode.getEndPoint(endpoint);
if (endpointNode.exists()) {
byte[] oldContent = endpointNode.getContent();
SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, oldContent, false);
lastTimeStarted = oldEndpoint.getLastTimeStarted();
endpointNode.setOffline();
byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped);
endpointNode.setContent(content);
}
}
Aggregations