mirror of https://github.com/apache/nifi.git
NIFI-9991 Fix: The asn1 StandardRecordModelIteratorProvider's interator returns only the first object read from the input stream.
This closes #6019. Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
This commit is contained in:
parent
a038309ba4
commit
8aaa3d2f10
|
@ -144,7 +144,6 @@ public class JASN1RecordReader implements RecordReader {
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,52 @@ public class StandardRecordModelIteratorProvider implements RecordModelIteratorP
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Iterator<BerType> iterator(InputStream inputStream, ComponentLog logger, Class<? extends BerType> rootClass, String recordField, Field seqOfField) {
|
public Iterator<BerType> iterator(InputStream inputStream, ComponentLog logger, Class<? extends BerType> rootClass, String recordField, Field seqOfField) {
|
||||||
|
if (StringUtils.isEmpty(recordField)) {
|
||||||
|
return new Iterator<BerType>() {
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
boolean hasNext;
|
||||||
|
|
||||||
|
try {
|
||||||
|
hasNext = inputStream.available() > 0;
|
||||||
|
} catch (IOException e) {
|
||||||
|
hasNext = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BerType next() {
|
||||||
|
final BerType model = decode(inputStream, logger, rootClass);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
final BerType model = decode(inputStream, logger, rootClass);
|
||||||
|
|
||||||
|
final List<BerType> recordModels;
|
||||||
|
try {
|
||||||
|
final Method recordModelGetter = rootClass.getMethod(JASN1Utils.toGetterMethod(recordField));
|
||||||
|
final BerType readPointModel = (BerType) recordModelGetter.invoke(model);
|
||||||
|
if (seqOfField != null) {
|
||||||
|
final Class seqOf = JASN1Utils.getSeqOfElementType(seqOfField);
|
||||||
|
recordModels = (List<BerType>) invokeGetter(readPointModel, JASN1Utils.toGetterMethod(seqOf.getSimpleName()));
|
||||||
|
} else {
|
||||||
|
recordModels = Collections.singletonList(readPointModel);
|
||||||
|
}
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new RuntimeException("Failed to get record models due to " + e, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return recordModels.iterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BerType decode(InputStream inputStream, ComponentLog logger, Class<? extends BerType> rootClass) {
|
||||||
final BerType model;
|
final BerType model;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
model = rootClass.getDeclaredConstructor().newInstance();
|
model = rootClass.getDeclaredConstructor().newInstance();
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
|
@ -49,24 +94,6 @@ public class StandardRecordModelIteratorProvider implements RecordModelIteratorP
|
||||||
throw new RuntimeException("Failed to decode " + rootClass.getCanonicalName(), e);
|
throw new RuntimeException("Failed to decode " + rootClass.getCanonicalName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<BerType> recordModels;
|
return model;
|
||||||
if (StringUtils.isEmpty(recordField)) {
|
|
||||||
recordModels = Collections.singletonList(model);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
final Method recordModelGetter = rootClass.getMethod(JASN1Utils.toGetterMethod(recordField));
|
|
||||||
final BerType readPointModel = (BerType) recordModelGetter.invoke(model);
|
|
||||||
if (seqOfField != null) {
|
|
||||||
final Class seqOf = JASN1Utils.getSeqOfElementType(seqOfField);
|
|
||||||
recordModels = (List<BerType>) invokeGetter(readPointModel, JASN1Utils.toGetterMethod(seqOf.getSimpleName()));
|
|
||||||
} else {
|
|
||||||
recordModels = Collections.singletonList(readPointModel);
|
|
||||||
}
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new RuntimeException("Failed to get record models due to " + e, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return recordModels.iterator();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue