import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
s.getCallbackUrl());
}
- private void validateRegistrationInfo(ServiceRegistrationInfo registrationInfo) throws ServiceException {
+ private void validateRegistrationInfo(ServiceRegistrationInfo registrationInfo)
+ throws ServiceException, MalformedURLException {
if (registrationInfo.serviceName.isEmpty()) {
throw new ServiceException("Missing mandatory parameter 'serviceName'");
}
if (registrationInfo.keepAliveIntervalSeconds < 0) {
throw new ServiceException("Keepalive interval shoul be greater or equal to 0");
}
+ if (!registrationInfo.callbackUrl.isEmpty()) {
+ new URL(registrationInfo.callbackUrl);
+ }
}
@ApiOperation(value = "Register a service")
testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
testErrorCode(restClient().put("/service", createServiceJson("name", -123)), HttpStatus.BAD_REQUEST);
+ testErrorCode(restClient().put("/service", createServiceJson("name", 0, "missing.portandprotocol.com")),
+ HttpStatus.BAD_REQUEST);
// GET non existing servive
testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
}
private String createServiceJson(String name, long keepAliveIntervalSeconds) {
- ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
+ return createServiceJson(name, keepAliveIntervalSeconds, "https://examples.javacodegeeks.com/core-java/");
+ }
+
+ private String createServiceJson(String name, long keepAliveIntervalSeconds, String url) {
+ ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, url);
String json = gson.toJson(service);
return json;