Micronaut CLI is very useful while creating the application, however the command to create a controller is not present in the CLI.
Micronaut Version: 2.0.3
From the micronaut documentation we have a command for profile https://docs.micronaut.io/2.0.0.M3/guide/index.html#cli
$ mn profile-info service
Profile: service
------------------
The service profile
Provided Commands:
--------------------
create-bean Creates a singleton bean
create-client Creates a client interface
create-controller Creates a controller and associated test
create-job Creates a job with scheduled method
create-test Creates a simple test for the project's testing framework
create-websocket-client Creates a Websocket client
create-websocket-server Creates a Websocket server
help Prints help information for a specific command
Provided Features:
------------------
...
When I run the command mn profile-info service I get an error as
I have only below options
I am trying to create a controller from the cli
Profiles were only in Micronaut version 1.x. So profile related commands like mn profile-info service are not available in Micronaut version 2.x.
When you create the project end enter the project directory you can use these additional mn commands:
feature-diff - Produces the diff of an original project with an original project with additional features.
create-job - Creates a job with scheduled method
create-client - Creates a client interface
create-controller - Creates a controller and associated test
create-test - Creates a simple test for the project's testing framework
create-bean - Creates a singleton bean
create-websocket-client - Creates a Websocket client
create-websocket-server - Creates a Websocket server
And you can also see more description of the command when you call it with -h option. For example:
$ mn create-controller -h
Usage: mn create-controller [-fhvVx] CONTROLLER-NAME
Creates a controller and associated test
CONTROLLER-NAME The name of the controller to create
-f, --force Whether to overwrite existing files
-h, --help Show this help message and exit.
-v, --verbose Create verbose output.
-V, --version Print version information and exit.
-x, --stacktrace Show full stack trace when exceptions occur.
Related
I've got a Spring Boot application that'd I'd like to automatically generate traces for using the OpenTelemetry Java agent, and subsequently upload those traces to Google Cloud Trace.
I've added the following code to the entry point of my application for sending traces:
OpenTelemetrySdk.builder()
.setTracerProvider(
SdkTracerProvider.builder()
.addSpanProcessor(
SimpleSpanProcessor.create(TraceExporter.createWithDefaultConfiguration())
)
.build()
)
.buildAndRegisterGlobal();
...and I'm running my application with the following system properties:
-javaagent:path/to/opentelemetry-javaagent-all.jar \
-jar myapp.jar
...but I don't know how to connect the two.
Is there some agent configuration I can apply? Something like:
-Dotel.traces.exporter=google_cloud_trace
I ended up resolving this as follows:
Clone the GoogleCloudPlatform /
opentelemetry-operations-java repo
git clone
git#github.com:GoogleCloudPlatform/opentelemetry-operations-java.git
Build the exporter-auto project
./gradlew clean :exporter-auto:shadowJar
Copy the jar produced in exporter-auto/build/libs to my target project
Run the application with the following arguments:
-javaagent:path/to/opentelemetry-javaagent-all.jar
-Dotel.javaagent.experimental.extensions=[artifact-from-step-3].jar
-Dotel.traces.exporter=google_cloud_trace
-Dotel.metrics.exporter=none
-jar myapp.jar
Note: This setup does not require any explicit code changes in the target code base.
we have installed a node js utility on a local machine/server.
using npm install -g openapi2Arbitaryservice
I can call this utility and it is working fine. It reads a json and create a service api.
openapi2Arbitaryservice generateApi myProxySwagSep6 -s ./swagger-petstore.json -d ./aug-2021
I want to trigger this when api request comes to the tomcat server with body of JSON. I have a spring-boot application using java 8.
I was trying to use exec method of java to call this locally installed node js application when an api request comes to the server and do the processing
String[] command = { "/bin/bash", "-c", ,"openapi2ArbitaryService", "generateApi", "myProxySwagSep6", "-s",".swagger-petstore.json", "-d", "./aug-2021" };
p = Runtime.getRuntime().exec(command);
But, i get error "Exit Value 127". It seems it's not able to recognise openapi2ArbitaryService
Is this a valid use-case for java calling local/server installed application on user api requests. Should this be decoupled using a queue and then handled separately e.g as a docker task.
Is Golang/python suitable for such use-cases please share some thoughts.
thanks in advance !
I'd like to run Play Framework over HTTPS only in the development mode and I've done so using the following bit of configuration:
https.port=9443
trustmanager.algorithm=JKS
keystore.file=conf/certificate.jks
keystore.password=password
certificate.password=password
application.mode=dev
%prodenv.application.mode=prod
This works when I run play run but in production we run play run --%prodenv and I want to disable HTTPS as the HTTPS is handled by Nginx. I'm lost with how to do this. I would like to do this via the configuration file and not via additional command-line arguments as it does defy the purpose of having all my application configuration in the application.conf file.
One way to do it is to have two confs file: application.conf and prod.conf
application.conf stays the way it is and prod.conf would look something like
include "application.conf"
https.port = myProdPort
### other params to be overwritten
when launching your application in prod you can do
play run -Dconfig.file=/mypath/prod.conf
sbt run -Dhttps.port=9443 -Dhttp.port=disabled
Rather than have two configuration files, I achieved this by using just one. In order to run the app, I run play run --%dev and this is what the configuration looks like.
%dev.https.port=9443
%dev.trustmanager.algorithm=JKS
%dev.keystore.file=conf/certificate.jks
%dev.keystore.password=password
%dev.certificate.password=password
Similar to the other answer by Johan, I do it the reverse way: my application.conf is for prod and I run a dev.conf just in development:
include "application.conf"
https.port = devPort
And run locally like so:
play run -Dconfig.file=dev.conf
This way you don't have to change any configuration on your prod server.
You could remove the https.port param from your conf file and pass it in via the command line, when you run it in development mode:
play run -Dhttp.port=9443
See: Sprecifying server address and port
Play framework runs using Netty server you can overwrite the server configuration using -D parameters.
In sbt it can be done like:
sbt "project pepe-grillo-server" "run -Dhttps.port=42443 -Dhttp.port=disabled"
If you are using custom ssl engine provider CustomSSLEngineProvider you can use below command to run netty in ssl mode.
./sbt "-Dhttps.port=9443" "-Dplay.server.https.engineProvider=services.https.CustomSSLEngineProvider" "-Dconfig.resource=<config file> run
Once the server is up and running you can curl the endpoint to check cert validity.
curl -v https://127.0.0.1:9443
when I run sample IBM Bluemix Liberty for Java application https://github.com/ibmjstart/bluemix-java-postgresql-uploader.git following error:
-----> Downloaded app package (1.9M)
-----> Downloaded app buildpack cache (4.0K)
OK
/var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:101:in build_pack': Unable to detect a supported application type (RuntimeError) from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:74:inblock in compile_with_timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in timeout' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:73:incompile_with_timeout'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:54:in block in stage_application' from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:inchdir'
from /var/vcap/packages/dea_next/buildpacks/lib/buildpack.rb:50:in stage_application' from /var/vcap/packages/dea_next/buildpacks/bin/run:10:in'
FAILED
Server error, status code: 400, error code: 170001, message: Staging error: cannot get instances since staging failed
TIP: use 'cf logs jpu-henryhan --recent' for more information
The top error looks like you left off the -p <path_to_war> parameter when doing a push. If you just push a directory containing a WAR file, it will not be detected by the Java buildpack.
The tip provided in the output of your cf push request is relevant.
TIP: use 'cf logs jpu-henryhan --recent' for more information
Running that command will tail the log files produced during the staging process and let you see what error may have been raised. Often, it can be a missing dependency or a transient failure of some sort.
I just successfully deployed the sample using the "deploy to Bluemix" button and manually via the cf command line tool. Unless you changed the code, it is most likely that this error is a transient failure.
Run following command:
$ cf push jpu- -b https://github.com/cloudfoundry/java-buildpack --no-manifest --no-start -p PostgreSQLUpload.war
add the parameter to set the buildpack "-b https://github.com/cloudfoundry/java-buildpack"
I am new to JMX. I am using Spring 4 with JMX. I am also using Apache Camel and would like to expose a stop method. I have setup everything but when clicking on the stop method within MBeans in JConsole I get the following Exception:
Problem invoking stop : java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.io.WriteArbortedException:writing aborted:java.io.NotSerializableException: org.apache.camel.spring.SpringCamelContext
The project is located on GitHub: https://github.com/rajivj2/example2/
The class for the MBean code is located is in com.example.config.ApacheCamelConfig.java
Once the project is build using mvn clean install run the following on the Command Prompt:
java -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar server-app-jar-with-dependencies.jar
After this in the Java JDK bin folder open jconsole and connect to the server-app-jar-with-dependencies.jar. Locate the MBeans tab and the stop method.
I can't see where I am going wrong. The SpringCamelContext is provided by Apache Camel.
you should not return the CamelContext - it is not serializable.
separate the #Bean from the #ManagedOperation - the operation for stopping the route should have return type void