vertx build with graalvm - vert.x

I fallowed https://github.com/vertx-howtos/graal-native-image-howto/blob/20.3.0/README.adoc and manage to build my vertx project with graalvm, but when I start the native image vertx is not starting. I can not see vertx logs, "listening on..."
You can see my full pom here
And java code here

Adding some error handling to the application will show that the 1st problem is related to missing the file application.properties from the image, this can be fixed by updating the native-image.properties config with:
-H:IncludeResources=.*\\.properties
Then the application will start but again will fail to return data. This is because the application is using jackson databind (which relies on reflection) to encode the POJO to JSON.
Fixing it requires some understanding on how jackson reflection works and write the correct configuration, or just keep it simple and use Vert.x built in JSON types, for example:
req.response()
.putHeader("content-type", "application/json")
.end(new JsonObject()
.put("name", "vertx")
.put("releaseYear", LocalDate.now().getYear())
.encode());

Related

How to read external config file when starting a bundle jboss fuse karaf

The problem is simple: i want to print all topics from apache kafka after installing kafka module on karaf. I need to get properties from cfg file which is located in jbossfuse/etc and create a KafkaConsumer object. I want to implement BundleActivator to be able to start method in the moment of installation module.
The question is: how can i get properties from the config file?
I found some solution here: some solution, they said " you can use ConfigAdimn service from OSGi spec. ". How can i use it? All examples with the code are welcome
Karaf uses Felix-FileInstall to read config files: http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html
So if there is a file named kafka.cfg, it will pick it up and register a config with the ConfigAdmin-Service under the pid 'kafka'.
You can fetch the ConfigAdmin-Service and fetch the config using an Activator and read that config from there, but I strongly recommend to use DeclarativeServices or Blueprint instead to interact with the OSGi-Framework, both support injection of configuration if it is available.
Because otherwise you have to deal yourself with the following topics:
there is no ConfigAdmin (yet), maybe because your bundle starts earlier)
the ConfigAdmin changes (for example due to a package refresh or update)
the configuration is not yet registered (because felix has not read it yet)
the configuration gets updated (for example somone changes the file)

JAI can't execute in native spark - only in sbt and as a separate scala function

I want to use a library (JAI) with spark to parse some spatial raster files. Unfortunately, there are some strange issues. JAI only works when running via the build tool i.e. sbt run when executed in spark.
When executed via spark-submit the error is:
java.lang.IllegalArgumentException: The input argument(s) may not be null.
at javax.media.jai.ParameterBlockJAI.getDefaultMode(ParameterBlockJAI.java:136)
at javax.media.jai.ParameterBlockJAI.<init>(ParameterBlockJAI.java:157)
at javax.media.jai.ParameterBlockJAI.<init>(ParameterBlockJAI.java:178)
at org.geotools.process.raster.PolygonExtractionProcess.execute(PolygonExtractionProcess.java:171)
Which looks like some native dependency is not called correctly.
Assuming something is wrong with the class path I tried to run a plain java/scala function. but this one works just fine.
In fact, the exact same problem occurs when Nifi is calling the parse function.
Is spark messing with the class paths? What is different from running the jar natively via java-jar or through spark or NiFi? Both show the same problem even when concurrency is disabled and they run only on a single thread.
JAI vendorname == null is somewhat similar as it shows what can go wrong when running a jar with JAI. I could not identify this as the exact same problem though.
I created a minimal example here:
https://github.com/geoHeil/jai-packaging-problem
Due to the dependency on the build process & packaging of native libraries I think it will not be possible to include snippets directly in this posting.
edit
I am pretty convinced this has to do the the assembly merge strategy, so far I could not find one which works.
Below you can see that the Vectorize operation is missing on sparks class path
edit 2
I think spark / NiFis class loader will not load some of the required registry files for JAI. A plain java app works fine with these assembly/ fat-jar settings.

java.lang.NoSuchFieldError returns when trying to create a stateless session to the Rules Execution Server

