@Test(timeout=10000) public void testFailToRegister() throws InitializationException, MalformedURLException, IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(HandleHttpRequest.class); runner.setProperty(HandleHttpRequest.PORT, "0"); final MockHttpContextMap contextMap = new MockHttpContextMap(); runner.addControllerService("http-context-map", contextMap); runner.enableControllerService(contextMap); runner.setProperty(HandleHttpRequest.HTTP_CONTEXT_MAP, "http-context-map"); contextMap.setRegisterSuccessfully(false); runner.run(1, false); try { final int[] responseCode = new int[1]; responseCode[0] = 0; final Thread httpThread = new Thread(new Runnable() { @Override public void run() { HttpURLConnection connection = null; try { final int port = ((HandleHttpRequest) runner.getProcessor()).getPort(); 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(); if(connection != null ) { try { responseCode[0] = connection.getResponseCode(); } catch (IOException e) { responseCode[0] = -1; } } else { responseCode[0] = -2; } } } }); httpThread.start(); while (responseCode[0] == 0) { runner.run(1, false, false); } runner.assertTransferCount(HandleHttpRequest.REL_SUCCESS, 0); assertEquals(503, responseCode[0]); } 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(); @OnScheduled void clearInit(); @OnStopped void shutdown(); @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(); @OnScheduled void clearInit(); @OnStopped void shutdown(); @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 Relationship REL_SUCCESS; }