Mybatis Invalid bound statement (not found) - java

environments: maven ,spring 4.2.4-RELEASE , 2 modules: zscb-server zscb-common ,and zscb-server dependent on zscb-common
my web.xml core code:
<listener>
<listener-class>com.iidooo.core.listener.RoleResourceInitListener</listener-class>
</listener>
i have a init listener in my module zscb-common:
RoleResourceInitListener core code:
public void contextInitialized(ServletContextEvent arg0) {
try {
ServletContext sc = arg0.getServletContext();
SqlSessionFactory sqlSessionFactory = (SqlSessionFactory) SpringUtil.getBean(sc, "sqlSessionFactory");
SqlSession sqlSession = sqlSessionFactory.openSession(true);
SecurityRoleMapper roleMapper = sqlSession.getMapper(SecurityRoleMapper.class);
List<SecurityRole> roleList = roleMapper.selectAll();
// key: roleID value:List<SecurityResource>
Map<Integer, List<SecurityResource>> roleResourceMap = new HashMap<Integer, List<SecurityResource>>();
for (SecurityRole item : roleList) {
roleResourceMap.put(item.getRoleID(), item.getResourceList());
}
sc.setAttribute(ServletConstant.ROLE_RESOURCE_MAP, roleResourceMap);
} catch (Exception e) {
e.printStackTrace();
logger.fatal(e);
}
}
my applicationContext.xml:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.iidooo.core.mapper com.edo.zscb.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
i have checked my mapper.xml's namepsace:
<mapper namespace="com.iidooo.core.mapper.SecurityRoleMapper">
and when i run tomcat, error occured
Mybatis Invalid bound statement (not found)
who can save me!

First result when googling MapperScannerConfigurer leads to the documentation stating:
The basePackage property can contain more than one package name,
separated by either commas or semicolons.
while your packages are separated by a space.

