jetty-maven-plugin setting buffers sizes - maven

Returning to jetty-maven-plugin I've trouble to set buffers size.
My use-case imply file upload (usual size is ~700Ko).
Because the upload is too big for jetty-maven-plugin default configuration I get Http response with error status code 413 (request too large)
I tryied using plugin configuration :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven.version}</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
<requestHeaderSize>8192</requestHeaderSize>
<requestBufferSize>2097152</requestBufferSize>
</connector>
</connectors>
</configuration>
</plugin>
Then I tried to use jetty-maven-plugin with a jetty.xml file
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven.version}</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<jettyConfig>${basedir}/src/main/config/jetty/jetty.xml</jettyConfig>
</configuration>
</plugin>
The jetty.xml is below:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
<Set name="requestHeaderSize">8192</Set>
<Set name="requestBufferSize">2097152</Set>
</New>
</Arg>
</Call>
</Configure>
Nothing works.
Could someone hand me the correct configuration please?

I'm not sure whether this fixes the problem in your use case, but you could try adding the following to your <configuration> section of the maven-jetty-plugin:
<systemProperties>
<systemProperty>
<name>org.eclipse.jetty.server.Request.maxFormContentSize</name>
<value>-1</value> <!-- or any other value -1 is for max -->
</systemProperty>
<systemProperties>
as mentioned by jesse mcconnell the property was renamed in jetty 7/8 to org.eclipse.jetty.server.Request.maxFormContentSize.
For jetty 6 for me org.mortbay.jetty.Request.maxFormContentSize is working.

change your pom as per this and add this two xml file into your project. I hope, it will work for you.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<contextPath>/random-api</contextPath>
<scanIntervalSeconds>5</scanIntervalSeconds>
<jettyXml>jetty.xml,jetty-http.xml</jettyXml>
</configuration>
</plugin>
===============jetty.xml and jetty-http.xml=================
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-tools/xwiki-platform-tool-jetty/xwiki-platform-tool-jetty-resources/src/main/resources/jetty/etc/jetty.xml
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-tools/xwiki-platform-tool-jetty/xwiki-platform-tool-jetty-resources/src/main/resources/jetty/etc/jetty-http.xml

