@Test(timeout=10000) public void testRequestAddedToService() throws InitializationException, MalformedURLException, IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(HandleHttpRequest.class); runner.setProperty(HandleHttpRequest.PORT, "0"); runner.setProperty(HandleHttpRequest.PATH_REGEX,"/my/path"); final MockHttpContextMap contextMap = new MockHttpContextMap(); runner.addControllerService("http-context-map", contextMap); runner.enableControllerService(contextMap); runner.setProperty(HandleHttpRequest.HTTP_CONTEXT_MAP, "http-context-map"); runner.run(1, false); try { final Thread httpThread = new Thread(new Runnable() { @Override public void run() { try { final int port = ((HandleHttpRequest) runner.getProcessor()).getPort(); final HttpURLConnection connection = (HttpURLConnection) new URL("http: + port + "/my/path?query=true&value1=value1&value2=&value3&value4=apple=orange").openConnection(); connection.setDoOutput(false); connection.setRequestMethod("GET"); connection.setRequestProperty("header1", "value1"); connection.setRequestProperty("header2", ""); connection.setRequestProperty("header3", "apple=orange"); connection.setConnectTimeout(3000); connection.setReadTimeout(3000); StreamUtils.copy(connection.getInputStream(), new NullOutputStream()); } catch (final Throwable t) { t.printStackTrace(); Assert.fail(t.toString()); } } }); httpThread.start(); while ( runner.getFlowFilesForRelationship(HandleHttpRequest.REL_SUCCESS).isEmpty() ) { runner.run(1, false, false); } runner.assertAllFlowFilesTransferred(HandleHttpRequest.REL_SUCCESS, 1); assertEquals(1, contextMap.size()); final MockFlowFile mff = runner.getFlowFilesForRelationship(HandleHttpRequest.REL_SUCCESS).get(0); mff.assertAttributeEquals("http.query.param.query", "true"); mff.assertAttributeEquals("http.query.param.value1", "value1"); mff.assertAttributeEquals("http.query.param.value2", ""); mff.assertAttributeEquals("http.query.param.value3", ""); mff.assertAttributeEquals("http.query.param.value4", "apple=orange"); mff.assertAttributeEquals("http.headers.header1", "value1"); mff.assertAttributeEquals("http.headers.header3", "apple=orange"); } finally { runner.run(1, true); } }
protected int getPort() { for (final Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { return ((ServerConnector) connector).getLocalPort(); } } throw new IllegalStateException("Server is not listening on any ports"); }
HandleHttpRequest extends AbstractProcessor { protected int getPort() { for (final Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { return ((ServerConnector) connector).getLocalPort(); } } throw new IllegalStateException("Server is not listening on any ports"); } }
HandleHttpRequest extends AbstractProcessor { protected int getPort() { for (final Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { return ((ServerConnector) connector).getLocalPort(); } } throw new IllegalStateException("Server is not listening on any ports"); }  }
HandleHttpRequest extends AbstractProcessor { protected int getPort() { for (final Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { return ((ServerConnector) connector).getLocalPort(); } } throw new IllegalStateException("Server is not listening on any ports"); }  @Override Set<Relationship> getRelationships(); @Override void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue); @OnScheduled void onScheduled(final ProcessContext context); @OnStopped void shutdown(); @OnRemoved void onRemoved(ProcessContext processContext); @Override void onTrigger(final ProcessContext context, final ProcessSession session); }
HandleHttpRequest extends AbstractProcessor { protected int getPort() { for (final Connector connector : server.getConnectors()) { if (connector instanceof ServerConnector) { return ((ServerConnector) connector).getLocalPort(); } } throw new IllegalStateException("Server is not listening on any ports"); }  @Override Set<Relationship> getRelationships(); @Override void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue); @OnScheduled void onScheduled(final ProcessContext context); @OnStopped void shutdown(); @OnRemoved void onRemoved(ProcessContext processContext); @Override void onTrigger(final ProcessContext context, final ProcessSession session); static final AllowableValue CLIENT_NONE; static final AllowableValue CLIENT_WANT; static final AllowableValue CLIENT_NEED; static final PropertyDescriptor PORT; static final PropertyDescriptor HOSTNAME; static final PropertyDescriptor HTTP_CONTEXT_MAP; static final PropertyDescriptor SSL_CONTEXT; static final PropertyDescriptor URL_CHARACTER_SET; static final PropertyDescriptor PATH_REGEX; static final PropertyDescriptor ALLOW_GET; static final PropertyDescriptor ALLOW_POST; static final PropertyDescriptor ALLOW_PUT; static final PropertyDescriptor ALLOW_DELETE; static final PropertyDescriptor ALLOW_HEAD; static final PropertyDescriptor ALLOW_OPTIONS; static final PropertyDescriptor ADDITIONAL_METHODS; static final PropertyDescriptor CLIENT_AUTH; static final PropertyDescriptor CONTAINER_QUEUE_SIZE; static final PropertyDescriptor SUPPORT_API_REGISTRY; static final PropertyDescriptor HTTP_API_REGISTRY; static final PropertyDescriptor HTTP_AUTHENTICATION; static final Relationship REL_SUCCESS; }