How do I get a specific dependency with grab? - groovy

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.

Related

Grab does not download dependency in soap ui

I am trying to download a dependency via #Grab in SOAP UI, running the below script
#Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv
def csv = '''Name,Lastname
Mark,Andersson
Pete,Hansen'''
def data = parseCsv(csv)
for(line in data) {
println "$line.Name $line.Lastname"
}
I am getting this error
Here are the JAR's I am using in SOAP UI ext folder
What is the problem and how do you fix this so that Grab downloads the dependencies.
Groovy Version: 4.0.6

setting micronaut configuration location

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

Conditional import/export when using different environment

I'm currently developing a Lambda function using node14 on AWS, but I have an issue when I want to develop it locally.
In my dev environment I have a corporate proxy needed to connect to AWS. In this case, I use aws-sdk-proxy library. However, I don't want to use this package while in production (as Lambda already has the aws-sdk injected in lambda core).
So, I created this snippet to perform the switch between the 2 environments:
// aws.js
import AWSPROD from 'aws-sdk'
import AWSDEV from 'aws-sdk-proxy'
import config from '../lib/Config.js'
import logger from './logger.js'
let AWS = null
if (config.get('ENVIRONMENT') === 'dev') {
logger.debug('[DEV] Using aws-sdk-proxy')
AWS = AWSDEV
} else {
AWS = AWSPROD
}
export default AWS
Not so clean, but it works. With this code, I can perform this:
import AWS from './aws.js'
Now the problem is that this code implies that I must provide aws-sdk-proxy into the "prod" dependencies of my package.json.
I think it breaks performance of the lambda as the code raised 9Mo (2Mo without), but I wish to keep this way of calling "AWS" SDK [the 2d code block].
I tried to use required or dynamic import but none of these solutions work.
Do you have any advice to improve my code?
PS:
The code is transpiled to ES5 using Babel to fit Lambda requirements
aws-sdk-proxy library must stay in devDependencies as it's a dev dependency

Import org.openntf cannot be resolved

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

Azure Functions use import instead of require

What is the configuration requirements to use import instead of require?
I'm using function runtime v2.
I tried upgrading node to v10.12.0 but still get this error when it hits the imports
Worker was unable to load function store: 'SyntaxError: Unexpected token {'
I have node version set to 10.12.0 in local.settings and in package.json.
my function is setup like this ...
module.exports = async function(context, queueMessage) {
import { cosmos } from "#azure/cosmos";
import { updateChat } from "./channels/chat/newChatMessage";
import { updateAttributeStatus } from
"./channels/attribute/updateAttributeStatus";
import { documentRequest } from "./channels/document/documentRequest";
...
Which version of node is supported by Azure Functions and is import supported? If so, how do I set it up?
Thanks,
Donnie
According to the docs these versions are supported for V2:
Active LTS and Current Node.js versions (8.11.1 and 10.6.0
recommended). Set the version by using the
WEBSITE_NODE_DEFAULT_VERSION app setting.
So the node version has to be set in the Application Settings as explained here.
Regarding the use of import vs require, this is still an experimental feature in Node, therefore I don't think it's possible to use this in Azure Functions yet.
I'd probably go with TypeScript instead and transpile it before uploading (you can find some examples on how to get started with that on GitHub).

Resources