Search in sources :

Example 1 with HTTPPOSTMeta

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;
}
Also used : HTTPPOSTMeta(org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta) 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)

Example 2 with HTTPPOSTMeta

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

Aggregations

HTTPPOSTMeta (org.pentaho.di.trans.steps.httppost.HTTPPOSTMeta)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)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 FramedMetaverseNode (org.pentaho.metaverse.frames.FramedMetaverseNode)1 HttpPostStepNode (org.pentaho.metaverse.frames.HttpPostStepNode)1 StreamFieldNode (org.pentaho.metaverse.frames.StreamFieldNode)1