Search in sources :

Example 1 with Endpoint

use of org.talend.esb.servicelocator.client.Endpoint in project tesb-rt-se by Talend.

the class LocatorRestServiceImpl method lookupEndpoints.

/**
 * For the given service return endpoint reference randomly selected from
 * list of endpoints currently registered at the service locator server.
 *
 * @param input
 *            String encoded name of service
 * @param input
 *            List of encoded additional parameters separated by comma
 *
 * @return EndpointReferenceListType encapsulate list of endpoint references
 *         or <code>null</code>
 */
public EndpointReferenceList lookupEndpoints(String arg0, List<String> arg1) {
    QName serviceName = null;
    try {
        serviceName = QName.valueOf(URLDecoder.decode(arg0, "UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
    }
    List<String> names = null;
    String adress = null;
    SLPropertiesMatcher matcher = null;
    try {
        matcher = createMatcher(arg1);
    } catch (UnsupportedEncodingException e1) {
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
    }
    EndpointReferenceList refs = new EndpointReferenceList();
    try {
        initLocator();
        if (matcher == null) {
            names = locatorClient.lookup(serviceName);
        } else {
            names = locatorClient.lookup(serviceName, matcher);
        }
    } 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 (names != null && !names.isEmpty()) {
        for (int i = 0; i < names.size(); i++) {
            adress = names.get(i);
            refs.getEndpointReference().add(buildEndpoint(serviceName, adress));
        }
    } else {
        if (LOG.isLoggable(Level.WARNING)) {
            LOG.log(Level.WARNING, "lookup Endpoints for " + serviceName + " failed, service is not known.");
        }
        throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity("Service not found").build());
    }
    return refs;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) EndpointReferenceList(org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 2 with Endpoint

use of org.talend.esb.servicelocator.client.Endpoint in project tesb-rt-se by Talend.

the class LocatorRestServiceImpl method registerEndpoint.

/**
 * Register the endpoint for given service.
 *
 * @param input
 *            RegisterEndpointRequestType encapsulate name of service and
 *            endpointURL. Must not be <code>null</code>
 */
public void registerEndpoint(RegisterEndpointRequest arg0) {
    String endpointURL = arg0.getEndpointURL();
    QName serviceName = QName.valueOf(arg0.getServiceName());
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Registering endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        BindingType bindingType = arg0.getBinding() == null ? BindingType.OTHER : BindingType.valueOf(arg0.getBinding().value());
        TransportType transportType = arg0.getTransport() == null ? TransportType.OTHER : TransportType.valueOf(arg0.getTransport().value());
        SLPropertiesImpl slProps = null;
        if (!arg0.getEntryType().isEmpty()) {
            slProps = new SLPropertiesImpl();
            List<EntryType> entries = arg0.getEntryType();
            for (EntryType entry : entries) {
                slProps.addProperty(entry.getKey(), entry.getValue());
            }
        }
        Endpoint simpleEndpoint = new SimpleEndpoint(serviceName, endpointURL, bindingType, transportType, slProps);
        locatorClient.register(simpleEndpoint, true);
    } catch (ServiceLocatorException e) {
        // throw new ServiceLocatorFault(e.getMessage(), e);
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
    } catch (InterruptedException e) {
        // throw new InterruptedExceptionFault(e.getMessage(), e);
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
    }
}
Also used : EntryType(org.talend.schemas.esb.locator.rest._2011._11.EntryType) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) BindingType(org.talend.esb.servicelocator.client.BindingType) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLPropertiesImpl(org.talend.esb.servicelocator.client.SLPropertiesImpl) TransportType(org.talend.esb.servicelocator.client.TransportType)

Example 3 with Endpoint

use of org.talend.esb.servicelocator.client.Endpoint in project tesb-rt-se by Talend.

the class RegisterEndpointProviderTest method registerServiceExistsNot.

