Configuring context path for jetty with static resources - jetty

I have a maven application configured to start Jetty and also load statics from ../client . Configuration is below:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.4.v20120524</version>
<configuration>
<scanIntervalSeconds>25</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>9095</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<webAppSourceDirectory>../client/</webAppSourceDirectory>
<webAppConfig>
<resourceBases>
<resourceBase>src/main/webapp</resourceBase>
<resourceBase>../client/</resourceBase>
</resourceBases>
</webAppConfig>
</configuration>
</plugin>
What I am trying to do is to move only webapp under /API resource base. To be more explicit I want to have the mappings:
src/main/webapp ---> /API
../client/ ---> /

Finally found the right config:
<webAppConfig>
<contextPath>/API</contextPath>
</webAppConfig>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<contextPath>/</contextPath>
<resourceBase>../client/</resourceBase>
</contextHandler>
</contextHandlers>

Related

why ElastiMq keeps requiring server and check parameters since I am passing it

I am using AWS SQS for the first time. I work in certain company which blocks us via firewall to connect from our local network to SQS for some reasons beyond my control. I can upload anything I have developed to our TomCat in AWS or even run via our Linux command line with our ec2-user (upload via WinSCP and trigger via Putty).
Since I need to provide certain solution using sqs but I can't debug accessing it from my Eclipse I am interested to mock sqs. Additionally, I see advantages on such approach from test perspective. That said, after few hours searching I found exactly what I need: http://www.schibsted.pl/blog/mocking-amazon-sqs-with-elasticmq/
I downloaded the example (https://github.com/JanGurda/elastc-mq-rule-sample) but I can't start it. I understand that there is an elasticmq embbeded which should be started together with such jar. I tried other way by downloading the elasticmq and started it before running the sample but I am still getting the same output.
Basically, I am getting this output
usage: java -jar project.jar [-h] [-v] {server,check} ...
positional arguments:
{server,check} available commands
optional arguments:
-h, --help show this help message and exit
-v, --version show the application version and exit
It seems I am doing something very silly but I didn't find a north.
PS. I checked and the pom has lombok and elasticmq properly settup.
pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.schibsted.spid</groupId>
<artifactId>elastc-mq-rule-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>1.10.1</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
<version>0.8.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticmq</groupId>
<artifactId>elasticmq-rest-sqs_2.11</artifactId>
<version>0.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>pl.schibsted.spid.elasticmq.server.ElasticMqRuleSampleApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/ITest*.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
DropwizardAppRule:
public class ITestPingResource {
#ClassRule
public static DropwizardAppRule<ElasticMqRuleSampleApplicationConfiguration> app =
new DropwizardAppRule<>(ElasticMqRuleSampleApplication.class,
ITestPingResource.class.getClassLoader().getResource("test.yml").getPath());
#ClassRule
public static SqsRule sqs = new SqsRule(SqsRuleConfiguration.builder()
.queue("sample-queue").port(8888).build());
private Client client = ClientBuilder.newClient();
#After
public void tearDown() {
sqs.purgeAllQueues();
}
#Test
public void shouldPublishProcessedRequestPayload() throws Exception {
// given
String toSend = "abcdefgh";
// when
Response response = client
.target("http://127.0.0.1:" + app.getLocalPort() + "/ping")
.request().post(Entity.json(toSend));
// then
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
List<Message> messagesFromQueue = sqs.getQueue("sample-queue").read(10);
assertEquals(1, messagesFromQueue.size());
assertEquals("ABCDEFGH", messagesFromQueue.get(0).getBody());
}
}
test.yml
queueUrl: http://localhost:8888/queue/sample-queue
awsAccessKey: x
awsSecretKey: x
main:
public class ElasticMqRuleSampleApplication extends Application<ElasticMqRuleSampleApplicationConfiguration> {
public static void main(String[] args) throws Exception {
new ElasticMqRuleSampleApplication().run(args);
}
#Override
public void run(ElasticMqRuleSampleApplicationConfiguration configuration, Environment environment) throws Exception {
PingResource resource = new PingResource(configuration);
environment.jersey().register(resource);
}
}
Demetrio,
The error you get is simply standard output of Dropwizard. You should use “server” parameter to start Dropwizard application. So command you use to start Dropwizard is java -jar <> server.
If you however would like to run sample integration test (which I discussed in my article) just use Maven. Type mvn clean install. It’ll build project and run integration test.
Thanks

nar-maven-plugin eclipse API Incompatibility

I'm using eclipse to compile/run my projects. I tried to use maven on c++ projects with nar-maven-plugin to build them. It works well as i launch maven goals in command line.
But when i import my maven project in eclipse, i have the following errors :
Execution default-nar-compile of goal
com.github.maven-nar:nar-maven-plugin:3.2.3:nar-compile failed: An API
incompatibility was encountered while executing
com.github.maven-nar:nar-maven-plugin:3.2.3:nar-compile:
java.lang.NoSuchMethodError:
org.codehaus.plexus.util.DirectoryScanner.setupMatchPatterns()V
----------------------------------------------------- realm = plugin>com.github.maven-nar:nar-maven-plugin:3.2.3 strategy =
org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
...
Moreover, eclipse seems to manage my project as a Java project instead of a C project.
Note : i'm using
Eclipse 4.3.1
M2E 1.4.0
CDT 8.3.0
My pom.xml
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>helloworld-cplusplus-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>nar</packaging>
<name>Helloworld</name>
<properties>
<rootdir>${project.basedir}</rootdir>
<nar.linker>gpp</nar.linker>
<nar.arch>x86</nar.arch>
<nar.os>Windows</nar.os>
</properties>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<versionRange>[3.2.3,)</versionRange>
<goals>
<goal>nar-test-unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<fork>true</fork>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<linker>
<name>g++</name>
</linker>
<libraries>
<library>
<type>executable</type>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sample</groupId>
<artifactId>helloworld-shared-library-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>nar</type>
</dependency>
</dependencies>
</project>
If someone is using nar-maven-plugin with eclipse can help me :). I would really like to use it on eclipse.
Thanks!

