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());
}
}
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);
}
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.");
}
}
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);
}
Aggregations