Search in sources :

Example 11 with SLEndpoint

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

Example 12 with SLEndpoint

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

Example 13 with SLEndpoint

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"));
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) ServerLifeCycleManagerImpl(org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl) HashMap(java.util.HashMap) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) ServiceLocator(org.talend.esb.servicelocator.client.ServiceLocator) SLProperties(org.talend.esb.servicelocator.client.SLProperties) ServiceLocatorMock(org.talend.esb.servicelocator.cxf.internal.internal.ServiceLocatorMock) Test(org.junit.Test)

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