use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.
the class TestGetHTTP method testContentModifiedTwoServers.
@Test
public final void testContentModifiedTwoServers() throws Exception {
// set up web services
ServletHandler handler1 = new ServletHandler();
handler1.addServletWithMapping(RESTServiceContentModified.class, "/*");
ServletHandler handler2 = new ServletHandler();
handler2.addServletWithMapping(RESTServiceContentModified.class, "/*");
// create the services
TestServer server1 = new TestServer();
server1.addHandler(handler1);
TestServer server2 = new TestServer();
server2.addHandler(handler2);
try {
server1.startServer();
server2.startServer();
// this is the base urls with the random ports
String destination1 = server1.getUrl();
String destination2 = server2.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination1);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.getStateManager().assertStateNotSet(GetHTTP.ETAG + ":" + destination1, Scope.LOCAL);
controller.getStateManager().assertStateNotSet(GetHTTP.LAST_MODIFIED + ":" + destination1, Scope.LOCAL);
controller.run(2);
// verify the lastModified and entityTag are updated
controller.getStateManager().assertStateNotEquals(GetHTTP.ETAG + ":" + destination1, "", Scope.LOCAL);
controller.getStateManager().assertStateNotEquals(GetHTTP.LAST_MODIFIED + ":" + destination1, "Thu, 01 Jan 1970 00:00:00 GMT", Scope.LOCAL);
// ran twice, but got one...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
controller.clearTransferState();
controller.setProperty(GetHTTP.URL, destination2);
controller.getStateManager().assertStateNotSet(GetHTTP.ETAG + ":" + destination2, Scope.LOCAL);
controller.getStateManager().assertStateNotSet(GetHTTP.LAST_MODIFIED + ":" + destination2, Scope.LOCAL);
controller.run(2);
// ran twice, but got one...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
// verify the lastModified's and entityTags are updated
controller.getStateManager().assertStateNotEquals(GetHTTP.ETAG + ":" + destination1, "", Scope.LOCAL);
controller.getStateManager().assertStateNotEquals(GetHTTP.LAST_MODIFIED + ":" + destination1, "Thu, 01 Jan 1970 00:00:00 GMT", Scope.LOCAL);
controller.getStateManager().assertStateNotEquals(GetHTTP.ETAG + ":" + destination2, "", Scope.LOCAL);
controller.getStateManager().assertStateNotEquals(GetHTTP.LAST_MODIFIED + ":" + destination2, "Thu, 01 Jan 1970 00:00:00 GMT", Scope.LOCAL);
} finally {
// shutdown web services
server1.shutdownServer();
server2.shutdownServer();
}
}
use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.
the class TestGetHTTP method testContentModified.
@Test
public final void testContentModified() throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(RESTServiceContentModified.class, "/*");
// create the service
TestServer server = new TestServer();
server.addHandler(handler);
try {
server.startServer();
// this is the base url with the random port
String destination = server.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.getStateManager().assertStateNotSet(GetHTTP.ETAG, Scope.LOCAL);
controller.getStateManager().assertStateNotSet(GetHTTP.LAST_MODIFIED, Scope.LOCAL);
controller.run(2);
// verify the lastModified and entityTag are updated
controller.getStateManager().assertStateNotEquals(GetHTTP.ETAG + ":" + destination, "", Scope.LOCAL);
controller.getStateManager().assertStateNotEquals(GetHTTP.LAST_MODIFIED + ":" + destination, "Thu, 01 Jan 1970 00:00:00 GMT", Scope.LOCAL);
// ran twice, but got one...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
// verify remote.source flowfile attribute
controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0).assertAttributeEquals("gethttp.remote.source", "localhost");
controller.clearTransferState();
// turn off checking for etag and lastModified
RESTServiceContentModified.IGNORE_ETAG = true;
RESTServiceContentModified.IGNORE_LAST_MODIFIED = true;
controller.run(2);
// ran twice, got two...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 2);
controller.clearTransferState();
// turn on checking for etag
RESTServiceContentModified.IGNORE_ETAG = false;
controller.run(2);
// ran twice, got 0...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
// turn on checking for lastModified, but off for etag
RESTServiceContentModified.IGNORE_LAST_MODIFIED = false;
RESTServiceContentModified.IGNORE_ETAG = true;
controller.run(2);
// ran twice, got 0...which is good
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
// turn off checking for lastModified, turn on checking for etag, but change the value
RESTServiceContentModified.IGNORE_LAST_MODIFIED = true;
RESTServiceContentModified.IGNORE_ETAG = false;
RESTServiceContentModified.ETAG = 1;
controller.run(2);
// ran twice, got 1...but should have new cached etag
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
String eTagStateValue = controller.getStateManager().getState(Scope.LOCAL).get(GetHTTP.ETAG + ":" + destination);
assertEquals("1", GetHTTP.parseStateValue(eTagStateValue).getValue());
controller.clearTransferState();
// turn off checking for Etag, turn on checking for lastModified, but change value
RESTServiceContentModified.IGNORE_LAST_MODIFIED = false;
RESTServiceContentModified.IGNORE_ETAG = true;
RESTServiceContentModified.modificationDate = System.currentTimeMillis() / 1000 * 1000 + 5000;
String lastMod = controller.getStateManager().getState(Scope.LOCAL).get(GetHTTP.LAST_MODIFIED + ":" + destination);
controller.run(2);
// ran twice, got 1...but should have new cached etag
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
controller.getStateManager().assertStateNotEquals(GetHTTP.LAST_MODIFIED + ":" + destination, lastMod, Scope.LOCAL);
controller.clearTransferState();
} finally {
// shutdown web service
server.shutdownServer();
}
}
use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.
the class TestGetHTTP method testCookiePolicy.
@Test
public final void testCookiePolicy() throws Exception {
// set up web services
ServletHandler handler1 = new ServletHandler();
handler1.addServletWithMapping(CookieTestingServlet.class, "/*");
ServletHandler handler2 = new ServletHandler();
handler2.addServletWithMapping(CookieVerificationTestingServlet.class, "/*");
// create the services
TestServer server1 = new TestServer();
server1.addHandler(handler1);
TestServer server2 = new TestServer();
server2.addHandler(handler2);
try {
server1.startServer();
server2.startServer();
// this is the base urls with the random ports
String destination1 = server1.getUrl();
String destination2 = server2.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination1 + "/?redirect=" + URLEncoder.encode(destination2, "UTF-8") + "&datemode=" + CookieTestingServlet.DATEMODE_COOKIE_DEFAULT);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.FOLLOW_REDIRECTS, "true");
controller.run(1);
// verify default cookie data does successful redirect
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1);
MockFlowFile ff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
ff.assertContentEquals("Hello, World!");
controller.clearTransferState();
// verify NON-standard cookie data fails with default redirect_cookie_policy
controller.setProperty(GetHTTP.URL, destination1 + "/?redirect=" + URLEncoder.encode(destination2, "UTF-8") + "&datemode=" + CookieTestingServlet.DATEMODE_COOKIE_NOT_TYPICAL);
controller.run(1);
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 0);
controller.clearTransferState();
// change GetHTTP to place it in STANDARD cookie policy mode
controller.setProperty(GetHTTP.REDIRECT_COOKIE_POLICY, GetHTTP.STANDARD_COOKIE_POLICY_STR);
controller.setProperty(GetHTTP.URL, destination1 + "/?redirect=" + URLEncoder.encode(destination2, "UTF-8") + "&datemode=" + CookieTestingServlet.DATEMODE_COOKIE_NOT_TYPICAL);
controller.run(1);
// verify NON-standard cookie data does successful redirect
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1);
ff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
ff.assertContentEquals("Hello, World!");
} finally {
// shutdown web services
server1.shutdownServer();
server2.shutdownServer();
}
}
use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.
the class TestGetHTTP method testUserAgent.
@Test
public final void testUserAgent() throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(UserAgentTestingServlet.class, "/*");
// create the service
TestServer server = new TestServer();
server.addHandler(handler);
try {
server.startServer();
String destination = server.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
// shutdown web service
} finally {
server.shutdownServer();
}
}
use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.
the class TestGetHTTP method testSecure_twoWaySsl.
@Test
public final void testSecure_twoWaySsl() throws Exception {
// set up web service
final ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(HelloWorldServlet.class, "/*");
// create the service, providing both truststore and keystore properties, requiring client auth (default)
final Map<String, String> twoWaySslProperties = getKeystoreProperties();
twoWaySslProperties.putAll(getTruststoreProperties());
final TestServer server = new TestServer(twoWaySslProperties);
server.addHandler(handler);
try {
server.startServer();
final String destination = server.getSecureUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
// Use context service with a keystore and a truststore
useSSLContextService(twoWaySslProperties);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "10 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.run();
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1);
final MockFlowFile mff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
mff.assertContentEquals("Hello, World!");
} finally {
server.shutdownServer();
}
}
Aggregations