@Ignore
@Test
public void registerServiceExistsNot() throws Exception {
    Endpoint endpoint = create(SERVICE_QNAME_1, ENDPOINT_1);
    serviceExistsNot(SERVICE_PATH_1);
    createService(SERVICE_PATH_1);
    endpointExistsNot(ENDPOINT_PATH_11);
    ep2Data(endpoint, NEW_DATA);
    createEndpointAndSetData(ENDPOINT_PATH_11, NEW_DATA);
    createEndpointStatus(ENDPOINT_PATH_11);
    replayAll();
    ServiceLocatorImpl slc = createServiceLocatorSuccess();
    slc.setEndpointTransformer(trans);
    slc.register(endpoint);
    verifyAll();
}
Also used : Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Endpoint

use of org.talend.esb.servicelocator.client.Endpoint in project tesb-rt-se by Talend.

the class RegisterEndpointProviderTest method registerServiceExistsEndpointExistsCheckLastTimes.

@Ignore
@Test
public void registerServiceExistsEndpointExistsCheckLastTimes() throws Exception {
    Endpoint endpoint = create(SERVICE_QNAME_1, ENDPOINT_1);
    Capture<Long> lastTimeStartedCapture = new Capture<Long>();
    serviceExists(SERVICE_PATH_1);
    endpointExists(ENDPOINT_PATH_11);
    getData(ENDPOINT_PATH_11, OLD_DATA);
    data2Ep(SERVICE_QNAME_1, OLD_DATA);
    ep2Data(endpoint, lastTimeStartedCapture, LAST_TIME_STOPPED, NEW_DATA);
    setData(ENDPOINT_PATH_11, NEW_DATA);
    createEndpointStatus(ENDPOINT_PATH_11);
    replayAll();
    ServiceLocatorImpl slc = createServiceLocatorSuccess();
    slc.setEndpointTransformer(trans);
    long beforeRegister = System.currentTimeMillis();
    slc.register(endpoint);
    long afterRegister = System.currentTimeMillis();
    verifyAll();
    long lastTimeStarted = lastTimeStartedCapture.getValue();
    assertTrue(beforeRegister <= lastTimeStarted && lastTimeStarted <= afterRegister);
}
Also used : Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) EasyMock.anyLong(org.easymock.EasyMock.anyLong) Capture(org.easymock.Capture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with Endpoint

use of org.talend.esb.servicelocator.client.Endpoint in project tesb-rt-se by Talend.

the class RegisterEndpointProviderTest method registerEndpointPersistently.

@Ignore
@Test
public void registerEndpointPersistently() throws Exception {
    Endpoint endpoint = create(SERVICE_QNAME_1, ENDPOINT_1);
    serviceExists(SERVICE_PATH_1);
    endpointExistsNot(ENDPOINT_PATH_11);
    ep2Data(endpoint, NEW_DATA);
    createEndpointAndSetData(ENDPOINT_PATH_11, NEW_DATA);
    createEndpointStatus(ENDPOINT_PATH_11, true);
    replayAll();
    ServiceLocatorImpl slc = createServiceLocatorSuccess();
    slc.setEndpointTransformer(trans);
    slc.register(endpoint, true);
    verifyAll();
}
Also used : Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Endpoint (org.talend.esb.servicelocator.client.Endpoint)14 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)12 Test (org.junit.Test)11 Ignore (org.junit.Ignore)10 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 QName (javax.xml.namespace.QName)2 Capture (org.easymock.Capture)2 EasyMock.anyLong (org.easymock.EasyMock.anyLong)2 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 KeeperException (org.apache.zookeeper.KeeperException)1 BindingType (org.talend.esb.servicelocator.client.BindingType)1 SLPropertiesImpl (org.talend.esb.servicelocator.client.SLPropertiesImpl)1 SLPropertiesMatcher (org.talend.esb.servicelocator.client.SLPropertiesMatcher)1 TransportType (org.talend.esb.servicelocator.client.TransportType)1 EndpointReferenceList (org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList)1 EntryType (org.talend.schemas.esb.locator.rest._2011._11.EntryType)1 Document (org.w3c.dom.Document)1