use of com.networknt.status.Status in project light-rest-4j by networknt.
the class ParameterValidatorsTest method validate_withInvalidStringParam_shouldFail.
@Test
public void validate_withInvalidStringParam_shouldFail() {
Status status = parameterValidators.validate("", stringParam());
Assert.assertNotNull(status);
// request parameter missing
Assert.assertEquals("ERR11001", status.getCode());
}
use of com.networknt.status.Status in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final Object value, final Object schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema));
if (api != null) {
if (this.definitions == null) {
this.definitions = Json.mapper().readTree(Json.pretty(api.getDefinitions()));
}
((ObjectNode) schemaObject).set(DEFINITIONS_FIELD, this.definitions);
}
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject);
final JsonNode content = Json.mapper().valueToTree(value);
processingReport = jsonSchema.validate(content);
} catch (JsonParseException e) {
return new Status(VALIDATOR_SCHEMA_INVALID_JSON, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
use of com.networknt.status.Status in project light-4j by networknt.
the class ZooKeeperRegistry method doRegister.
@Override
protected void doRegister(URL url) {
try {
serverLock.lock();
removeNode(url, ZkNodeType.AVAILABLE_SERVER);
removeNode(url, ZkNodeType.UNAVAILABLE_SERVER);
createNode(url, ZkNodeType.UNAVAILABLE_SERVER);
} catch (Throwable e) {
throw new FrameworkException(new Status(REGISTER_ZOOKEEPER_ERROR, url, getUrl(), e.getMessage()), e);
} finally {
serverLock.unlock();
}
}
use of com.networknt.status.Status in project light-4j by networknt.
the class ZooKeeperRegistry method discoverService.
@Override
protected List<URL> discoverService(URL url) {
try {
String parentPath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
List<String> currentChilds = new ArrayList<String>();
if (client.exists(parentPath)) {
currentChilds = client.getChildren(parentPath);
}
return nodeChildsToUrls(parentPath, currentChilds);
} catch (Throwable e) {
throw new FrameworkException(new Status(DISCOVER_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
}
}
use of com.networknt.status.Status in project light-4j by networknt.
the class ZooKeeperRegistry method subscribeService.
@Override
protected void subscribeService(final URL url, final ServiceListener serviceListener) {
try {
clientLock.lock();
ConcurrentHashMap<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
if (childChangeListeners == null) {
serviceListeners.putIfAbsent(url, new ConcurrentHashMap<ServiceListener, IZkChildListener>());
childChangeListeners = serviceListeners.get(url);
}
IZkChildListener zkChildListener = childChangeListeners.get(serviceListener);
if (zkChildListener == null) {
childChangeListeners.putIfAbsent(serviceListener, new IZkChildListener() {
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) {
serviceListener.notifyService(url, getUrl(), nodeChildsToUrls(parentPath, currentChilds));
if (logger.isInfoEnabled())
logger.info(String.format("[ZooKeeperRegistry] service list change: path=%s, currentChilds=%s", parentPath, currentChilds.toString()));
}
});
zkChildListener = childChangeListeners.get(serviceListener);
}
// prevent old node unregistered
removeNode(url, ZkNodeType.CLIENT);
createNode(url, ZkNodeType.CLIENT);
String serverTypePath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
client.subscribeChildChanges(serverTypePath, zkChildListener);
if (logger.isInfoEnabled())
logger.info(String.format("[ZooKeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.AVAILABLE_SERVER), url.toFullStr()));
} catch (Throwable e) {
throw new FrameworkException(new Status(SUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
} finally {
clientLock.unlock();
}
}
Aggregations