After a pause (lunch) I grabed the code of the web-app I was supposed to test.
There was a redundant limitation into its "internal" configuration (use an upload agent with it's own size limit).
In fact the two configuration proposed for jetty are working (now that web-app doesn't have any redundant limitation)

Related

Using placeholders in Jetty contextXML file

I'm using Maven and jetty plugin to local start my application.
And I have seen way that you could use placeholders in Jetty contextXML.
Here is part of my pom.xml (located in separate module) where I connected jetty plugin:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<stopKey>${test.jetty.stop-key}</stopKey>
<stopPort>${test.jetty.stop-port}</stopPort>
<webAppConfig>
<contextPath>/${test.contextPath}/*</contextPath>
</webAppConfig>
<httpConnector>
<port>${jetty.port}</port>
<host>${jetty.host}</host>
</httpConnector>
<contextXml>${project.basedir}/src/main/resources/jetty/${jetty.mode}-jetty.xml</contextXml>
</configuration>
<dependencies>
...
</dependencies>
</plugin>
Here is part of my stub-jetty.xml file:
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<New id="loggerCF" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg></Arg>
<Arg>jms/logger/connectionFactory/loggerCF</Arg>
<Arg>
<New class="org.apache.activemq.ActiveMQConnectionFactory">
<Arg>tcp://${active-mq.host}:${active-mq.port}</Arg>
</New>
</Arg>
</New>
</Configure>
Parameters "active-mq.host" and "active-mq.port" defined in main pom.xml file.
When I run I receive next exception:
Caused by: java.net.URISyntaxException: Illegal character in authority at index 6: tcp://${active-mq.host}:${active-mq.port}
at java.net.URI$Parser.fail (URI.java:2848)
...
So I understand that Jetty not understand that needed to change placeholders to values from Maven properties. How to fix this problem or what I could read about this?
You can't directly reference properties defined in Maven configurations. The desired behavior could be achieved with System Properties. You can set it up as a part of jetty-maven-plugin configuration, the required option is systemProperties or systemPropertiesFile.
Here is a rough example (please note that I haven't checked it):
<New class="org.apache.activemq.ActiveMQConnectionFactory">
<Arg>tcp://<SystemProperty name="active-mq.host"/>:<SystemProperty name="active-mq.port"/></Arg>
</New>
and pom:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<name>active-mq.host</name>
<value>${active-mq.host}</value>
</systemProperty>
<systemProperty>
<name>active-mq.port</name>
<value>${active-mq.port}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>

Set context root for spring annotation based web app

How can set the context root for a annotation based spring web app? Sample application found in following link,
https://github.com/bkielczewski/example-spring-mvc-initializer
In browser I can access it as,
http://localhost:8080/
I want to change it as,
http://localhost:8080/spring
Thanks,
Charith
Update your pom.xml to include web-app configuration. See below
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.6.v20130930</version>
<configuration>
<webApp>
<contextPath>/spring</contextPath>
</webApp>
<httpConnector>
<port>8080</port>
<host>localhost</host>
</httpConnector>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>

maven-jetty-plugin does not run application on contextPath

maven-jetty-plugin is always running application on default context path ('/'). I tried running by setting contextpath property to 'test' but it does not work. http://localhost:8080/test is not accessible. It still runs on default context path.
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>9.1.0.M0</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/test</contextPath>
</webApp>
<connectors>
<!-- work around file locking on windows -->
<connector implementation="org.mortbay.jetty.bio.SocketConnector">
<port>8080</port><!-- this connector defaults to 1300 for some reason -->
</connector>
</connectors>
</configuration>
</plugin>
using only
<contextPath>/test</contextPath>
instead of
<webApp>
<contextPath>/test</contextPath>
</webApp>
worked for me

Automated testing issue-testng exception

I have 2 modules both having there respective pom.xmls,I would like to run pom.xml of module1 and using that run some code of module2 by using the classname to be run in the testng.xml.
Now this never works and i get a ClassNotFoundException.
Kindly help.
Cannot find class in classpath: com.org.Console1
at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
at org.testng.xml.XmlClass.init(XmlClass.java:68)
at org.testng.xml.XmlClass.<init>(XmlClass.java:54)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:516)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1322)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:170)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:299)
at org.testng.TestNG.run(TestNG.java:972)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:88)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:104)
This is my testng.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><suite allow-return-values="false" configfailurepolicy="skip" data-provider-thread-count="10" group-by-instances="false" junit="false" name="Suite" parallel="false" preserve-order="true" skipfailedinvocationcounts="false" thread-count="5">
<test allow-return-values="false" group-by-instances="false" junit="false" name="Test" preserve-order="true" skipfailedinvocationcounts="false">
<classes>
<class name="com.org.Console1">
</class>
</classes>
</test> <!-- Test -->
This is my pom.xml
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.8</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
You don't need to specify a suite for just testing. The surefire-plugin has to be configured to catch all your java-classes, the default is to look up for "*Test.java", i personally dont like this behaviour.
pom-snippet:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*.java</include><!-- dont just run *Test.java-files, which is default for surefire -->
</includes>
</configuration>
</plugin>
Please also verify that your test-classes are in the right position:
src/main/test/com/org/Console1.java
It HAS to be there, unless you want to configure it (which i dont recommend)

Maven Jetty run JNDI configuration

My project structure looks like this:
parent POM
|-- app-core
|-- app-model
|-- app-services
`-- app-web
In my pom.xml for app-web:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/test/resources/webdefault.xml</webDefaultXml>
</configuration>
</plugin>
Hot deployment works properly and have no issues with mvn jetty:run
Question : app-core uses springs how can I configure this JNDI for Jetty maven plugin in this multi-module hierarchy which should be accessible in app-core module
Update :
Have added pom.xml like this
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
<jettyConfig>src/main/resources/jetty.xml</jettyConfig>
</configuration>
</plugin>
And my jetty.xml looks like this :
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="icatDB" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/testDB</Arg>
<Arg>
<New class="net.sourceforge.jtds.jdbcx.JtdsDataSource">
<Set name="serverName">localhost</Set>
<Set name="databaseName">test</Set>
<Set name="user">sa</Set>
<Set name="password"></Set>
</New>
</Arg>
</New>
</Configure>
After that when i run mvn jetty:run I get this error
Failure: Object is not of type class org.mortbay.jetty.webapp.WebAppContext
Ok this works for me :
I need to use jettyEnvXml instead of jettyConfig.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
<jettyEnvXml>src/main/resources/jetty.xml</jettyEnvXml>
</configuration>
</plugin>
See this jetty documentation for the configuration of JNDI in Jetty
See this Maven Jetty documentation for the way how to add the configuration files to the build process

Resources