use of com.predic8.schema.Schema in project service-proxy by membrane.
the class NamespaceInfo method writeInfo.
public void writeInfo(Model m) {
try {
FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/membrane.namespaces");
OutputStream oo = o.openOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(oo);
try {
Properties p = new Properties();
int i = 1;
for (MainInfo mi : m.getMains()) {
String key = "schema" + (i++);
p.put(key + "-targetNamespace", mi.getAnnotation().targetNamespace());
p.put(key + "-outputPackage", mi.getAnnotation().outputPackage());
p.put(key + "-outputName", mi.getAnnotation().outputName());
}
p.store(bos, "Autogenerated by " + getClass().getName());
} finally {
bos.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.predic8.schema.Schema in project service-proxy by membrane.
the class ApiManagementConfiguration method updateAfterLocationChange.
public void updateAfterLocationChange() throws IOException {
if (!isLocalFile(location)) {
log.info("Loading configuration from [" + location + "]");
if (location.startsWith("etcd")) {
handleEtcd(location);
} else {
try {
parseAndConstructConfiguration(getResolver().resolve(location));
} catch (ResourceRetrievalException e) {
log.error("Could not retrieve resource");
return;
}
}
return;
} else {
if (location.isEmpty())
location = "api.yaml";
final String newLocation = ResolverMap.combine(getCurrentDir(), location);
log.info("Loading configuration from [" + newLocation + "]");
InputStream is = null;
try {
is = getResolver().resolve(newLocation);
} catch (ResourceRetrievalException e) {
log.error("Could not retrieve resource");
return;
}
parseAndConstructConfiguration(is);
try {
getResolver().observeChange(newLocation, new Consumer<InputStream>() {
@Override
public void call(InputStream inputStream) {
log.info("Loading configuration from [" + newLocation + "]");
if (!getContextLost()) {
try {
parseAndConstructConfiguration(inputStream);
getResolver().observeChange(newLocation, this);
} catch (ResourceRetrievalException ignored) {
} catch (IOException ignored) {
}
}
}
});
} catch (Exception warn) {
URL url = null;
try {
url = new URL(newLocation);
} catch (MalformedURLException ignored) {
}
String schema = "";
if (url != null) {
schema = url.getProtocol();
}
log.warn("Could not observe AMC location for " + schema);
}
}
}
use of com.predic8.schema.Schema in project service-proxy by membrane.
the class JSONSchemaValidationTest method validate.
private void validate(String schema, String json, boolean success) throws IOException, Exception {
final StringBuffer sb = new StringBuffer();
FailureHandler fh = new FailureHandler() {
@Override
public void handleFailure(String message, Exchange exc) {
sb.append(message);
sb.append("\n");
}
};
JSONValidator jsonValidator = new JSONValidator(new ResolverMap(), schema, fh);
Request request = new Request.Builder().body(IOUtils.toByteArray(getClass().getResourceAsStream(json))).build();
Exchange exchange = new Exchange(null);
jsonValidator.validateMessage(exchange, request, "request");
if (success)
Assert.assertTrue(sb.toString(), sb.length() == 0);
else
Assert.assertTrue("No error occurred, but expected one.", sb.length() != 0);
}
use of com.predic8.schema.Schema in project service-proxy by membrane.
the class ValidatorInterceptorTest method createSchemaValidatorInterceptor.
private ValidatorInterceptor createSchemaValidatorInterceptor(String schema) throws Exception {
ValidatorInterceptor interceptor = new ValidatorInterceptor();
interceptor.setResourceResolver(new ResolverMap());
interceptor.setSchema(schema);
interceptor.init();
return interceptor;
}
use of com.predic8.schema.Schema in project core by s4.
the class AbstractPE method setKeyValue.
private void setKeyValue(Object event, CompoundKeyInfo compoundKeyInfo) {
if (compoundKeyInfo == null) {
return;
}
keyValue = new ArrayList<Object>();
Schema schema = schemaContainer.getSchema(event.getClass());
// get the value for each keyInfo
for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
Object value = null;
Object record = event;
List<?> list = null;
Property property = null;
for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
if (keyPathElement instanceof KeyPathElementIndex) {
record = list.get(((KeyPathElementIndex) keyPathElement).getIndex());
schema = property.getComponentProperty().getSchema();
} else {
String keyPathElementName = ((KeyPathElementName) keyPathElement).getKeyName();
property = schema.getProperties().get(keyPathElementName);
value = null;
try {
value = property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
if (value == null) {
Logger.getLogger("s4").error("Value for " + keyPathElementName + " is null!");
return;
}
if (property.getType().isPrimitive() || property.isNumber() || property.getType().equals(String.class)) {
keyValue.add(value);
if (saveKeyRecord) {
if (keyRecord == null) {
keyRecord = new ArrayList<Object>();
}
keyRecord.add(record);
}
continue;
} else if (property.isList()) {
try {
list = (List) property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
} else {
try {
record = property.getGetterMethod().invoke(record);
} catch (Exception e) {
Logger.getLogger("s4").error(e);
return;
}
schema = property.getSchema();
}
}
}
}
}
Aggregations