I have an existing groovy micronaut app I'm trying to change where it loads its config from. I don't understand what code to write so I can set the location of the micronaut configuration. I know you can use micronaut.config.files system variable or MICRONAUT_CONFIG_FILES environment variable, but this is a terrible idea because micronaut is built into grails and therefore every grails app you have running in tomcat will pick up the same config and crash.
Nor do I know where in the code to set the config file. There's an Application class with a run() method, but I don't know if this is only called during development, or whether it gets called when deploying in Tomcat. When setting the config in a Grails app, there is an Application class extending EnvironmentAware, and you can override setEnvironment, and load external configs there, but there is no hint of that for micronaut apps.
The micronaut doco says it can load a configuration from "application.{extension}", but it doesn't say what "application" is, or what directory it expects that in, or whether you can change the directory. Is "application" the value of micronaut.application.name in one's application.yml? I couldn't seem to get it to load based on that.
Then the documentation talks about loading from a PropertySource, which is fine and all, but doesn't tell you where you can put that code to load from a PropertySource. There is mention you can pass the PropertySource to ApplicationContext.run(xx), but in this app I inherited, there is no mention of ApplicationContext, and the micronaut documentation isn't very clear what I'm supposed to do with ApplicationContext. This app I've inherited has an Application class with a main() calling Micronaut.run() which apparently returns an ApplicationContext, but it's not clear if main() is called when running in Tomcat, or whether I should be calling run() on that, when it works as is, and I'm just trying to change where it loads its config.
The question is, how do I get my micronaut app to load its config from
where I tell it to, and not from micronaut.config.file system variable
location.
I don't think we have a specific feature in the framework that allows you to tell the framework to ignore micronaut.config.files. If you would like such a feature you can request it at https://github.com/micronaut-projects/micronaut-core/issues. If that is of interest I suggest you open it up for discussion at https://github.com/micronaut-projects/micronaut-core/discussions first.
You can load external config files, from a path not set as micronaut.config.files, in the main method of the Application class before running the application. Take a look at below class which accepts a config folder location as a system property demo.config.path(can be something else) and loads yaml config files from that folder:
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import io.micronaut.context.env.PropertySource;
import io.micronaut.context.env.yaml.YamlPropertySourceLoader;
import io.micronaut.core.io.ResourceLoader;
import io.micronaut.core.io.file.DefaultFileSystemResourceLoader;
import io.micronaut.runtime.Micronaut;
public class Application {
private static final String PROP_CONFIG_LOCATION = "demo.config.path";
public static void main(String[] args) throws IOException {
if (System.getProperty(PROP_CONFIG_LOCATION) != null) {
List<PropertySource> propertySources = new ArrayList<>();
YamlPropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader();
ResourceLoader resourceLoader = new DefaultFileSystemResourceLoader();
Files.newDirectoryStream(Paths.get(System.getProperty(PROP_CONFIG_LOCATION))).forEach(file -> {
String fileName = file.toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
propertySourceLoader.load(fileNameWithoutExtension, resourceLoader).ifPresent(propertySources::add);
});
Micronaut.build(args)
.classes(Application.class)
.propertySources(propertySources.toArray(new PropertySource[1]))
.start();
} else {
Micronaut.run(Application.class, args);
}
}
}
As is, this code works for yaml config files(with snakeyaml in classpath). With minor changes, it can be made to work for properties files and to read config location from environment variable instead of system property. Full sample application present in github
I've followed the official documentation in order to create my own occaddon webservice layer : https://help.sap.com/viewer/e5d7cec9064f453b84235dc582b886da/1905/en-US/8b96a80f8669101482d4f3c1e27b4eb6.html and created the "dummy" controller :
package org.training.trainingoccaddon.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
#Controller
#RequestMapping(value = "/{baseSiteId}/newResource")
public class ExtendedCustomersController {
#RequestMapping(method = RequestMethod.GET)
#ResponseBody
public String getNewResource() {
return "newSampleResource";
}
}
However, when I try to access to
https://localhost:9002/rest/v2/{baseSiteId}/newResource
It redirects me to hac.
I've created my new occ addon
added to localextensions.xml
Performed ant addoninstall -Daddonnames="occaddon" -DaddonStorefront.ycommercewebservices="ycommercewebservices"
Rebuit the application with ant clean all && hybrisserver debug
But It doesn't work. Am I missing something?
Also, how can I setup swagger?
I am assuming you are using SAP Commerce 1905, also that you not have added any custom 'ycommercewebservices' extension.
Missing ycommercewebservices extension
Since you are redirected to the HAC your 'ycommercewebservices' extension is not loaded correctly. Normally it should throw an error from the 'ycommercewebservices' extension itself instead of redirecting to the HAC.
The extension should be at least present in the 'localextension.xml'.
You can verify loaded extensions in the HAC
e.g. https://localhost:9002/platform/extensions
The next thing you could check if your addon was added as dependency in the 'ycommercewebservices' extension by checking the 'extensioninfo.xml' in its directory. Also double check if a 'project.properties' file was generated in your custom occaddon extension. If something is wrong here you should review your 'ant addoninstall' command.
Swagger Setup
Swagger works out of the box and you can decorate your classes with the annotations as documented on here https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X.
You can visit the swagger ui on the ycommercewebservices extension
e.g. https://localhost:9002/rest/v2/swagger-ui.html
I have a Notes V11.0.1 designer client and configured a widget that imports the latest OpenNTF Domino API (downloaded from OpenNTF website) through an update site.
The plug-in is loaded in the designer
I created a new application and added the library to XSP Properties.
But when I create a simple Java class and want to import org.openntf.domino.*, I get an error:
package test;
import org.openntf.domino.*;
public class Test {
public static void test() {
Session session = null;
}
}
Error: the import org.openntf cannot be resolved.
Building the app does not solve the problem.
In the MANIFESST.MF I get the following error
Any idea why this goes wrong?
It's most likely that the default Target Platform in 9.0.1FP10 and newer (11.0.1 included) is broken: https://frostillic.us/blog/posts/2018/10/19/058650e080e352178525832b00519d2c
Im using the AWS SDK:
#Grab(group='com.amazonaws', module='aws-java-sdk-elasticbeanstalk', version='1.11.232')
import com.amazonaws.regions.Regions
import com.amazonaws.services.elasticbeanstalk.*
import com.amazonaws.services.elasticbeanstalk.model.DescribeEnvironmentsRequest
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider
class testAws {
static Object test (){
def awsCreds = new BasicAWSCredentials('sdfsdfdf', 'sdfsdfdsf')
def ebClient = new AWSElasticBeanstalkClientBuilder()
.withRegion(Regions.valueOf('US-EAST-1'))
.withCredentials(new AWSStaticCredentialsProvider (awsCreds))
.build()
ebClient.describeEnvironments(
new DescribeEnvironmentsRequest().withEnvironmentNames('zzzzz')
).getEnvironments()
}
}
I get this error:
Caught: java.lang.NoSuchMethodError: `org.apache.http.conn.ssl.SSLConnectionSocketFactory.<init>(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/HostnameVerifier;)V`
Doing some googling i found the aws sdk depends on a specific version of the http library. If this was a java project I would define that specific version in my pom or gradle config. How do I do this with grab?
To be clear I dont need to grab http explicitly because it gets pulled in as a dependency of the aws sdk. The problem is I have a different (newer) version installed locally. Even if I explicitly grab the older version it still throws this error. If I uninstall the new version from my system it works. But I want to enforce this in groovy and not have to modify local environemnt.
I am new to Jenkins, TFS and Groovy Script, but I have been researching and not found the exact way to do the following:
I would like to generate a list of all the Jenkins CI projects along with their TFS Project Path since the naming at my current company has been very inconsistent and I can't find which project in Jenkins CI correlates to which project in TFS without manually examining the project path in Jenkins.
I tried this, but it blows up since getProjectPath() isn't a method in Hudson.model.*
import hudson.model.*
jenkins = Hudson.instance
for (item in jenkins.items)
{
println item.getFullDisplayName()
println item.getProjectPath()
}
Any guidance would be appreciated. Thanks!
TFS's configuration located under SCM (Source Control Management) configuration section. To access it at first you need to get SCM with getScm() method:
import hudson.model.*
import hudson.plugins.tfs.TeamFoundationServerScm
jenkins = Hudson.instance
for (item in jenkins.items)
{
scm = item.getScm()
if (scm instanceof TeamFoundationServerScm) {
println item.getFullDisplayName()
println scm.getProjectPath()
}
}