use of org.infinispan.protostream.FileDescriptorSource in project kogito-apps by kiegroup.
the class ProtostreamProducerTest method kogitoTypesDescriptor.
@Test
void kogitoTypesDescriptor() {
try {
FileDescriptorSource fileDescriptorSource = protostreamProducer.kogitoTypesDescriptor();
assertTrue(fileDescriptorSource.getFileDescriptors().containsKey(KOGITO_INDEX_PROTO));
assertTrue(fileDescriptorSource.getFileDescriptors().containsKey(KOGITO_TYPES_PROTO));
} catch (IOException e) {
fail("Failed with IOException", e);
}
}
use of org.infinispan.protostream.FileDescriptorSource in project kogito-apps by kiegroup.
the class ProtoIndexParserTest method testConfigureBuilderWithInvalidFile.
@Test
void testConfigureBuilderWithInvalidFile() {
SerializationContext ctx = new SerializationContextImpl(configureBuilder().build());
FileDescriptorSource invalidFileDescriptorSource = FileDescriptorSource.fromString("invalid", "invalid");
try {
ctx.registerProtoFiles(invalidFileDescriptorSource);
fail("Failed to process invalid proto file");
} catch (DescriptorParserException ex) {
// Successfully throw exception
}
}
use of org.infinispan.protostream.FileDescriptorSource in project infinispan by infinispan.
the class ProtobufMetadataManagerInterceptor method visitPutMapCommand.
@Override
public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) {
if (!ctx.isOriginLocal()) {
return invokeNext(ctx, command);
}
final Map<Object, Object> map = command.getMap();
FileDescriptorSource source = new FileDescriptorSource();
for (Object key : map.keySet()) {
final Object value = map.get(key);
if (!(key instanceof String)) {
throw log.keyMustBeString(key.getClass());
}
if (!(value instanceof String)) {
throw log.valueMustBeString(value.getClass());
}
if (shouldIntercept(key)) {
if (!((String) key).endsWith(PROTO_KEY_SUFFIX)) {
throw log.keyMustBeStringEndingWithProto(key);
}
source.addProtoFile((String) key, (String) value);
}
}
// lock global errors key
VisitableCommand cmd = commandsFactory.buildLockControlCommand(ERRORS_KEY_SUFFIX, command.getFlagsBitSet(), null);
InvocationStage stage = invoker.running().invokeStage(ctx, cmd);
return makeStage(asyncInvokeNext(ctx, command, stage)).thenApply(ctx, command, (rCtx, rCommand, rv) -> {
long flagsBitSet = copyFlags(rCommand);
ProgressCallback progressCallback = null;
if (rCtx.isOriginLocal()) {
progressCallback = new ProgressCallback();
source.withProgressCallback(progressCallback);
} else {
source.withProgressCallback(EMPTY_CALLBACK);
}
registerFileDescriptorSource(source, source.getFiles().keySet().toString());
if (progressCallback != null) {
List<KeyValuePair<String, String>> errorUpdates = computeErrorUpdates(progressCallback);
return updateSchemaErrorsIterator(rCtx, flagsBitSet, errorUpdates.iterator());
}
return InvocationStage.completedNullStage();
});
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class ProtoSchemaBuilder method main.
public static void main(String[] args) throws Exception {
CommandLine cmd = parseCommandLine(args);
if (cmd == null) {
return;
}
String packageName = cmd.getOptionValue(PACKAGE_LONG_OPT);
Configuration config = Configuration.builder().build();
SerializationContext ctx = ProtobufUtil.newSerializationContext(config);
Properties schemas = cmd.getOptionProperties(SCHEMA_LONG_OPT);
if (schemas != null) {
for (String schema : schemas.stringPropertyNames()) {
String file = schemas.getProperty(schema);
try (FileInputStream in = new FileInputStream(file)) {
ctx.registerProtoFiles(new FileDescriptorSource().addProtoFile(schema, in));
}
}
}
String[] marshallers = cmd.getOptionValues(MARSHALLER_LONG_OPT);
if (marshallers != null) {
for (String marshallerClass : marshallers) {
BaseMarshaller<?> bm = (BaseMarshaller<?>) Class.forName(marshallerClass).newInstance();
ctx.registerMarshaller(bm);
}
}
File file = cmd.hasOption(FILE_LONG_OPT) ? new File(cmd.getOptionValue(FILE_LONG_OPT)) : null;
String fileName = file == null ? DEFAULT_GENERATED_SCHEMA_NAME : file.getName();
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder().fileName(fileName).packageName(packageName);
for (String className : cmd.getArgs()) {
protoSchemaBuilder.addClass(Class.forName(className));
}
String schemaFile = protoSchemaBuilder.build(ctx);
if (file != null) {
try (PrintStream out = new PrintStream(new FileOutputStream(file))) {
out.print(schemaFile);
out.flush();
}
} else {
System.out.print(schemaFile);
}
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testNotImportedInSamePackage.
@Test
public void testNotImportedInSamePackage() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Failed to resolve type of field \"test.M2.b\". Type not found : M1");
String file1 = "package test;\n" + "message M1 {\n" + " required string a = 1;\n" + "}";
String file2 = "package test;\n" + "message M2 {\n" + " required M1 b = 2;\n" + "}";
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("file1.proto", file1);
fileDescriptorSource.addProtoFile("file2.proto", file2);
parseAndResolve(fileDescriptorSource);
}
Aggregations