jetty-maven-plugin multiple wars separate ports - java

I use the jetty-maven-plugin for local development testing. What I want is from a single jetty:run command, start a bunch of jetty containers on separate ports as specified in the pom.xml -- I don't want to specify it within the war. My current plugin configuration block looks like ::
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-a/target/a.war</war>
<contextPath>/a</contextPath>
<allowNullPathInfo>true</allowNullPathInfo>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-b/target/b.war</war>
<contextPath>/b</contextPath>
<allowNullPathInfo>true</allowNullPathInfo>
</contextHandler>
</contextHandlers>
</configuration>
I know I can specify a -Djetty.port but that globally sets the port. The above example starts both wars in the same jetty container instance running on port 8080. Does anyone know a switch within contextHandler to set the port or how to do it if I have multiple instances of the entire plugin block? Every example I've searched for only has the option to set it in the jetty.xml file within the war which I don't want to do.

It's possible if you name the connectors and context handlers
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<name>instance_8080</name>
</connector>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8081</port>
<name>instance_8081</name>
</connector>
</connectors>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-a/target/a.war</war>
<contextPath>/a</contextPath>
<connectorNames>
<item>instance_8080</item>
</connectorNames>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-b/target/b.war</war>
<contextPath>/b</contextPath>
<connectorNames>
<item>instance_8081</item>
</connectorNames>
</contextHandler>
</contextHandlers>
</configuration>
Note, this configuration is for org.mortbay.jetty:jetty-maven-plugin.

In your jetty maven plugin you can create multiple connectors that can run on different ports. That's a first start.
I'm not sure offhand how or if those connector blocks can run different wars. They can refer to different jetty.xml (although I've had nothing but trouble with jetty.xml)
http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#configuring-jetty-container

Related

Wildfly Maven Plugin - commands seem to have no effect

I am using the Wildfly Maven Plugin and it is working, in that it turns on, runs web application, however I am having trouble with my custom configurations, namely:
Setting the Root logger and Console logger to debug mode
Allowing connections from 0.0.0.0:8080 or something other than localhost.
Here is my set up:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.2.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<java-opts>
<java-opt>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044</java-opt>
</java-opts>
<commands>
<!-- **These are the commands that aren't going through** -->
<command>/subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG") </command>
<command>/subsystem=logging/console-handler=CONSOLE:write-attribute(name="level", value="DEBUG")</command>
<command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", "path"=>"debug.log"})</command>
<command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
<command>/subsystem-----Enable Remote access here?</command>
</commands>
<add-user>
<users>
<user>
<username>admin</username>
<password>admin.1234</password>
</user>
<user>
<username>admin-user</username>
<password>user.1234</password>
<groups>
<group>admin</group>
<group>user</group>
</groups>
<application-user>true</application-user>
</user>
<user>
<username>default-user</username>
<password>user.1234</password>
<groups>
<group>user</group>
</groups>
<application-user>true</application-user>
</user>
</users>
</add-user>
</configuration>
</plugin>
I know when starting from terminal, one would use this: ./standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 However I am running demos straight from Maven and need to access my webapp from a separate machine.
Note - from within the Wildfly Management page, I can manually set the Root Logger and Console Logger to debug mode and then the proper debug logs will flow out.
For example, manually I could go here: http://127.0.0.1:9990/console/index.html#logging-configuration and then manually change the logging from the default INFO level to DEBUG:
So my question is, along with allowing remote access, is how to change the logging level as a command into the maven wildfly plugin.
You'd need to upgrade the plugin version to 2.1.0.Beta1 to get that to work. The 2.0.x versions do no have the ability to execute CLI commands from the run or deploy goals.
If you need to stick with the version you're using you'd need to define the execute-commands goal. Then you could use the embedded server to configure the server.
<commands>
<!-- **These are the commands that aren't going through** -->
<command>embed-server</command>
<command>/subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG") </command>
<command>/subsystem=logging/console-handler=CONSOLE:write-attribute(name="level", value="DEBUG")</command>
<command>/subsystem=logging/file-handler=debug:add(level=DEBUG,autoflush=true,file={"relative-to"=>"jboss.server.log.dir", "path"=>"debug.log"})</command>
<command>/subsystem=logging/logger=org.jboss.as:add(level=DEBUG,handlers=[debug])</command>
<command>/subsystem-----Enable Remote access here?</command>
<command>stop-embedded-server</command>
</commands>

How can I set a custom SSLSocketFactory on a Heroku app?

