Search in sources :

Example 6 with SLEndpoint

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();
}
Also used : SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Test(org.junit.Test)

Example 7 with SLEndpoint

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();
}
Also used : SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Test(org.junit.Test)

Example 8 with SLEndpoint

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();
}
Also used : SLProperties(org.talend.esb.servicelocator.client.SLProperties) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) EndpointTransformerImpl(org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl) DOMResult(javax.xml.transform.dom.DOMResult) WebApplicationException(javax.ws.rs.WebApplicationException) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Document(org.w3c.dom.Document)

Example 9 with SLEndpoint

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);
}
Also used : QName(javax.xml.namespace.QName) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 10 with SLEndpoint

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);
    }
}
Also used : QName(javax.xml.namespace.QName) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Aggregations

SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)13 QName (javax.xml.namespace.QName)5 Test (org.junit.Test)5 SLProperties (org.talend.esb.servicelocator.client.SLProperties)4 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)4 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 EndpointTransformerImpl (org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl)2 Document (org.w3c.dom.Document)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Bus (org.apache.cxf.Bus)1 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)1 ServerLifeCycleManagerImpl (org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Service (org.apache.cxf.service.Service)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1