use of org.eclipse.jetty.server.handler.ContextHandler in project apollo by ctripcorp.
the class ConfigIntegrationTest method testGetConfigWithNoLocalFileButWithRemoteConfig.
@Test
public void testGetConfigWithNoLocalFileButWithRemoteConfig() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String someNonExistedKey = "someNonExistedKey";
String someDefaultValue = "someDefaultValue";
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, someValue));
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
assertEquals(someDefaultValue, config.getProperty(someNonExistedKey, someDefaultValue));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project apollo by ctripcorp.
the class ConfigIntegrationTest method testGetConfigWithNoLocalFileAndRemoteMetaServiceRetry.
@Test
public void testGetConfigWithNoLocalFileAndRemoteMetaServiceRetry() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, someValue));
ContextHandler configHandler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
boolean failAtFirstTime = true;
ContextHandler metaServerHandler = mockMetaServerHandler(failAtFirstTime);
startServerWithHandlers(metaServerHandler, configHandler);
Config config = ConfigService.getAppConfig();
assertEquals(someValue, config.getProperty(someKey, null));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project apollo by ctripcorp.
the class ConfigIntegrationTest method testGetConfigWithLocalFileAndWithRemoteConfig.
@Test
public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception {
String someKey = "someKey";
String someValue = "someValue";
String anotherValue = "anotherValue";
Properties properties = new Properties();
properties.put(someKey, someValue);
createLocalCachePropertyFile(properties);
ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue));
ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
startServerWithHandlers(handler);
Config config = ConfigService.getAppConfig();
assertEquals(anotherValue, config.getProperty(someKey, null));
}
use of org.eclipse.jetty.server.handler.ContextHandler in project apollo by ctripcorp.
the class BaseIntegrationTest method mockMetaServerHandler.
protected ContextHandler mockMetaServerHandler(final boolean failedAtFirstTime) {
final ServiceDTO someServiceDTO = new ServiceDTO();
someServiceDTO.setAppName(someAppName);
someServiceDTO.setInstanceId(someInstanceId);
someServiceDTO.setHomepageUrl(configServiceURL);
final AtomicInteger counter = new AtomicInteger(0);
ContextHandler context = new ContextHandler("/services/config");
context.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (failedAtFirstTime && counter.incrementAndGet() == 1) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
baseRequest.setHandled(true);
return;
}
response.setContentType("application/json;charset=UTF-8");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(gson.toJson(Lists.newArrayList(someServiceDTO)));
baseRequest.setHandled(true);
}
});
return context;
}
use of org.eclipse.jetty.server.handler.ContextHandler in project camel by apache.
the class HttpProducerSessionTest method initServer.
@BeforeClass
public static void initServer() throws Exception {
port = AvailablePortFinder.getNextAvailable(24000);
localServer = new Server(new InetSocketAddress("127.0.0.1", port));
ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/session");
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setHandler(new SessionReflectionHandler());
contextHandler.setHandler(sessionHandler);
localServer.setHandler(contextHandler);
localServer.start();
}
Aggregations