I'd like to control which public IP addresses my app can connect to, so that I can blacklist a small set of IPs for outgoing connections for the entire app.
Deploying a Tomcat Java app to Heroku, I've specified a custom Java security configuration by overriding "java.security.properties"
web: java $JAVA_OPTS -Djava.security.properties=java.security -jar target/dependency/webapp-runner.jar --port $PORT target/*.war
In that config, I've given a custom SSLSocketFactory class
ssl.SocketFactory.provider=security.MyCustomSocketFactory
This allows MyCustomSocketFactory to examine every IP address and host for outgoing connections in a small sample app. However, it's not working for my full application after I deploy to Heroku. The class isn't found, even though it is packaged into the .war file.
Caused by: java.lang.ClassNotFoundException: security.MyCustomSocketFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:105)
at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335)
at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:292)
I think I have to specify that my single class is class-loaded differently, because my application is initialized by webapp-runner.jar. Is there a different approach I should be taking?
I know my class is available to some classloader, because I can call Class.forName() from my own code, without getting an exception. But it's just not able to be loaded from SSLSocketFactory.getDefault().
As codefinger suggested in a comment, I needed to include MyCustomSocketFactory on the classpath outside of the war file.
I moved MyCustomSocketFactory to a separate Maven project, and built it as a separate jar.
Then, I added a built step on my main project to copy the JAR into the same directory as webapp-runner.jar.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-socketblocker</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/dependency</outputDirectory>
<resources>
<resource>
<directory>jars</directory>
<includes>socketblocker-1.0.jar</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Finally, I modified my Procfile to use wildcard matching, and add both webapp-runner.jar and my custom JAR as classpath entries.
web: java $JAVA_OPTS -Djava.security.properties=java.security -cp "target/dependency/*" webapp.runner.launch.Main --port $PORT target/*.war

Can I redeploy to remote Tomcat instance and start local testing instance

I'd like to start a new local Tomcat instance for testing purposes during the Maven's pre-integration-test phase (on different port) and run tests there. Then if the tests pass I'd like to do a cargo:redeploy to a remote Tomcat instance. I'm having issues with getting this right though. If I do
mvn org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat8x -Dcargo.maven.containerUrl=https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.36/bin/apache-tomcat-8.0.36.zip -Dcargo.maven.type=standalone
I get
[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.19:run (default-cli) on project atf-relay-server: Execution default-cli of goal org.co
dehaus.cargo:cargo-maven2-plugin:1.4.19:run failed: Cannot create configuration. There's no registered configuration for the parameters (container [id = [tomcat
8x], type = [installed]], configuration type [runtime]). Valid types for this configuration are:
[ERROR] - standalone
[ERROR] - existing
[ERROR] -> [Help 1]
My pom.xml for cargo is (specifying only remote instance):
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.19</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>localhost</cargo.hostname>
<cargo.servlet.port>9990</cargo.servlet.port>
<cargo.remote.username>user</cargo.remote.username>
<cargo.remote.password>pass</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
</deployer>
</configuration>
</plugin>
What's the correct way to achieve this?
Ok, seems it's quite easy to achieve after getting familiar with Maven profiles.
I have now one profile controlling remote Tomcat instance and doing the cargo:redeploy and other profile just creating local Tomcat, running it, deploying app there and running the tests.

Set JARs to skip in order to speed up Tomcat 7 maven plugin startup

Is there a simple way (e.g., directly from tomcat7-maven-plugin configuration) to specify which JARs should be skipped during Tomcat startup in order to speed it up?
The Tomcat 7 documentation encourages to use a system property org.apache.catalina.startup.ContextConfig.jarsToSkip (see http://wiki.apache.org/tomcat/HowTo/FasterStartUp#JAR_scanning), but when set from maven configuration, it does not work.
After inspecting the sources of tomcat7-maven-plugin, I found a workaround to achieve jars skipping. (It may however stop working with future releases of Maven Tomcat 7 plugin.)
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<path>/${project.artifactId}</path>
<port>8080</port>
<systemProperties>
<org.apache.catalina.startup.ContextConfig.jarsToSkip>*</org.apache.catalina.startup.ContextConfig.jarsToSkip>
<!-- work around .. see: https://issues.apache.org/jira/browse/MTOMCAT-281 -->
<catalina.config>${project.baseUri}/target/tomcat/logs</catalina.config>
</systemProperties>
</configuration>
</plugin>
As described in a related bug (https://issues.apache.org/jira/browse/MTOMCAT-281), the problem is that Tomcat blindly overrides all system properties with properties from tomcat-embed-core-7.0.47.jar!/org/apache/catalina/startup/catalina.properties. As a result, the value of org.apache.catalina.startup.ContextConfig.jarsToSkip system property specified in plugin configuration is overridden.

How m2eclipse create a new domain by maven-glassfish-plugin?

version is glassfish v3
I want to trying maven-glassfish-plugin but I don't know how to create a new domain.
You can use the create-domain command. Either pass parameters on the command line or follow the interactive steps:
$ asadmin create-domain
But the Maven GlassFish Plugin (once properly configured) can also create a domain with the following goal:
glassfish:create-domain Create a new Glassfish domain. (Creating an existing domain will cause it to be deleted and recreated.)
Here is a configuration sample (inspired by the Fairly Complete Configuration Example):
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.2-SNAPSHOT</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>${domain.username}</user>
<adminPassword>${domain.password}</adminPassword>
<!-- <passwordFile>path/to/asadmin/passfile</passwordFile> -->
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>true</echo>
<skip>${test.int.skip}</skip>
<domain>
<name>${project.artifactId}</name>
<httpPort>8080</httpPort>
<adminPort>4848</adminPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
</plugin>

Categories