use of org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta in project pentaho-metaverse by pentaho.
the class HTTPPostExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(HTTPPOST httpClientInput, RowMetaInterface rowMeta, Object[] row) {
Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
// For some reason the step doesn't return the StepMetaInterface directly, so go around it
HTTPPOSTMeta meta = (HTTPPOSTMeta) httpClientInput.getStepMetaInterface();
if (meta == null) {
meta = (HTTPPOSTMeta) httpClientInput.getStepMeta().getStepMetaInterface();
}
if (meta != null) {
try {
String url;
if (meta.isUrlInField()) {
url = rowMeta.getString(row, meta.getUrlField(), null);
} else {
url = meta.getUrl();
}
if (!Const.isEmpty(url)) {
WebServiceResourceInfo resourceInfo = (WebServiceResourceInfo) ExternalResourceInfoFactory.createURLResource(url, true);
if (ArrayUtils.isNotEmpty(meta.getArgumentField())) {
for (int i = 0; i < meta.getArgumentField().length; i++) {
String field = meta.getArgumentField()[i];
String label = meta.getArgumentParameter()[i];
resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
}
}
if (ArrayUtils.isNotEmpty(meta.getQueryField())) {
for (int i = 0; i < meta.getQueryField().length; i++) {
String field = meta.getQueryField()[i];
String label = meta.getQueryParameter()[i];
resourceInfo.addParameter(label, rowMeta.getString(row, field, null));
}
}
resources.add(resourceInfo);
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
}
return resources;
}
use of org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testHTTPPostStep_UrlFromField.
@Test
public void testHTTPPostStep_UrlFromField() throws Exception {
// this is testing a specific TextFileInputStep instance
HttpPostStepNode node = root.getHttpPostStepNode_urlFromField();
assertNotNull(node);
// this HTTP Client gets it's files from an incoming stream field, there should be no files modeled statically
Iterable<FramedMetaverseNode> inputUrls = node.getInputUrls();
int countInputUrls = getIterableSize(inputUrls);
assertEquals(0, countInputUrls);
assertEquals("HTTP Post", node.getStepType());
HTTPPOSTMeta stepMeta = (HTTPPOSTMeta) getStepMeta(node);
Set<String> usedFields = new HashSet<>();
Collections.addAll(usedFields, stepMeta.getQueryField());
Collections.addAll(usedFields, stepMeta.getArgumentField());
if (stepMeta.isUrlInField()) {
usedFields.add(stepMeta.getUrlField());
}
// check the param field is "used"
Iterable<StreamFieldNode> streamFieldNodesUses = node.getStreamFieldNodesUses();
assertEquals(usedFields.size(), getIterableSize(streamFieldNodesUses));
for (StreamFieldNode streamFieldNodesUse : streamFieldNodesUses) {
assertTrue(usedFields.contains(streamFieldNodesUse.getName()));
}
Iterable<StreamFieldNode> outputs = node.getOutputStreamFields();
assertEquals(getExpectedOutputFieldCount(stepMeta), getIterableSize(outputs));
}
Aggregations