packagingExcludes and maven property variable

I have a folder structure as shown below under src/main/webapp/
I have a maven property ${sencha.env} that can be either of development | testing or production. I want to exclude the others from the build directory while making WAR. I am trying the below but its not working. Please guide -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp/build/${sencha.env}/BACK</directory>
</resource>
</webResources>
<packagingExcludes>.sencha/**,app/**,ext/**,sass/**,%regex[build/(?!${sencha.env})]</packagingExcludes>
</configuration>
</plugin>
Please notice :
%regex[build/(?!${sencha.env})] in packagingExcludes
thanks!
You are very close; you need to have %regex[build/(?!${sencha.env}/).*]. Notice the .* which means that you are excluding every path below build/(?!${sencha.env}/.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp/build/${sencha.env}/BACK</directory>
</resource>
</webResources>
<packagingExcludes>.sencha/**,app/**,ext/**,sass/**,%regex[build/(?!${sencha.env}/).*]</packagingExcludes>
</configuration>
</plugin>

JWSC for weblogic 12c with Maven

We are in the process of upgrading from Weblogic 10g to 12c. A portion of our code base is webservices so we were using weblogic-maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>2.9.5</version>
<configuration>
<contextPath>ws</contextPath>
<keepGenerated>true</keepGenerated>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jwsc</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>weblogic</groupId>
<artifactId>weblogic</artifactId>
<version>${weblogic.version}</version>
<scope>system</scope>
<systemPath>${bea.lib}/weblogic.jar</systemPath>
</dependency>
</dependencies>
</plugin>
The build error I see is
[ERROR] Failed to execute goal org.codehaus.mojo:weblogic-maven-plugin:2.9.5:jwsc (default) on project webService: Execution default of goal org.codehaus.mojo:weblogic-maven-plugin:2.9.5:jwsc failed: Plugin org.codehaus.mojo:weblogic-maven-plugin:2.9.5 or one of its dependencies could not be resolved: Failure to find weblogic:webservices:jar:10.3.6 in http://ccicusbuild1/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
Deeper inspection shows that the plugin has a dependency on weblogic:weblogic:10.3.6 and weblogic:webservices:10.3.6. As shown in the previous code, I can override weblogic:weblogic:10.3.6 with weblogic:weblogic:12.1.1. The problem is webservices.jar is no longer apart of weblogic 12c, so I have nothing to override the dependency with, nor can I exclude it.
The page for weblogic-maven-plugin (http://mojo.codehaus.org/weblogic-maven-plugin/) mentions support for 12c, but doesn't give any details.
The goal is to be able to run JWSC through maven. Is there a tweak to the plugin configuration that I can do to make it work, or is there another plugin, or do I need to bite the bullet and run the code with the ant plugin?
This was the eventual solution we used. If some one else has something better, please post it.
plugins portion of pom.xml
<plugins>
<!--
Below contains a work around to build web services for Weblogic 12c.
weblogic-maven-plugin was how things were done (and was much cleaner)
but at the time of this work around, it doesn't appear to support Weblogic 12c.
If in the future, weblogic-maven-plugin or some other plugin become known,
it should replace both parts of the work around.
-->
<!-- START OF WORK AROUND part 1-->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>set-main-artifact</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.artifact.setFile(new File(project.build.directory+'/'+project.artifactId+'-'+project.version+'.war'))
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<target>
<property name="maven.compile.classpath" refid="maven.compile.classpath" />
<property name="maven.runtime.classpath" refid="maven.runtime.classpath" />
<property name="maven.test.classpath" refid="maven.test.classpath" />
<property name="maven.plugin.classpath" refid="maven.plugin.classpath" />
<ant antfile="src/main/ant/build.xml" target="all" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>weblogic</groupId>
<artifactId>weblogic</artifactId>
<version>${weblogic.version}</version>
<scope>system</scope>
<systemPath>${bea.lib}/weblogic.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
<!-- END OF WORK AROUND part 1 -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<!-- START OF WORK AROUND part 2 -->
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
</executions>
<!-- END OF WORK AROUND part 2 -->
</plugin>
</plugins>
build.xml
<project name="build-webservice" default="all">
<target name="all" depends="build.webService" />
<path id="maven_plugin_classpath">
<pathelement path="${maven.plugin.classpath}" />
</path>
<path id="maven_runtime_classpath">
<pathelement path="${maven.compile.classpath}" />
<pathelement path="${maven.runtime.classpath}" />
<pathelement path="${maven.plugin.classpath}" />
<pathelement path="${weblogic.jar}" />
</path>
<taskdef name="jwsc"
classname="weblogic.wsee.tools.anttasks.JwscTask"
classpath="${weblogic.jar}"
classpathref="maven_plugin_classpath"
/>
<target name="build.webService" description="Compile the web services if not up2date">
<!--
Eclipse compiles and places classes into target/classes when the workspace is building.
If this folder exists when jwsc runs, then any classes that are already compiled will NOT
be included in the final WAR file. Thus, this directory is removed prior to created the
webServices WAR fie.
-->
<delete dir="target/classes" />
<jwsc srcdir="${project.build.sourceDirectory}"
destDir="target"
classpathref="maven_runtime_classpath"
keepGenerated="yes"
applicationxml="${project.build.directory}/application.xml"
fork="true"
memorymaximumsize="256m"
verbose="true"
debug="on"
>
<module contextPath="ws" name="${project.artifactId}-${project.version}">
<jwsfileset srcdir=".">
<include name="**/*.java" />
<exclude name="**/*Test.java" />
</jwsfileset>
</module>
</jwsc>
</target>
</project>
Overall description:
War plugin execution is overwritten so that it isn't run
The compiling and packaging is handled in ant by JwscTask
gmaven plugin is used inform maven that it should use the ant generated war as the artifact
Notes:
Alternatives for gmaven were attachartifact ant task and build-helper-maven-plugin as specified in How to register a custom built jar file as maven main artifact?, but neither worked. Both resulted in An attached artifact must have a different ID than its corresponding main artifact.