I am using Ilog JRules Studio 7.1.1 for the rules development. I am using JUnit test cases to test the developed rules.
When i am trying to create a stateless session to the RES, it's returning with the below error.
IlrStatelessSession session = factory.createStatelessSession();
Anyone is having any idea?
java.lang.NoSuchFieldError: ilog/rules/res/decisionservice/plugin/IlrWsdlGenerationInteractionSpec.FUNCTION_NAME_BACKPORT_GENERATE_WSDL
at ilog.rules.res.decisionservice.plugin.IlrWsdlGeneratorInteractionExtension.getSupportedFunctionNames(IlrWsdlGeneratorInteractionExtension.java:418)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.createPlugins(IlrPluginManager.java:222)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.changePlugins(IlrPluginManager.java:173)
at ilog.rules.res.xu.plugin.impl.IlrPluginManager.start(IlrPluginManager.java:135)
at ilog.rules.res.xu.spi.IlrManagedXUConnectionFactory.createConnectionFactory(IlrManagedXUConnectionFactory.java:648)
at ilog.rules.res.xu.spi.IlrManagedXUConnectionFactory.createConnectionFactory(IlrManagedXUConnectionFactory.java:668)
at ilog.rules.res.session.util.IlrJ2SEConnectionFactoryFinder.findConnectionFactory(IlrJ2SEConnectionFactoryFinder.java:23)
at ilog.rules.res.session.IlrJ2SESessionFactory.createClientFactory(IlrJ2SESessionFactory.java:93)
at ilog.rules.res.session.IlrJ2SESessionFactory.getClientFactory(IlrJ2SESessionFactory.java:129)
at ilog.rules.res.session.IlrJ2SESessionFactory.createStatelessSession(IlrJ2SESessionFactory.java:62)
Regards,
Hari
Nothing to do with the session.
JRules is crashing because it is not able to generate the WSDL, meaning there is something wrong with your project at first.
Try to run it locally first.
The thing is a web service is automatically provided if the XOM is based on XSD
There is an error somewhere in your project. If you use XSD (which I guess) then have a look to your rule project.
If you use JAVA XOM then there is an error in your web service server (which I doubt) because I cannot see why JRules would complain for your own code.
Verify your in/output parameters
Make it simple first then complicate the process.If simple then redeploy...
Hope it helps

GWT logging to file

I am writing my first GWT and i confess i have no idea how to set up loggers.
I am deploying the application to tomcat and want to be able to set up a logger so that i can log to a file in $catalina.home. Gwt came with logging.properties for a java util style log and log4j.properties; i have looked at documentation for the gwt java util logger and it seems to just write to console so it must be log4j i need?
In the past ive seen org.apache.log4j.Logger used, is this what i want?
Could somebody please point me to somewhere where this is documented?
Thanks.
The documentation is here. You can't use file appenders directly because the GWT code runs as Javascript in the browser (when not in development mode). If you want to log to a file you need to enable remote logging.
If there is a server side part logging works as normal. But then it has not much to do with GWT, except for being in the same project and providing services (via a custom protocol).
What do you want to log? rpc service servlets or client logic?
Log4j is just for java not javascript. So it is intended to log your classes in your /server/ package that will be deployed in your server.
Your /client/ package classes will be translated to javascript and will run in the client browser. So, no Java at all!
You can use log4j "emulated" to javascript with http://code.google.com/p/gwt-log/ which will send your client logs using a RemoteLogger to the server via rpc and then you can log them to a file.

Combining Akka, Spray, and embedded Jetty

I'm trying to create a standalone JAR containing Akka, Spray, and Jetty. Ideally I distribute the entire application in that single file, without any external files whatsoever.
I understand how to create an embedded Jetty server instance
def main(args: Array[String]): Unit = {
val server = new Server(9012);
server.start();
server.join();
Thread.sleep(2000);
server.stop();
}
and I've followed the Spray example code in creating a HelloService and Boot class, but I have no earthly idea of how to connect the two, so that when a URL is requested on the Jetty server a Spray service responds to it. Any help would be much appreciated.
Update: I'm getting a lot closer to solving this problem, thanks to a thread of inquiry prompted by Alois Cochard (I'm coming from a web scripting background, and getting my head around Java web services has been ... challenging!). I've modified my main method to start the server and read the Jetty and akka configuration files that are in the getting started template. It's reading both of those files, but now I'm getting this when I navigate to / on the Jetty server:
HTTP ERROR: 500
Problem accessing /. Reason:
assertion failed: 0 actors for id 'spray-root-service' found, expected exactly one
I know I'm missing something silly (and probably that I should break down and use SBT, but being able to just compile and run in Eclipse, and then refresh in the browser, is so simple and appealing).
Update #2: Figured out the problem. I wasn't creating a WebAppContext object, which meant that the web.xml was never getting read, and thus Akka was never being loaded. This is the revised main method which is now working.
According to the spray-template, you should add the Spray servlet connector in the web.xml configuration file:
http://github.com/spray/spray-template/blob/master/src/main/webapp/WEB-INF/web.xml
You can find some informations about how to configure a standealone jetty to use this file here (there is surely better references in netty documentation directly):
http://exist.sourceforge.net/deployment.html#d47e594
BTW, using the spray template as a basis for your project looks like a good idea ;)