Search in sources :

Example 1 with HTTPMeta

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());
    }
}
Also used : StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) HttpClientStepNode(org.pentaho.metaverse.frames.HttpClientStepNode) HTTPMeta(org.pentaho.di.trans.steps.http.HTTPMeta) Test(org.junit.Test)

Example 2 with HTTPMeta

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));
}
Also used : StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) HttpClientStepNode(org.pentaho.metaverse.frames.HttpClientStepNode) HTTPMeta(org.pentaho.di.trans.steps.http.HTTPMeta) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with HTTPMeta

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) WebServiceResourceInfo(org.pentaho.metaverse.api.model.WebServiceResourceInfo) LinkedList(java.util.LinkedList) HTTPMeta(org.pentaho.di.trans.steps.http.HTTPMeta)

Aggregations

HTTPMeta (org.pentaho.di.trans.steps.http.HTTPMeta)3 Test (org.junit.Test)2 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)2 HttpClientStepNode (org.pentaho.metaverse.frames.HttpClientStepNode)2 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 KettleException (org.pentaho.di.core.exception.KettleException)1 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)1 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)1