Avoid use of deprecated methods in org.eclipse.jetty.server.ssl.SslSocketConnector with jetty-maven-plugin

Releated to
Deprecated Embedded Jetty 7.6 using SSL
Jetty SslConnector's deprecated methods
How to write correct Maven POM without using the deprecated methods / tags in connector like needClientAuth or keystore?
Example with deprecated method use:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<!-- see http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin -->
<version>8.0.4.v20111024</version>
<!-- see http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.mortbay.jetty%22%20AND%20a%3A%22jetty-maven-plugin%22 -->
<dependencies>
<!--[...]-->
</dependencies>
<configuration>
<webAppXml>src/main/resources/jetty-Login.xml</webAppXml>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webAppConfig>
<contextPath>/MyApp</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>8080</port>
</connector>
<connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
<port>8443</port>
<password>changeit</password>
<wantClientAuth>true</wantClientAuth><!-- deprecated! -->
<needClientAuth>false</needClientAuth><!-- deprecated! -->
<keystore>/my/path/to/java/keystore</keystore><!-- deprecated! -->
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
A custom Ssl configuration via the maven configuration structure isn't possible.
This is due to the introduction of the SslContextFactory requirement on the SslSocketConnector constructor to tighten up some SSL security issues on the server side.
Maven can only construct objects from the default constructor when using the structures in the pom.xml.
You'll have to bridge the change via the <jettyXml> element.
Go grab a copy of the jetty-ssl.xml from the distribution and put it into your ${project.basedir}/src/main/config/jetty-ssl.xml and use the following configuration block.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webAppConfig>
<contextPath>/MyApp</contextPath>
</webAppConfig>
<jettyXml>src/main/config/jetty-ssl.xml</jettyXml>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>8080</port>
</connector>
</connectors>
</configuration>
</plugin>