本文整理汇总了Java中org.apache.commons.configuration2.ex.ConfigurationException类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationException类的具体用法?Java ConfigurationException怎么用?Java ConfigurationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationException类属于org.apache.commons.configuration2.ex包,在下文中一共展示了ConfigurationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBoard
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
@Override
public void showBoard() {
File paramFile = new File("config/mainboardfx.properties");
try {
final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(
PropertiesConfiguration.class)
.configure(
new FileBasedBuilderParametersImpl().setFile(paramFile).setEncoding("utf8"));
cfg = builder.getConfiguration();
} catch (ConfigurationException ex) {
QLog.l().logger()
.error("Не загружен файл конфигурации " + paramFile.getAbsolutePath(), ex);
throw new ServerException(
"Не загружен файл конфигурации " + paramFile.getAbsolutePath());
}
super.showBoard();
}
示例2: setPassword
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
public void setPassword() {
String content = passwordVar.getText();
if (passwordVisibility){
content = visPasswordVar.getText();
}
try {
WorldConfig.savePassword(content);
} catch (ConfigurationException e) {
e.printStackTrace();
}
loadedPassword = content;
log.debug("Done");
showPassword();
}
示例3: createPropertiesConfiguration
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
private static FileBasedConfiguration createPropertiesConfiguration(Reader reader)
throws ConfigurationException, IOException {
if (reader == null) {
throw new NullPointerException("reader: null");
}
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(new Parameters()
.properties()
.setListDelimiterHandler(new DefaultListDelimiterHandler(',')));
FileBasedConfiguration config = builder.getConfiguration();
config.read(reader);
return config;
}
示例4: createConfiguration
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
private static FileBasedConfiguration createConfiguration(Reader reader)
throws ConfigurationException {
if (reader == null) {
throw new NullPointerException("reader: null");
}
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class)
.configure(new Parameters().xml());
FileBasedConfiguration fileBasedConfiguration = builder.getConfiguration();
FileHandler handler = new FileHandler(fileBasedConfiguration);
handler.load(reader);
return fileBasedConfiguration;
}
示例5: test
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
@Test
public void test() throws ConfigurationException {
// Null input. (= Default value.)
assertEquals(VERSION.fetch(null), VERSION.getDefaultValue());
// Not found. (= Default value.)
Configuration conf = new MapConfiguration(new HashMap<>());
assertEquals(VERSION.fetch(conf), VERSION.getDefaultValue());
// Retrieved from properties. (Empty)
conf.setProperty(VERSION.getKey(), "");
assertNull(VERSION.fetch(conf));
// Retrieved from properties. (Configured)
conf.setProperty(VERSION.getKey(), "test");
assertEquals(VERSION.fetch(conf), "test");
}
示例6: createXmlConfiguration
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());
Parameters params = new Parameters();
FallbackBasePathLocationStrategy locationStrategy =
new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
.configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName)
.setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));
try {
XMLConfiguration xmlConfiguration = builder.getConfiguration();
return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
} catch (ConfigurationException e) {
throw new ConfigException(e);
}
}
示例7: makeCombinedConfiguration
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Ritorna una istanza di YadaConfiguration. Il progetto deve dichiarare la sua sottoclasse specifica in configuration.xml e fare un override
* di questo metodo per ritornare il tipo castato alla sottoclasse, oltre ad aggiungere @Bean
* @return
* @throws ConfigurationException
*/
protected void makeCombinedConfiguration(YadaConfiguration yadaConfiguration) throws ConfigurationException {
Parameters params = new Parameters();
ReloadingCombinedConfigurationBuilder builder = new ReloadingCombinedConfigurationBuilder()
.configure(
params.fileBased()
.setFile(new File("configuration.xml"))
);
yadaConfiguration.setBuilder(builder);
// yadaConfiguration.setConfiguration(ConfigurationUtils.unmodifiableConfiguration(builder.getConfiguration()));
// builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<Event>() {
// @Override
// public void onEvent(Event event) {
// builder.getReloadingController().checkForReloading(null);
//// try {
//// yadaConfiguration.setConfiguration(ConfigurationUtils.unmodifiableConfiguration(builder.getConfiguration()));
//// } catch (ConfigurationException e) {
//// log.error("Can't reload configuration (ignored)", e);
//// }
// }
// });
}
示例8: run
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
@Override
public void run() {
try {
try {
while (this.getStatus() == Status.OPEN && this.getSocket() != null) {
handleConnection();
}
} catch (final IOException | ConfigurationException e) {
this.logger.error(e.getMessage(), e);
}
} finally {
this.setStatus(Status.CLOSING);
this.close();
}
}
示例9: readIncomingStream
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Read and process the incoming stream.
*
* @throws IOException
* @throws XPathExpressionException
* @throws ConfigurationException
* @throws ParserConfigurationException
* @throws SAXException
*/
public void readIncomingStream() throws IOException, XPathExpressionException, ConfigurationException, ParserConfigurationException, SAXException {
this.setDataStream(null);
try {
while (this.getDataStream().write(this.getInputStream().read()) != -1) {
if (Arrays.equals(this.getDataStream().getTail(), this.getTerminator())) {
this.incrementMessagesReceivedCount();
break;
}
}
if (this.getDataStream().getLastByte() == -1) {
// The stream has ended so close all streams so that a new ServerSocket is opened and a new connection can be accepted.
this.close();
} else if (this.getDataStream().size() > 0) { // Ignore null (i.e. zero length) in order allow a probing ping e.g. paping.exe
this.processIncomingMessage();
}
responsesSent.addAll(sendResponses());
} catch (SocketTimeoutException e) {
// Do nothing. This occurs because a client was not closed and the read timeout on the locked stream (i.e. blocked thread) is 60 seconds.
this.logger.warn(e);
}
}
示例10: sendResponses
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
private List<ResponseDAO> sendResponses() throws XPathExpressionException, ConfigurationException, ParserConfigurationException, SAXException, IOException {
if (getIsResponses()) {
final String message = this.getDataStream().toString().substring(0, this.getDataStream().toString().length() - this.getDataStream().getTail().length);
Set<TCPClient> clients = getResponses().get(message);
if (clients != null) {
for (TCPClient tcpClient : clients) {
logger.debug("Sending responses from \"{}\".", tcpClient.toString());
responsesSent.addAll(tcpClient.sendResponses());
tcpClient.close();
}
}
}
return responsesSent;
}
示例11: getPorts
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Retrieve a unmodifiable set of server port numbers, to listen on, that are specified in the {@link #getFileName() configuration file}.
*
* @return an unmodifiable set of server port numbers specified in the {@link #getFileName() configuration file}
* @throws ConfigurationException error reading the configuration file
*/
public Set<Integer> getPorts() throws ConfigurationException {
try {
final String expression = "/configuration/server";
final XPath xPath = XPathFactory.newInstance().newXPath();
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = factory.newDocumentBuilder();
final Document document = builder.parse(getFileName().toString());
final NodeList portNodes = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET);
final Set<Integer> ports = new HashSet<>();
for (int i = 0; i < portNodes.getLength(); i++) {
final Node server = portNodes.item(i);
final String portValue = server.getAttributes().getNamedItem(PORT_ATTRIBUTE_NAME).getNodeValue();
final Integer port = Integer.parseInt(portValue);
ports.add(port);
}
return Collections.unmodifiableSet(ports);
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) {
throw new ConfigurationException(e);
}
}
示例12: getResponses
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Returns all of the responses specified for the {@link MockTCPServer} configured on the specified port.
*
* @param port of the {@link MockTCPServer} in question.
* @return The responses for the {@link MockTCPServer} running on the specified port.
* @throws ConfigurationException error reading the configuration file
*/
public Responses getResponses(int port) throws ConfigurationException {
final Responses responses = new Responses();
final NodeList incomingList = getIncomingMessages(port);
for (int incomingIndex = 0; incomingIndex <= incomingList.getLength() - 1; ++incomingIndex) {
final Node incoming = incomingList.item(incomingIndex);
final String incomingMessage = getIncomingMessage(incoming);
final Node responseList = getIncomingResponses(incoming);
for (int responseIndex = 0; responseIndex <= responseList.getChildNodes().getLength() - 1; ++responseIndex) {
final Node response = responseList.getChildNodes().item(responseIndex);
if (response.getNodeName().equals(RESPONSE_ELEMENT_NAME)) {
responses.add(incomingMessage, createResponseDAO(response));
}
}
}
return responses;
}
示例13: ack
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Server returns the expected ACK to a properly terminated message.
*
* @throws IOException see source documentation.
* @throws ConfigurationException error reading the configuration file
* @throws InterruptedException the MockTCPServer was unexpectedly interrupted
*/
@Test(timeout = TIMEOUT)
public void ack() throws IOException, ConfigurationException, InterruptedException {
final int totalClientsPerServer = 500;
// Start the client connections and send two messages from each one.
for (int i = 0; i < totalClientsPerServer; i++) {
clientList.add(clientList.size(), getClientFactory(TestConstants.MOCK_SERVER_PORT_1111));
assertArrayEquals(TestConstants.getAck(), clientList.get(clientList.size() - 1).send(TestConstants.WELLFORMED_XML_WITH_VALID_TERMINATOR).toByteArray());
assertArrayEquals(TestConstants.getAck(), clientList.get(clientList.size() - 1).send(TestConstants.WELLFORMED_XML_WITH_VALID_TERMINATOR).toByteArray());
clientList.add(clientList.size(), getClientFactory(TestConstants.MOCK_SERVER_PORT_2222));
assertArrayEquals(TestConstants.getAck(), clientList.get(clientList.size() - 1).send(TestConstants.WELLFORMED_XML_WITH_VALID_TERMINATOR).toByteArray());
assertArrayEquals(TestConstants.getAck(), clientList.get(clientList.size() - 1).send(TestConstants.WELLFORMED_XML_WITH_VALID_TERMINATOR).toByteArray());
}
// Confirm that each client is still open.
for (TCPClient tcpClient : clientList) {
assertTrue(tcpClient.isConectionActive());
}
this.checkLogMonitorForUnexpectedMessages();
}
示例14: expectSpecificMessage
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Having set the Server to expect only messages that match a specified Regular Expression, ensure that a NAK is returned for messages that do not match and an ACK for messages that do match.
*
* @throws IOException see source documentation.
* @throws InterruptedException
* @throws ConfigurationException
*/
@Test(timeout = TIMEOUT)
public void expectSpecificMessage() throws IOException, ConfigurationException, InterruptedException {
final String baseMessage = "Hello World!!";
final String message = String.format("%s%s", baseMessage, new String(TestConstants.DEFAULT_TERMINATOR));
// All messages sent to the Server must match this regular expression.
final String messageRegularExpression = String.format("%s%s", "Hello.*", new String(TestConstants.DEFAULT_TERMINATOR));
final String invalidMessage = String.format("%s%s", "This does not match the expected Regular Expression.",
new String(TestConstants.DEFAULT_TERMINATOR));
this.getServer().setExpectedMessage(messageRegularExpression);
assertArrayEquals(TestConstants.getAck(), this.getClient().send(message).toByteArray());
assertNull(this.getServer().getAssertionError());
assertArrayEquals(TestConstants.getNak(), this.getClient().send(invalidMessage).toByteArray());
assertNotNull(this.getServer().getAssertionError());
this.checkLogMonitorForUnexpectedMessages();
}
示例15: startup
import org.apache.commons.configuration2.ex.ConfigurationException; //导入依赖的package包/类
/**
* Bootstrap multiple servers using details from the configuration file.
*
* @throws ConfigurationException error reading the configuration file
* @throws InterruptedException the MockTCPServer was unexpectedly interrupted
* @throws IOException error while sending responses
*/
@Test(timeout = TestConstants.TEST_TIMEOUT_5_MINUTE)
public void startup() throws ConfigurationException, InterruptedException, IOException {
try (final Bootstrap bootstrap = new Bootstrap();) {
bootstrap.startup();
final List<String> expectedMessages = new ArrayList<>(Arrays.asList(StringEscapeUtils.unescapeJava(TestConstants.MACHINE_A_RESPONSE_MESSAGE), StringEscapeUtils.unescapeJava(TestConstants.MACHINE_B_RESPONSE_MESSAGE)));
testResponses(bootstrap.getServerPool().get(TestConstants.MOCK_SERVER_PORT_1234), TestConstants.MOCK_SERVER_PORT_2345, TestConstants.INCOMING_MESSAGE_ONE + TestConstants.DEFAULT_TERMINATOR, expectedMessages, TestConstants.SERVER_TIMEOUT, TestConstants.ONE_TENTH_OF_A_SECOND);
checkLogMonitorForUnexpectedMessages();
testResponses(bootstrap.getServerPool().get(TestConstants.MOCK_SERVER_PORT_6789), TestConstants.MOCK_SERVER_PORT_5678, TestConstants.WELLFORMED_XML_WITH_VALID_TERMINATOR, expectedMessages, TestConstants.SERVER_TIMEOUT, TestConstants.ONE_TENTH_OF_A_SECOND);
checkLogMonitorForUnexpectedMessages();
bootstrap.shutdown();
}
}