I am trying to put mappings json files in a subdirectories due to different requirements based on diff profiles.
I have it working with default /mappings directory and all mappings work ok in postman.
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources”
src/main/resources
-mappings
—folderA
—folderB
—folderC
But once I try to place json files under sub directory of “mappings” folder, no mappings get picked up and /__admin/mappings endpoint show a total of 0.
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources**/mappings/aws**”
(Note the path difference)
I am just wondering if mappings folder subdirectories are even supported in wire mock or have I configured something incorrectly? It seems something too simple to be not supported by wiremock!
Many thanks
I have fixed it but for anyone facing similar problem u need to make “mappings” subdirectory of your custom folders.
src/main/resources
-my_wiremock_mappings
—folderA
—— mappings (should contain json files)
—folderB
—— mappings
—folderC
—— mappings
WiremockConfiguration options = options()
.usingFilesUnderDirectory(System.getPtoperty(“user.dir”) + “/app/src/main/resources/my_wiremock_mappings/folderA”
There is no need to add “mappings” to the path.
If you use a classpath ant pattern, you have to add *.json at the end.
#AutoConfigureWireMock(port = 8081, stubs = "classpath:/stubs/**/*.json")
https://github.com/spring-cloud/spring-cloud-contract/blob/main/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/WireMockConfiguration.java#L213
Related
Fairly new to Wicket so excuse my ignorance.
I have a Wicket app...starts with WicketApplication.class I have a WicketApplication.properties file to load some values. The properties file sits next to the class file (same package). Works fine, no issues.
Now, I would like to move the properties file outside the application WAR/JAR. Exported the app as a WAR to run on Tomcat. I have create a a folder called properties under tomcat root & moved WicketApplication.properties to this directory. Added the following to init() method in WicketApplication.class...
String realPath = getServletContext().getRealPath("/");
realPath = realPath.replaceAll("\\\\", "/");
if (realPath.toUpperCase().indexOf("WEBAPPS") != -1) {
String newRes = realPath.substring(0, realPath.toUpperCase().indexOf("WEBAPPS") -1);
System.out.println (newRes + "/properties");
getResourceSettings().getResourceFinders().add(new Path( newRes + "/properties"));
}
I get an exception thrown.
How do I "externalise" the properties file?
Also, if I could take one step further, how do I map a properties file name to class name..it, myapplication.properties -> WicketApplication.class
Thanks in advance.
You need to add new IStringResourceLoader with application.getResourceSettings().getStringResourceLoaders().add(...).
See https://github.com/apache/wicket/blob/515e2be2a5301f5caf7b1baee4a593d21c20e275/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java#L220-L224 for the default ones.
IResourceFinder should be used when you want to add custom location for your HTML files.
There is no way to map myapplication.properties to WicketApplication.class. By adding an additional IStringResourceLoader you just tell Wicket to search in yet another place.
Read multiple message resources having same/different name, under different packages, in a jar in on go?
let's suppose my jar xyz.jar structure is as follow:
project structure:
src|main|resources
|pkg1|message1.properties
|pkg2|message2.properties
...
|pkg3|message1.properties
These resources under different packages are being generated dynamically through maven goals. What I want here, load all resource bundles and maintain at single place along with package name. I don't want to hard code these packages in my code, even don't want to change my code when new files are being added dynamically.
Any help, much appreciated!
Thanks
If locating these property files dynamically is what you need, you can use apache.commons.io FileUtils for that.
String[] s = {"properties"};
File f = new File(getClass().getClassLoader().getResource("./").getFile());
Collection<File> o = FileUtils.listFiles(f, s, true);
for (File file : o) {
System.out.println(file.getAbsolutePath());
}
And you can move files to the required location with Files.move method.
I am making a JTree that loads files and folder of a FTP Server, using (Apache Commons).
I use this method to load files of a specific directory:
FTPFile[] innerFiles = ftp.listFiles();
I noticed that for any directory, innerFiles [0] is . and innerFiles [1] is ..
It is easy to ignore them by start looking from innerFiles[2], but I just want to know what are these reserved items for and would it make any problem in case of ignoring them?
Those files represent the current directory (.) and the directory above it (..). You should ignore these when creating a tree structure showing all the files and directories.
You could specify a FTPFileFilter that strips these out.
You can just ignore them. Here is an implementation of listing all the actual files, disregarding the two dot ones:
ftp.listFiles(remoteFilePath, file ->
{
val filePath = file.getName();
return !(filePath.equals(".") || filePath.equals(".."));
});
This seems more proper than starting with index 2.
Does someone knows a way to export a hazelcast config to a file?
I know for importing it, there are following ways:
hazelcast.config system property
hazelcast.xml file in the working directory
hazelcast.xml on the classpath
hazelcast-default.xml that comes with hazelcast.jar
But what can I do, if I want to save the actual config as xml. Perhaps for backup purposes. How can I do this?
I'm not aware of a configuration exporter but there is getter methods on Hazaelcast configuration class com.hazelcast.config.Config. You can use them to extract the configuration for you maps, lists, multimaps, groups, etc. For instance:
Map<String, ListConfig> listConfigs = config.getListConfigs();
for(ListConfig listConfig = listConfigs.values()) {
// export the configuration to an output file
System.out.println("List: " + listConfig.getName()+" has max size: "+listConfig.getMaxSize());
}
I'm trying to deploy restSQL in my local tomcat installation based on this link.
From my tomcat webapps folder:
webapps\restsql-0.8\WEB-INF\classes\resources\properties
I have modified 'default-restsql.properties' to set the correct database connections
and retained the property 'sqlresources.dir=/resources/xml/sqlresources' while adding/creating the folder on that location.
I also modified in web.xml:
<context-param>
<param-name>org.restsql.properties</param-name>
<param-value>/WEB-INF/resources/properties/default-restsql.properties</param-value>
</context-param>
I'm quite sure that the default.restsql.properties is loaded since when I access this resource:
http://localhost:8080/restsql-0.8/conf
I get this response:
Properties loaded from /resources/properties/default-restsql.properties:
log4j.configuration = resources/properties/default-log4j.properties
org.restsql.security.Authorizer = org.restsql.security.impl.AuthorizerImpl
org.restsql.core.RequestLogger = org.restsql.core.impl.RequestLoggerImpl
**sqlresources.dir = /resources/xml/sqlresources**
database.driverClassName = com.mysql.jdbc.Driver
logging.config = resources/properties/default-log4j.properties
database.user = root
org.restsql.core.Factory.ResponseSerializerFactory = org.restsql.core.impl.ResponseSerializerFactoryImpl
org.restsql.core.SqlBuilder = org.restsql.core.impl.SqlBuilderImpl
database.password = root
org.restsql.core.Factory.ConnectionFactory = org.restsql.core.impl.ConnectionFactoryImpl
org.restsql.core.SqlResourceMetaData = org.restsql.core.impl.SqlResourceMetaDataMySql
org.restsql.core.HttpRequestAttributes = org.restsql.core.impl.HttpRequestAttributesImpl
logging.facility = log4j
response.useXmlSchema = false
org.restsql.core.Factory.RequestFactory = org.restsql.core.impl.RequestFactoryImpl
database.url = jdbc:mysql://localhost:3306/
logging.dir = /var/log/restsql
org.restsql.core.Factory.SqlResourceFactory = org.restsql.core.impl.SqlResourceFactoryImpl
request.useXmlSchema = false
response.useXmlDirective = false
org.restsql.core.Factory.RequestDeserializerFactory = org.restsql.core.impl.RequestDeserializerFactoryImpl
Properties using defaults:
org.restsql.core.Factory.Connection = org.restsql.core.impl.ConnectionFactoryImpl
java.util.logging.config.file = resources/properties/default-logging.properties
request.useXmlDirective = false
org.restsql.properties = /resources/properties/default-restsql.properties
However when I access this resources
http://localhost:8080/restsql-0.8/res/
I get this response:
SQL Resources directory /resources/xml/sqlresources does not exist ... please
correct your sqlresources.dir property in your restsql.properties file
Although the folder do exist: webapps\restsql-0.8\WEB-INF\classes\resources\xml\sqlresources
What could be the problem?
Sorry you're having trouble with deployment. restSQL requires an absolute path to the main properties file. It does not have the capability to search its WAR file or exploded web app dir, other than look in the classpath for the default.
Most paths are to other files, referenced in the main restSQL properties files have to be absolute. The only one that is relative is the logging.config. Please have a look at Deployment for all the nitty-gritty deployment instructions.
Hope that does the trick for you.
When it rains it pours?
Sounds like you had trouble running one of the database create scripts? Is that in restsql-sdk/WebContent/database/postgresql? Did you have errors running create-sakila.bat? Perhaps your psql executable is not in your path. You can edit the file to add it to your PATH environment variable temporarily.
You won't get any 5xx errors if the resource query returns no data. You will get a 200 with an empty readResponse document.
Your problem is likely a resource definition metadata issue. Is country_id from the country table? Is country defined as a table in the metadata? Can you post the resource definition?
Have you looked over the SQL resource rules at http://restsql.org/doc/SqlResourceRules.html? Sorry, SQL Functions and views are not allowed. You must use plain old columns and tables.