Search in sources :

Example 1 with EndpointNotFoundException

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

the class LocatorRestServiceImpl method updateTimetolive.

@Override
public void updateTimetolive(String arg0, String arg1, int timetolive) {
    String endpointURL = null;
    QName serviceName = null;
    try {
        serviceName = QName.valueOf(URLDecoder.decode(arg0, "UTF-8"));
        endpointURL = URLDecoder.decode(arg1, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Updating expiring time to happen in " + timetolive + " seconds on endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        locatorClient.updateTimetolive(serviceName, endpointURL, timetolive);
    } catch (ServiceLocatorException e) {
        if (e instanceof EndpointNotFoundException) {
            throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(e.getMessage()).build());
        }
        if (e instanceof WrongArgumentException) {
            throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
        }
        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());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EndpointNotFoundException(org.talend.esb.servicelocator.client.EndpointNotFoundException) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WrongArgumentException(org.talend.esb.servicelocator.client.WrongArgumentException)

Example 2 with EndpointNotFoundException

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

the class LocatorSoapServiceTest method updateEndpointExpiringTimeMissingEndpoint.

@Test
public void updateEndpointExpiringTimeMissingEndpoint() throws Exception {
    final int ttl = 95;
    sl.updateTimetolive(SERVICE_NAME, ENDPOINTURL, ttl);
    expectLastCall().andThrow(new EndpointNotFoundException());
    replay(sl);
    try {
        lps.updateTimetolive(SERVICE_NAME, ENDPOINTURL, ttl);
        fail();
    } catch (ServiceLocatorFault e) {
    // pass
    }
    verify(sl);
}
Also used : EndpointNotFoundException(org.talend.esb.servicelocator.client.EndpointNotFoundException) ServiceLocatorFault(org.talend.services.esb.locator.v1.ServiceLocatorFault) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Test(org.junit.Test)

Example 3 with EndpointNotFoundException

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

the class ServiceLocatorImpl method updateTimetolive.

@Override
public void updateTimetolive(QName serviceName, String endpoint, int timetolive) throws ServiceLocatorException, InterruptedException {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Updating expiring time to happen in " + timetolive + " seconds on endpoint " + endpoint + " for service " + serviceName + "...");
    }
    if (timetolive < 0) {
        throw new WrongArgumentException("Time-to-live cannot be negative.");
    }
    if (timetolive == 0) {
        throw new WrongArgumentException("Time-to-live cannot be zero.");
    }
    RootNode rootNode = getBackend().connect();
    ServiceNode serviceNode = rootNode.getServiceNode(serviceName);
    EndpointNode endpointNode = serviceNode.getEndPoint(endpoint);
    if (endpointNode.exists()) {
        endpointNode.setLive(true);
        endpointNode.setExpiryTime(new Date(System.currentTimeMillis() + timetolive * 1000), true);
    } else {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Unable to update endpoint expiring time for endpoint " + endpoint + " for service " + serviceName + " because it does not exist.");
        }
        throw new EndpointNotFoundException("Endpoint " + endpoint + " for service " + serviceName + " does not exist.");
    }
}
Also used : EndpointNotFoundException(org.talend.esb.servicelocator.client.EndpointNotFoundException) WrongArgumentException(org.talend.esb.servicelocator.client.WrongArgumentException) Date(java.util.Date)

Example 4 with EndpointNotFoundException

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

the class LocatorRestServiceTest method updateEndpointExpiringTimeMissingEndpoint.

@Test
public void updateEndpointExpiringTimeMissingEndpoint() throws Exception {
    final int ttl = 95;
    sl.updateTimetolive(SERVICE_NAME, ENDPOINTURL, ttl);
    expectLastCall().andThrow(new EndpointNotFoundException());
    replay(sl);
    try {
        lps.updateTimetolive(SERVICE_NAME.toString(), ENDPOINTURL, ttl);
        fail();
    } catch (WebApplicationException e) {
        assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus());
    // pass
    }
    verify(sl);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EndpointNotFoundException(org.talend.esb.servicelocator.client.EndpointNotFoundException) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Test(org.junit.Test)

Aggregations

EndpointNotFoundException (org.talend.esb.servicelocator.client.EndpointNotFoundException)4 WebApplicationException (javax.ws.rs.WebApplicationException)2 Test (org.junit.Test)2 Endpoint (org.talend.esb.servicelocator.client.Endpoint)2 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)2 WrongArgumentException (org.talend.esb.servicelocator.client.WrongArgumentException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 QName (javax.xml.namespace.QName)1 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)1 ServiceLocatorFault (org.talend.services.esb.locator.v1.ServiceLocatorFault)1