use of org.pentaho.di.trans.steps.http.HTTPMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testHttpClientStep.
@Test
public void testHttpClientStep() throws Exception {
HttpClientStepNode node = root.getHttpClientStepNode();
assertNotNull(node);
Iterable<FramedMetaverseNode> inputUrls = node.getInputUrls();
int countInputUrls = getIterableSize(inputUrls);
assertEquals(1, countInputUrls);
assertEquals("HTTP Client", node.getStepType());
HTTPMeta stepMeta = (HTTPMeta) getStepMeta(node);
for (FramedMetaverseNode inputUrl : inputUrls) {
assertEquals(stepMeta.getUrl(), inputUrl.getName());
}
// check the param field is "used"
Iterable<StreamFieldNode> streamFieldNodesUses = node.getStreamFieldNodesUses();
assertEquals(2, getIterableSize(streamFieldNodesUses));
Iterable<StreamFieldNode> outputs = node.getOutputStreamFields();
assertEquals(5, getIterableSize(outputs));
Iterable<StreamFieldNode> inputs = node.getInputStreamFields();
assertEquals(3, getIterableSize(inputs));
for (StreamFieldNode in : inputs) {
assertNotNull(in.getFieldNodesDerivedFromMe());
assertEquals(in.getName(), in.getFieldNodesDerivedFromMe().iterator().next().getName());
}
}
use of org.pentaho.di.trans.steps.http.HTTPMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testHTTPClientStep_UrlFromField.
@Test
public void testHTTPClientStep_UrlFromField() throws Exception {
// this is testing a specific TextFileInputStep instance
HttpClientStepNode node = root.getHttpClientStepNode_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);
// it is coming from a field
assertEquals(0, countInputUrls);
HTTPMeta stepMeta = (HTTPMeta) getStepMeta(node);
assertEquals("HTTP Client", node.getStepType());
Set<String> usedFields = new HashSet<>();
Collections.addAll(usedFields, stepMeta.getHeaderField());
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));
}
use of org.pentaho.di.trans.steps.http.HTTPMeta in project pentaho-metaverse by pentaho.
the class HTTPClientExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(HTTP 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
HTTPMeta meta = (HTTPMeta) httpClientInput.getStepMetaInterface();
if (meta == null) {
meta = (HTTPMeta) 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.getHeaderField())) {
for (int i = 0; i < meta.getHeaderField().length; i++) {
String field = meta.getHeaderField()[i];
String label = meta.getHeaderParameter()[i];
resourceInfo.addHeader(label, rowMeta.getString(row, field, null));
}
}
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.addParameter(label, rowMeta.getString(row, field, null));
}
}
resources.add(resourceInfo);
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
}
return resources;
}
Aggregations