You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by ddewaele <gi...@git.apache.org> on 2016/12/29 22:29:15 UTC

[GitHub] nifi pull request #1373: NIFI-3266 Added EL support for basePath and port in...

GitHub user ddewaele opened a pull request:

    https://github.com/apache/nifi/pull/1373

    NIFI-3266 Added EL support for basePath and port in ListenHTTP

    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [x] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [x] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/IxorTalk/nifi nifi-3266

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1373.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1373
    
----
commit d4c804000386db5b4689e948df7718aabbade696
Author: Davy De Waele <dd...@gmail.com>
Date:   2016-12-29T22:24:21Z

    NIFI-3266 Added EL support for basePath and port in ListenHTTP

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1373: NIFI-3266 Added EL support for basePath and port in...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/1373


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1373: NIFI-3266 Added EL support for basePath and port in...

Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1373#discussion_r94231391
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenHTTP.java ---
    @@ -16,22 +16,6 @@
      */
     package org.apache.nifi.processors.standard;
     
    -import java.io.IOException;
    -import java.util.ArrayList;
    -import java.util.Collections;
    -import java.util.HashSet;
    -import java.util.List;
    -import java.util.Map;
    -import java.util.Set;
    -import java.util.concurrent.ConcurrentHashMap;
    -import java.util.concurrent.ConcurrentMap;
    -import java.util.concurrent.TimeUnit;
    -import java.util.concurrent.atomic.AtomicReference;
    -import java.util.regex.Pattern;
    -
    -import javax.servlet.Servlet;
    -import javax.ws.rs.Path;
    -
    --- End diff --
    
    Could you fix import order? (I know this is probably automatically done by your IDE, but it is better to keep the change to what is really needed)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1373: NIFI-3266 Added EL support for basePath and port in...

Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1373#discussion_r94231446
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java ---
    @@ -0,0 +1,175 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.processors.standard;
    +
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSessionFactory;
    +import org.apache.nifi.reporting.InitializationException;
    +import org.apache.nifi.ssl.SSLContextService;
    +import org.apache.nifi.ssl.StandardSSLContextService;
    +import org.apache.nifi.util.MockFlowFile;
    +import org.apache.nifi.util.TestRunner;
    +import org.apache.nifi.util.TestRunners;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +import java.net.HttpURLConnection;
    +import java.net.ServerSocket;
    +import java.net.URL;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import static org.apache.nifi.processors.standard.ListenHTTP.RELATIONSHIP_SUCCESS;
    +import static org.junit.Assert.fail;
    +
    +public class TestListenHTTP {
    +
    +    private static final String HTTP_POST_METHOD = "POST";
    +    private static final String HTTP_BASE_PATH = "basePath";
    +
    +    private final static String PORT_VARIABLE = "HTTP_PORT";
    +    private final static String HTTP_SERVER_PORT_EL = "${" + PORT_VARIABLE + "}";
    +
    +    private final static String BASEPATH_VARIABLE = "HTTP_BASEPATH";
    +    private final static String HTTP_SERVER_BASEPATH_EL = "${" + BASEPATH_VARIABLE + "}";
    +
    +    private ListenHTTP proc;
    +    private TestRunner runner;
    +
    +    private int availablePort;
    +
    +    @Before
    +    public void setup() throws IOException {
    +        proc = new ListenHTTP();
    +        runner = TestRunners.newTestRunner(proc);
    +        availablePort = findAvailablePort();
    +        runner.setVariable(PORT_VARIABLE, Integer.toString(availablePort));
    +        runner.setVariable(BASEPATH_VARIABLE,HTTP_BASE_PATH);
    +
    +    }
    +
    +    @Test
    +    public void testPOSTRequestsReceivedWithoutEL() throws Exception {
    +
    +        runner.setProperty(ListenHTTP.PORT, Integer.toString(availablePort));
    +        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
    +
    +        testPOSTRequestsReceived();
    +    }
    +
    +    @Test
    +    public void testPOSTRequestsReceivedWithEL() throws Exception {
    +
    +        runner.setProperty(ListenHTTP.PORT, HTTP_SERVER_PORT_EL);
    +        runner.setProperty(ListenHTTP.BASE_PATH, HTTP_SERVER_BASEPATH_EL);
    +
    +        testPOSTRequestsReceived();
    +    }
    +
    +    private int executePOST(String message) throws Exception {
    +
    +        URL url= new URL("http://localhost:" + availablePort + "/" + HTTP_BASE_PATH);
    +        HttpURLConnection con = (HttpURLConnection) url.openConnection();
    +
    +        con.setRequestMethod(HTTP_POST_METHOD);
    +        con.setDoOutput(true);
    +        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    +        if (message!=null) {
    +            wr.writeBytes(message);
    +        }
    +        wr.flush();
    +        wr.close();
    +
    +        return con.getResponseCode();
    +
    +    }
    +    private void testPOSTRequestsReceived() throws Exception {
    +        final List<String> messages = new ArrayList<>();
    +        messages.add("payload 1");
    +        messages.add("");
    +        messages.add(null);
    +        messages.add("payload 2");
    +
    +        startWebServerAndSendMessages(messages);
    +
    +        List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(RELATIONSHIP_SUCCESS);
    +
    +        runner.assertTransferCount(RELATIONSHIP_SUCCESS,4);
    +        mockFlowFiles.get(0).assertContentEquals("payload 1");
    +        mockFlowFiles.get(1).assertContentEquals("");
    +        mockFlowFiles.get(2).assertContentEquals("");
    +        mockFlowFiles.get(3).assertContentEquals("payload 2");
    +    }
    +
    +    private void startWebServerAndSendMessages(final List<String> messages)
    +            throws Exception {
    +
    +            final ProcessSessionFactory processSessionFactory = runner.getProcessSessionFactory();
    +            final ProcessContext context = runner.getProcessContext();
    +            proc.createHttpServer(context);
    +
    +            Runnable sendMessagestoWebServer = () -> {
    +                try {
    +                    for (final String message : messages) {
    +                        if (executePOST(message)!=200) fail("HTTP POST failed.");
    +                    }
    +                } catch (Exception e) {
    +                    e.printStackTrace();
    +                    fail("Not expecting error here.");
    +                }
    +            };
    +            new Thread(sendMessagestoWebServer).start();
    +
    +            long responseTimeout = 10000;
    +
    +            int numTransferred = 0;
    +            long startTime = System.currentTimeMillis();
    +            while (numTransferred < messages.size()  && (System.currentTimeMillis() - startTime < responseTimeout)) {
    +                proc.onTrigger(context, processSessionFactory);
    +                numTransferred = runner.getFlowFilesForRelationship(RELATIONSHIP_SUCCESS).size();
    +                Thread.sleep(100);
    +            }
    +
    +            runner.assertTransferCount(ListenTCP.REL_SUCCESS, messages.size());
    --- End diff --
    
    ListenTCP?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1373: NIFI-3266 Added EL support for basePath and port in Listen...

Posted by ddewaele <gi...@git.apache.org>.
Github user ddewaele commented on the issue:

    https://github.com/apache/nifi/pull/1373
  
    @pvillard31 : applied review comments


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1373: NIFI-3266 Added EL support for basePath and port in Listen...

Posted by pvillard31 <gi...@git.apache.org>.
Github user pvillard31 commented on the issue:

    https://github.com/apache/nifi/pull/1373
  
    Reviewing...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---