use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.
the class InnerPollerParserTests method testRefDefaultTrue.
@Test
public void testRefDefaultTrue() {
try {
// Load context from a String to avoid IDEs reporting the invalid configuration
String badContext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<beans xmlns=\"http://www.springframework.org/schema/beans\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:int=\"http://www.springframework.org/schema/integration\"" + " xmlns:int-jdbc=\"http://www.springframework.org/schema/integration/jdbc\"" + " xsi:schemaLocation=\"http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd" + " http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" + " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">" + "" + " <int:poller id=\"outer\" fixed-rate=\"5000\"/>" + "" + " <int:channel id=\"someChannel\"/>" + "" + " <int-jdbc:inbound-channel-adapter channel=\"someChannel\" jdbc-operations=\"ops\"" + " query=\"select 1\">" + // <<<<< default true not allowed here
" <int:poller ref=\"outer\" default=\"true\"/>" + " </int-jdbc:inbound-channel-adapter>" + "" + " <bean id=\"ops\" class=\"org.mockito.Mockito\" factory-method=\"mock\">" + " <constructor-arg value=\"org.springframework.jdbc.core.JdbcOperations\"/>" + " </bean>" + "</beans>";
Resource resource = new ByteArrayResource(badContext.getBytes());
new GenericXmlApplicationContext(resource).close();
fail("Expected Failure to load ApplicationContext");
} catch (BeanDefinitionParsingException bdpe) {
assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
}
}
use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration by spring-projects.
the class InnerPollerParserTests method testRefExtraAttribute.
@Test
public void testRefExtraAttribute() {
try {
// Load context from a String to avoid IDEs reporting the invalid configuration
String badContext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<beans xmlns=\"http://www.springframework.org/schema/beans\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:int=\"http://www.springframework.org/schema/integration\"" + " xmlns:int-jdbc=\"http://www.springframework.org/schema/integration/jdbc\"" + " xsi:schemaLocation=\"http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd" + " http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" + " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">" + "" + " <int:poller id=\"outer\" fixed-rate=\"5000\"/>" + "" + " <int:channel id=\"someChannel\"/>" + "" + " <int-jdbc:inbound-channel-adapter channel=\"someChannel\" jdbc-operations=\"ops\"" + " query=\"select 1\">" + // <<<<< fixed-rate not allowed here
" <int:poller ref=\"outer\" fixed-rate=\"1000\"/>" + " </int-jdbc:inbound-channel-adapter>" + "" + " <bean id=\"ops\" class=\"org.mockito.Mockito\" factory-method=\"mock\">" + " <constructor-arg value=\"org.springframework.jdbc.core.JdbcOperations\"/>" + " </bean>" + "</beans>";
Resource resource = new ByteArrayResource(badContext.getBytes());
new GenericXmlApplicationContext(resource).close();
fail("Expected Failure to load ApplicationContext");
} catch (BeanDefinitionParsingException bdpe) {
assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
}
}
use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration-samples by spring-projects.
the class Main method main.
/**
* @param args Not used.
*/
public static void main(String... args) throws Exception {
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
final ConfigurableEnvironment env = context.getEnvironment();
boolean mapQuestApiKeyDefined = env.containsProperty("mapquest.apikey");
if (mapQuestApiKeyDefined) {
env.setActiveProfiles("mapquest");
}
context.load("classpath:META-INF/spring/*.xml");
context.refresh();
final TravelGateway travelGateway = context.getBean("travelGateway", TravelGateway.class);
final Scanner scanner = new Scanner(System.in);
System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration Travel App! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n=========================================================");
System.out.println("Please select the city, for which you would like to get traffic and weather information:");
for (City city : City.values()) {
System.out.println(String.format("\t%s. %s", city.getId(), city.getName()));
}
System.out.println("\tq. Quit the application");
System.out.print("Enter your choice: ");
while (true) {
final String input = scanner.nextLine();
if ("q".equals(input.trim())) {
System.out.println("Exiting application...bye.");
break;
} else {
final Integer cityId = Integer.valueOf(input);
final City city = City.getCityForId(cityId);
final String weatherReply = travelGateway.getWeatherByCity(city);
System.out.println("\n=========================================================" + "\n Weather:" + "\n=========================================================");
System.out.println(weatherReply);
if (mapQuestApiKeyDefined) {
final String trafficReply = travelGateway.getTrafficByCity(city);
System.out.println("\n=========================================================" + "\n Traffic:" + "\n=========================================================");
System.out.println(trafficReply);
} else {
LOGGER.warn("Skipping Traffic Information call. Did you setup your MapQuest API Key? " + "e.g. by calling:\n\n $ mvn exec:java -Dmapquest.apikey=\"your_mapquest_api_key_url_decoded\"");
}
System.out.println("\n=========================================================" + "\n Done." + "\n=========================================================");
System.out.print("Enter your choice: ");
}
}
scanner.close();
context.close();
}
use of org.springframework.context.support.GenericXmlApplicationContext in project spring-integration-samples by spring-projects.
the class Main method executeSample2.
private static void executeSample2() {
final Scanner scanner = new Scanner(System.in);
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:META-INF/spring/integration/spring-integration-sample2-context.xml");
context.registerShutdownHook();
context.refresh();
final CoffeeService service = context.getBean(CoffeeService.class);
final String message = "\n\n" + "* Please enter 'list' and press <enter> to get a list of coffees.\n" + "* Enter a coffee id, e.g. '1' and press <enter> to get a description.\n" + "* Please press 'q + Enter' to quit the application.\n";
System.out.println(message);
while (!scanner.hasNext("q")) {
String input = scanner.nextLine();
if ("list".equalsIgnoreCase(input)) {
List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();
for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName()));
}
} else {
System.out.println("Retrieving coffee information...");
String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));
System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n");
}
}
scanner.close();
context.close();
System.out.println("Back to main menu.");
}
use of org.springframework.context.support.GenericXmlApplicationContext in project spring-framework by spring-projects.
the class EnvironmentSystemIntegrationTests method genericXmlApplicationContext.
@Test
void genericXmlApplicationContext() {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
assertHasStandardEnvironment(ctx);
ctx.setEnvironment(prodEnv);
ctx.load(XML_PATH);
ctx.refresh();
assertHasEnvironment(ctx, prodEnv);
assertEnvironmentBeanRegistered(ctx);
assertEnvironmentAwareInvoked(ctx, prodEnv);
assertThat(ctx.containsBean(DEV_BEAN_NAME)).isFalse();
assertThat(ctx.containsBean(PROD_BEAN_NAME)).isTrue();
}
Aggregations