How to set the Web application context in Thorntail? - thorntail

I'm looking for a way to customize the Web application name (so to change the Web context accordingly) in Thorntail. I assume that it can be done through the thorntail's maven plugin but I cannot find which is the property to set for it.
Thanks

By default, the context is /, which should be what you want most of the time. To customize it, you can use one of the following options:
1) Pass the thorntail.context.path system property when starting the uberjar: java -jar my-app-thorntail.jar -Dthorntail.context.path=my-context.
2) If you use project-defaults.yml, you can configure it there:
thorntail:
context:
path: my-context
3) Create a file WEB-INF/jboss-web.xml with this content:
<jboss-web>
<context-root>my-context</context-root>
</jboss-web>
(Under the hood, options 1 and 2 are actually transformed to 3, but you don't have to care.)

Related

Spring application war - Google App Engine - How to specify Log location, profile, environment variab;les

I have a spring boot application bundled as war file , and able to push to App Engine
But I am getting problems starting app (I suspect there could be an issue with DB too...but couldnt remember where I saw...a nightmare)
java.lang.RuntimeException: java.lang.IllegalStateException: Logback
configuration error detected: ERROR in
ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Failed to
create parent directories for
[/base/data/home/apps/e~pemy/20210716t001812.436581063072799646/logs/pynew.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] -
openFile(logs/pynew.log,true) call failed.
java.io.FileNotFoundException: logs/pynew.log (No such file or
directory)
I am using the below properties in my application props
> logging.file.path=logs
> logging.file.name=${logging.file.path}/pynew.log
I am finding it very hard to include google specific dependencies and properties , and making a mess of my project...created app.yaml, web-inf>> appengine-web xml, logging.properties (not sure why but added as told in a tutorial)
Question: How can I create parent directory or link to cloud storage folder etc?
I also want to specify a profile and I see I can do it in yaml file. Is this used only
env_variables:
JAVA_USER_OPTS: '-Dspring.profiles.active=prod'
But I would like to know how to connect to Cloud SQL
spring.datasource.url=jdbc:mysql:///mydb?cloudSqlInstance=myapp:europe-west2:dBinstancename&socketFactory=com.google.cloud.sql.mysql.SocketFactory
spring.datasource.username=${dbuser}
spring.datasource.password=ENC(${dbencpwd})
spring.cloud.gcp.sql.database-name=mydb
spring.cloud.gcp.sql.instance-connection-name=myapp:europe-west2:dBinstancename
It is so confusing that I keep forgetting which connection needs password and which wont. and keep breaking my local
Question
Assuming that I need to supply credentials, How can I supply - ${dbuser}
I used the default spring logger with logback-spring.xml for all my development, and this is not working on AppEngine
So I followed https://cloud.google.com/logging/docs/setup/java
and added logback.xml and the dependency
implementation 'com.google.cloud:google-cloud-logging-logback:0.121.3-alpha'

Loading multiple config file from spring cloud config server

Hey I got to know how to check properties in config server i.e. http://{Config server URL}:{Port}/{ServiceID}/{Profile}
Right now I am facing a problem where I've to read multiple properties file from cloud config server. Ex: Right now I've to read properties file(huge file) from a single property file i.e. employee.properties
I don't want huge list of properties file in single folder. like
employee-dev.properties
employee-dit.properties
employee-sit.properties
employee-uat.properties
employee-preprod.properties
employee-prod.properties
customers-dev.properties
customers-dit.properties
customers-sit.properties
customers-uat.properties
customers-preprod.properties
customers-prod.properties
.
.
.
and soo on.
My requirement is I need to maitain a list of properties file and config server will provide me these values. like :
**{env}/employee.properties**
**{env}/customers.properties**
Here env could be any environment like dit, sit, prod etc.
Hope I'll get answer here.
If you don't want to have all properties files in an only folder, so you need to add this configuration on config server properties file.
1. Match all options
spring.cloud.config.server.native.searchLocations = [classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]
2. Match only /application-name/application-name-profile.properties
spring.cloud.config.server.native.searchLocations = classpath:config/{application}
Then you'll have matched based on application name folder for example.
resources/config/application-name/application-name-properties.

How can/do I configure my Spring app to check a specific tag of configs with custom directory?

Suppose I have the following dir:
root.properties
dev-ci
common.properties
app_dir
app.properties
prod
stage
test
test/stage/prod all follow dev-ci's dir/path structure.
How can I setup my bootstrap.yml file so that when I start my app, it'll load the following:
root.properties
dev-ci/common.properties
dev-ci/app_dir/app.properties
Is there a way to set up my yml so that it takes some parameter from commandline? Or will I have to map out all the possible 'paths' then pass in some label/name?
Lastly, where does the tag name come into play?

How to change bundle start level in glassfish 3.1.2 equinox?

I want to change the start level for a bundle in my glassfish. I used equinox as osgi runtime.
I changed the configuration file glassfish\config\osgi.properties and add the folowing line:
osgi.bundles=bundlesymbolicname#5:start
When I connect via telnet and search the bundle with "lb bundleid" I see in the level column 1 instead of 5.
Can anyone help me? What is the problem with my configuration?
Thanks Marco.
You can change in in ${GF_HONE}/glassfish/config/osgi.properties, by update the below item:
# What should be the initial start level of framework.
# For performance reason, initially we set the start level to 1 so that no optional
# bundles can get activated while server is still starting. Once server is started,
# the framework's start level is set to whatever is configured in glassfish.osgi.start.level.final property.
org.osgi.framework.startlevel.beginning=1
# Set bundle start level to be same or less than that of framework,
# otherwise HK2 installed bundles won't be activated.
# See issue #5934
felix.startlevel.bundle=1

Embedded Glassfish v3: deploying sun-resources.xml programmatically fails

I would like to be able to package my jpa-ejb-web project as a standalone application, by using Glassfish embedded API.
To use the JPA layer, I need to deploy the sun-resource.xml configuration, which should be possible with the asadmin command add-resources path\to\sun-resources.xml. I've this code to do it:
String command = "add-resources";
ParameterMap params = new ParameterMap();
params.add("", "...\sun-resources.xml" );
CommandRunner runner = server.getHabitat().getComponent(CommandRunner.class);
ActionReport report = server.getHabitat().getComponent(ActionReport.class);
runner.getCommandInvocation(command, report).parameters(params).execute();
but Glassfish refuses it with:
15-Jul-2010 16:34:12 org.glassfish.admin.cli.resources.AddResources execute
SEVERE: Something went wrong in add-resources
java.lang.Exception: ...\gfembed6930201441546233570tmp\lib\dtds\sun-resources_1_4.dtd (The system cannot find the path specified)
at org.glassfish.admin.cli.resources.ResourcesXMLParser.initProperties(ResourcesXMLParser.java:163)
at org.glassfish.admin.cli.resources.ResourcesXMLParser.<init>(ResourcesXMLParser.java:109)
at org.glassfish.admin.cli.resources.ResourcesManager.createResources(ResourcesManager.java:67)
at org.glassfish.admin.cli.resources.AddResources.execute(AddResources.java:106)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
at javaapplication4.Main.main(Main.java:55)
and indeed, there is no lib directory on the indicated path ...
is there something wrong in my code? (I use glassfish-embedded-all-3.0.1.jar)
Thanks
I solved it by specifying an Embedded File System for the embedded Glassfish, and prepopulated the /path/to/my/glassfish/lib/dtds folder with the files which were missing.
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
efsb.autoDelete(false);
efsb.installRoot(new File("/path/to/my/glassfish"), true);
EmbeddedFileSystem efs = efsb.build();
Server.Builder builder = new Server.Builder("test");
builder.embeddedFileSystem(efs);
builder.logger(true);
Server server = builder.build();
server.addContainer(ContainerBuilder.Type.all);
server.start();
and asking Glassfish not to delete the folder at the end of the execution.
I'm not sure this is possible, Running asadmin Commands Using the Sun GlassFish Embedded Server API doesn't mention such a use case (passing a sun-resources.xml).
But I would use a preconfigured domain.xml instead of trying to deploy a sun-resource.xml file, the result should be similar. From the Sun GlassFish Enterprise Server v3 Embedded Server Guide:
Using an Existing domain.xml File
Using an existing domain.xml file
avoids the need to configure embedded
Enterprise Server programmatically in
your application. Your application
obtains domain configuration data from
an existing domain.xml file. You can
create this file by using the
administrative interfaces of an
installation of nonembedded Enterprise
Server. To specify an existing
domain.xml file, invoke the
installRoot, instanceRoot, or
configurationFile method of the
EmbeddedFileSystem.Builder class or
a combination of these methods.
The documentation provides code samples showing how to do this (should be pretty straightforward).

Resources