In Mybatis if you add a mapper in a way like getMapper(YourMapper.class) or addMapper(YourMapper.class), it is necessary to leave the relative YourMapper.xml inside the same source package.
In maven it is also necessary to include the xml file(s) as resources and they must be in same place of the generated .class file.
So it would be something like this inside the <build> section of your pom.xml file:
<build>
...
<resources>
<resource>
<filtering>false</filtering>
<directory>src</directory>
<includes>
<include>**/package_path/to/your/*.xml</include>
</includes>
</resource>
</resources>
...
</build>
With this configuration maven will leave .xml files in the same place as you have in your source tree.

Related

How to switch between properties file depending on selected profile

We have profiles described as :
<profiles>
<!-- Local/Windows development -->
<profile>
<id>local</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>localhost</INSTALL_MACHINE_LIST>
<COPY_MODE>local</COPY_MODE>
</properties>
</profile>
<!-- Development -->
<profile>
<id>dev</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dev01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- QA -->
<profile>
<id>qa</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dqa01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- Production -->
<profile>
<id>prod</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>prod01</INSTALL_MACHINE_LIST>
</properties>
</profile>
</profiles>
For our test environment, we have 2 properties file (under src/main/test/resources) application-local.properties and application.properties file. The plan is to use application-local.properties in "local" profile mode ( on our development windows system) and application.properties for rest of the profile modes. In spring context (spring-context.xml), currently, we are manually switching between 2 properties file depending on what profile we are using. Looking for a way to select automatically application-local.properties for "local" profile and application.properties for any other type of profile. Is there a way to use if-then-else condition in xml based spring-context file? I tried :
<bean id="flag" class="java.lang.Boolean">
<constructor-arg value="#{ profile == 'local' ? true: false }" />
</bean>
<util:properties id="machineMetaDbProps" location="#{ flag ? 'application-local.properties' : 'application.properties' }"/>
Getting error :
Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'profile' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?'
try naming your property files like this:
application.properties
application-prod.properties
application-test.properties
and use "-Dspring.profiles.active=test" when starting your app
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-change-configuration-depending-on-the-environment
Xml Config:
In XML based config, you can make properties files related to a profile accessible to Spring via:
<beans profile="local">
<context:property-placeholder
location="classpath:docker-db.properties" ignore-unresolvable="true"/>
</beans>
<beans profile="test">
<context:property-placeholder
location="classpath:test-db.properties" ignore-unresolvable="true"/>
</beans>
Java Config:
Regarding to the active profile, you can also manually feed properties file to the spring vi java config as:
#Configuration
#Profile("local")
public class LocalPropertyReader {
#Bean
public static PropertyPlaceholderConfigurer properties() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] {
new ClassPathResource("docker-db.properties"), new ClassPathResource("application-local.properties")
};
ppc.setLocations(resources);
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}
}
#Configuration
#Profile("test")
public class ProdPropertyReader {
#Bean
public static PropertyPlaceholderConfigurer properties() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[] {
new ClassPathResource("test-db.properties"), new ClassPathResource("application-test.properties")
};
ppc.setLocations(resources);
ppc.setIgnoreUnresolvablePlaceholders(true);
return ppc;
}
}
Enabling Profile:
This can be done in following ways:
Using Spring context environment : ctx.getEnvironment().setActiveProfiles("local");
Using system property : System.setProperty("spring.profiles.active", "local");
Passing a system parameter at run time: -Dspring.profiles.active="local"
Enabling profile in web.xml
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>local</param-value>
</context-param>
More Info:
Load environment configurations and properties with Spring
Example

Arquillian testing on remote server

I want to test my war file on remote server but it is not working and giving me error:
sun.net.www.protocol.http.HttpURLConnection$HttpInputStream cannot be cast to com.itextpdf.text.pdf.codec.Base64$InputStream
I dont know what i am doing wrong.I am new to arquillian and have checked almost all the links available but still not got any solution over this..
Here is my arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<!-- Uncomment to have test archives exported to the file system for inspection -->
<!-- <engine> -->
<!-- <property name="deploymentExportPath">target/</property> -->
<!-- </engine> -->
<!-- Force the use of the Servlet 3.0 protocol with all containers, as it
is the most mature -->
<defaultProtocol type="Servlet 3.0" />
<!-- Example configuration for a remote JBoss EAP 6 instance -->
<container qualifier="jboss" default="true">
<!-- By default, arquillian will use the JBOSS_HOME environment variable.
Alternatively, the configuration below can be uncommented. -->
<configuration>
<!-- <property name="jbossHome">/opt/jboss7</property> --> <!-- <property name="managementAddress">197.242.148.253</property> <property
name="managementPort">22000</property> <property name="username"></property>
<property name="password"></property> -->
<property name="managementAddress">197.242.148.253</property>
<property name="managementPort">22000</property>
<property name="username">abc</property>
<property name="password">aabc123</property>
</configuration>
</container>
</arquillian>
This is my test class
public class ArqTest extends Arquillian{
//creates war and deploys it
#Deployment(testable = true)
public static WebArchive createNotTestableDeployment() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "USSD.war")
.addClasses(ShowConversations.class)
.addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
System.out.println("deployed");
System.out.println(war.getName());
return war;
}
#RunAsClient
#Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
public void Test() throws IOException {
URL url = new URL("http://197.242.148.253");
InputStream is = (InputStream) url.openStream();
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
String result = br.readLine();
System.out.println(result+"hello");
br.close();
}
}
Can any body provide me some help over this
Try to add at the configuration node the next property:
<property name="allowConnectingToRunningServer">true</property>
Dunno if this will solve your error but I think you need it because, if not, arquillian tries to create a new jBoss instance instead of using the remote running one.

Hibernate - ClassNotFoundException: com.mysql.jdbc.Driver

I'm trying to retrieve data from a MySQL database through Hibernate, but I'm stuck with this error:
Failed to create sessionFactory object.org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded
java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver
[...]
I use a class called DAOFactory to get the hibernate session:
public class DAOFactory {
private static boolean isInstance = false;
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
private static Session session;
private DAOFactory() throws ExceptionInInitializerError{
if( !isInstance ) {
try {
Configuration cfg = new Configuration().configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties())
.buildServiceRegistry();
sessionFactory = cfg.buildSessionFactory(serviceRegistry);
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object."+ ex);
throw new ExceptionInInitializerError(ex);
}
session = sessionFactory.openSession();
isInstance = true ;
}
}
public static DAOFactory getInstance() {
return new DAOFactory() ;
}
public Session getSession() {
return session ;
}
}
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/enigma</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
And mysql-connector-java-5.1.26-bin.jar is already in the classpath:
Does anyone see what I'm missing ?
Thanks to Reimeus for the answer. mysql-connector-java-5.1.26-bin.jar needs to be in the runtime classpath.
Run -> Run Configurations... -> Classpath -> Add external JAR.
Clean everything, try again, and the Exception is gone.
For those who use Maven: add the following dependency in pom.xml.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
or choose another version from here.
Then you can get the artifact using:
mvn dependency:resolve
(if you don't use the IDE).
Faced the same issue with mysql-connector-java-5.1.48-bin.jar. To fix this issue I changed the driver class name from
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
to
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
In some cases it can be not a suitable solution to add jar to classpath via Run -> Run Configurations... -> Classpath -> Add external JAR.
First case
When the jar file cannot be put into classpath folder, there is alternative way to load class from the another place. You just need to instantiate URLClassLoader and then invoke loadClass() on it (was mentioned here):
URLClassLoader urlCL = new URLClassLoader(new URL[] {"path_to_jar"});
Class driverClass = urlCL.loadClass("com.mysql.jdbc.Driver");
Second case
If you would like to add your class to classpath at runtime (I prefer the answer of Ranjit Aneesh here), for this purpose you may create a very simple custom class loader extending URLClassLoader with the only overridden addUrl method:
public class DynamicURLClassLoader extends URLClassLoader {
public DynamicURLClassLoader(URLClassLoader classLoader) {
super(classLoader.getURLs());
}
#Override
public void addURL(URL url) {
super.addURL(url);
}
}
Then invoke it:
URLClassLoader urlCL = (URLClassLoader) ClassLoader.getSystemClassLoader();
new DynamicURLClassLoader(urlCL).addURL("path_to_jar");
Faced the same issue with mysql-connector-java-5.1.48-bin.jar. To fix this issue I changed the driver class name from
com.mysql.cj.jdbc.Driver
to
com.mysql.jdbc.Driver
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
<scope>provided</scope>
</dependency>
I had above dependency in Maven.
The scope tag had caused the error.
Removing scope tag solved the problem.
Download mysql-connector-java-8.0.20.jar
from https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.20/
Add the jar to class path
Run -> Run Configurations... -> Classpath -> Add external JAR.

A ResourcePool could not acquire a resource from its primary factory or source

I'm trying to connect to a database in Java, using jdbcTemplate and I'm gettin the error below. I have Googled for a long time and all solutions I found didn't solve my problem. I tried several different DBs (both SQLServer and MySQL) and none worked.
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/promotion-handler-admin] threw exception [Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!] with root cause
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
...
This is my properties file:
app.driverClassName=net.sourceforge.jtds.jdbc.Driver
app.url=jdbc:sqlserver://myUrl:port;databaseName=my_database
app.username=myUsername
app.password=myPassword
webapp/WEB-INF/applicationContext-database.xml:
<beans:bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<beans:property name="driverClass" value="${app.driverClassName}" />
<beans:property name="jdbcUrl"
value="${app.url}" />
<beans:property name="user" value="${app.username}" />
<beans:property name="password" value="${app.password}" />
<beans:property name="acquireIncrement" value="5" />
<beans:property name="idleConnectionTestPeriod" value="600" />
<beans:property name="maxPoolSize" value="10" />
<beans:property name="maxStatements" value="5" />
<beans:property name="minPoolSize" value="3" />
<beans:property name="preferredTestQuery" value="select 1 from DUAL" />
</beans:bean>
<!-- TRANSACTION_MANAGERS -->
<!-- See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html -->
<!-- Default -->
<beans:bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
DAO class:
#Repository
public class CampaignDAO {
private JdbcTemplate jdbcTemplate;
#Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public List<Campaign> getCampaignList() {
Long start = System.currentTimeMillis();
List<Campaign> queryList;
try {
queryList = jdbcTemplate.query("SELECT * FROM campaign", new RowMapper<Campaign>() {
public Campaign mapRow(ResultSet rs, int line) throws SQLException {
Campaign campaign = new Campaign();
campaign.setId(rs.getLong("id"));
campaign.setExtraInfo(rs.getString("extra_info"));
campaign.setBeginTime(rs.getDate("begin_time"));
campaign.setEndTime(rs.getDate("end_time"));
return campaign;
}
});
} finally {
...
}
return queryList;
}
For anyone that finds this question in the future. What I was doing wrong was that I was using the jtds driver and I forgot to add that in the url. So in my properties file what I should have done was:
app.url=jdbc:jtds:sqlserver://myUrl:port;databaseName=my_database
For anyone that finds this question in the future.
This can also be caused by a missing database driver.
In my case I was using the maven-shade-plugin with the minimizeJar option set. This - of course - was throwing away the jtds driver because it is not directly referenced anywhere.
This can be fixed as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<!-- Make sure jtds is included. -->
<artifact>net.sourceforge.jtds:jtds</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.sf</exclude>
<exclude>META-INF/*.dsa</exclude>
<exclude>META-INF/*.rsa</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
In my case the problem was related with version mismach between MySQL and mysql-connector-java. After few days of headache I took out my ComboPooledDataSource module in a separate clean project and tried to connect with it to MySQL. However, I got stacktrace (unfortunatly I forgot what exactly were there), with which I understood that the problem is related with versions.
This message can also be displayed, if, like me, you run your application with the Maven plugin for Tomcat:
mvn clean install tomcat7:run
and you have a provided scope element in your Maven dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
<scope>provided</scope>
</dependency>
The provided scope will prevent the connector from being part of the war archive and the Tomcat plugin will find no connector to establish the database connection.
Simply removing the provided scope from the dependency solves the issue.
I got this problem on c3p0 0.9.5-pre6 with mchange-commons-java 0.2.6.3. After downgrading to c3p0 0.9.5-pre5 and mchange-commons-java 0.2.6.2, the problem disappears.

Form too Large Exception

When I send a large file using a post request the system shows an exception:
java.lang.IllegalStateException: Form too large1105723>200000
at org.mortbay.jetty.Request.extractParameters(Request.java:1404)
at org.mortbay.jetty.Request.getParameter(Request.java:749)......
When I search help for this in Google they give some help e.g.,
webappcontext.setMaxFormContentSize(5000000);
I am using this code but the problem is not solved
Also I am using the code
jettyServer.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", 5000000);
But no result
Note:-I am using Jetty-6.1.0
Try setting System properties via jetty.xml
<Call class="java.lang.System" name="setProperty">
<Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
<Arg>500000</Arg>
</Call>
ok you can configure it from your web app
Add WEB-INF/jetty-web.xml file in your web application
and configure the parameter in that file:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure id="WebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="maxFormContentSize" type="int">600000</Set>
</Configure>
Document
Version 7 or Higher
Since version 7, Jetty's classes have moved to a different package. You must replace org.mortbay... with org.eclipse... (Thanks to David for his comment).
import org.mortbay.jetty.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", -1);
This code works on jetty 6.0.2 which I'm using.
The size of "-1" means the form has no limit I tryed to post a form large 20,000,000 bytes and I had no problem.
For eclipse releases of Jetty(jetty 7) you have to use the following code:
import org.eclipse.jetty.server.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);
Unfortunately, I'm not able to make any changes to jetty.xml, so instead I simply set some options to adjust the maxFormContentSize like so:
JVM_OPTS="$JVM_OPTS -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000"
This exists in the shell script that we use to launch our instance of Solr.
More documentation on form size: http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size
I came across this problem too (running Jetty embedded in another application, so I'm not using jetty.xml).
I used the setMaxFormContentSize method on the ContextHandler class, which fixed the "form too large" exception. (See http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty#Setting_a_ServletContext for an example of creating/using a context handler).
<!-- Development Jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
<webApp>
<contextPath>/${project.build.finalName}</contextPath>
</webApp>
<systemProperties>
<systemProperty>
<name>org.eclipse.jetty.server.Request.maxFormContentSize</name>
<value>10485760</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
Work for jetty 8 in maven plugin
webappcontext.getServletContext().getContextHandler() .setMaxFormContentSize(10000000);
I use jetty 9.2.3.v20140905, and i fixed the problem use the follow:
confiure pom.xml
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.3.v20140905</version>
<configuration>
<jettyXml>
src/main/resources/jetty/jetty.xml
</jettyXml>
</configuration>
</plugin>
configure jetty.xml
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
<Arg>-1</Arg>
</Call>
</Configure>
Depending on how old your Jetty Version is you are using (in my case jetty-5.1.14 embedded in Eclipse Equinox), it also could be that the property needs to be org.mortbay.http.HttpRequest.maxFormContentSize
From: org.mortbay.http.HttpRequest
/**
* Max size of the form content. Limits the size of the data a client can push at the server.
* Set via the org.mortbay.http.HttpRequest.maxContentSize system property.
*/
public static int __maxFormContentSize = Integer.getInteger(
"org.mortbay.http.HttpRequest.maxFormContentSize", 200000).intValue();
So you need to do something like this in your application on startup to set the value:
System.setProperty("org.mortbay.http.HttpRequest.maxFormContentSize", "10000000");
None of the above Solution worked for me ,
So in order to make this work I set the system property before creating the server, rather then setting it as server attribute
System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "500000000");
Server server = ServerFactory.createServer(host, port, contextPath, war);
I ran into a similar issue on ActiveMQ so i had to edit the jetty.xml and add
<property name="maxFormContentSize" value="-1" />
to the handler property.
from:-
<property name="handler">
<bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<property name="contextPath" value="/admin" />
<property name="resourceBase" value="${activemq.home}/webapps/admin" />
<property name="logUrlOnStart" value="true" />
</bean>
to
<property name="handler">
<bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<property name="contextPath" value="/admin" />
<property name="resourceBase" value="${activemq.home}/webapps/admin" />
<property name="logUrlOnStart" value="true" />
<property name="maxFormContentSize" value="-1" />
</bean>
If you use jetty in embedded mode,try this.
ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletHandler.setMaxFormContentSize(1024*1024*1024);//size you want to allow.
I use Spring boot and set server.jetty.max-http-post-size: maxSize in application.properties to fix it.
server.jetty.max-http-post-size: 500000
set in jetty/webapps -> configure .xml (e.g jetty-web.xml) file
"-1" for unlimited content
<Set name="maxFormContentSize" type="int">600000</Set>
OR
<Set name="maxFormContentSize" type="int">-1</Set>
Possibly because of changes in Jetty since version 7, but I only had success like so:
in jetty-web.xml, add the below to the Server object (1000000 is an example size, obv)
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
<Arg>1000000</Arg>
</Call>
full file might look something like mine
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
<Arg>1000000</Arg>
</Call>
<Ref id="DeploymentManager">
<Call id="webappprovider" name="addAppProvider">
<Arg>
(...)
ref http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size
If you're running from eclipse/spring add the below to vm arguments
-Dorg.mortbay.jetty.Request.maxFormContentSize=-1
Start jenkins by adding command line argument
-Dorg.eclipse.jetty.server.Request.maxFormContentSize=500000
i.e java -Dorg.eclipse.jetty.server.Request.maxFormContentSize=500000 -jar jenkins.war
ActiveMQ:
The problem here is with Jetty, on which ActiveMQ is based. You can find more details here, documentation
Solution is in apache-activemq-5.9.0/bin/win64/wrapper.conf file, add the following line a after b (refer below).
a: wrapper.java.additional.16=-Dorg.eclipse.jetty.server.Request.maxFormContentSize=1000000
b: wrapper.java.additional.15=-Djava.security.auth.login.config=%ACTIVEMQ_CONF%/login.config
If you are running on a 32 bit computer, then please add the same line in apache-activemq-5.9.0/bin/win32/wrapper.conf.
Happy Coding..

Categories

Resources