Im new to JSF 2. My question is related to BalusC's answer to this question jsf2 ajax update parts based on request parameters I tried the kickstart code BalusC posted and I encountered an EL parsing error:
/nameofpage.xhtml #12,64 rendered="#{bean.panels.contains('u1')}"
Error Parsing: #{bean.panels.contains('u1')}
I guess that this is caused because I'm not running a Servlet 3.0 / EL 2.2 capable container with a /WEB-INF/web.xml declared as per Servlet 3.0 spec. I'm using Tomcat 6.
BalusC suggested in his answer to create a custom EL function. But how do I accomplish this using a custom EL function? Or can this be fixed by just configuring certain parts of my project?
Below is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
First create a final class with a public static method which does exactly the job you want:
package com.example;
import java.util.Collection;
public final class Functions {
private Functions() {
// Hide constructor.
}
public static boolean contains(Collection<Object> collection, Object item) {
return collection.contains(item);
}
}
Then define it as a facelet-taglib in /WEB-INF/functions.taglib.xml:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://example.com/functions</namespace>
<function>
<function-name>contains</function-name>
<function-class>com.example.Functions</function-class>
<function-signature>boolean contains(java.util.Collection, java.lang.Object)</function-signature>
</function>
</facelet-taglib>
Then familarize Facelets with the new taglib in the existing /WEB-INF/web.xml:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/functions.taglib.xml</param-value>
</context-param>
(note: if you already have the javax.faces.FACELETS_LIBRARIES definied, then you can just add the new path semicolon separated)
Then define it in the Facelets XHTML file as new XML namespace:
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:func="http://example.com/functions"
...
>
Finally you can use it as intended:
rendered="#{func:contains(bean.panels, 'u1')}"
As a completely different alternative, you can also include JBoss EL in your project. It works on Tomcat 6.0 and you'll be able to invoke non-getter methods in EL. Drop jboss-el.jar file in /WEB-INF/lib and add the following to your web.xml:
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
Since EL 2.2 there's another approach: create an #ApplicationScoped bean with methods in turn referring to those static functions. See also a.o. Utility methods in application scoped bean.
Related
I have configured below c3p0 settings in my project. But while executing the jar file, I have found "no writeable property". Kindly advise me how to solve this.
Configuration:-
dataSource.setClassName("com.mchange.v2.c3p0.ComboPooledDataSource");
dataSource.getDriverProperties().setProperty("driverClass", properties.getProperty("jdbc.driver"));
dataSource.setUniqueName(properties.getProperty("jbpm.uniquename"));
dataSource.setMaxPoolSize(Integer.parseInt(properties.getProperty("jbpm.max")));
dataSource.setAllowLocalTransactions(true);
dataSource.getDriverProperties().setProperty("URL", properties.getProperty("jbpm.url"));
dataSource.getDriverProperties().setProperty("user", properties.getProperty("jbpm.username"));
dataSource.getDriverProperties().setProperty("password", properties.getProperty("jbpm.password"));
dataSource.getDriverProperties().setProperty("acquireIncrement", properties.getProperty("jdbc.acquireincrement"));
dataSource.getDriverProperties().setProperty("preferredTestQuery", properties.getProperty("jdbc.preferredtestquery"));
dataSource.getDriverProperties().setProperty("breakAfterAcquireFailure", properties.getProperty("jdbc.breakafteracquirefailure"));
dataSource.getDriverProperties().setProperty("acquireRetryAttempts", properties.getProperty("jdbc.acquireretryattempts"));
dataSource.getDriverProperties().setProperty("acquireRetryDelay", properties.getProperty("jdbc.acquireretrydelay"));
dataSource.getDriverProperties().setProperty("loginTimeout", properties.getProperty("jdbc.logintimeout"));
dataSource.getDriverProperties().setProperty("idleConnectionTestPeriod", properties.getProperty("jdbc.dleconnectiontestperiod"));
dataSource.getDriverProperties().setProperty("maxPoolSize", properties.getProperty("jdbc.maxpoolsize"));
dataSource.getDriverProperties().setProperty("minPoolSize", properties.getProperty("jdbc.minpoolsize"));
Error log:-
bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named java:jboss/datasources/DS
at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:80)
at com.tnq.messageq.DataSource.init(DataSource.java:60)
at com.tnq.messageq.IntegrationConsumer.main(IntegrationConsumer.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: bitronix.tm.utils.PropertyException: no writeable property 'URL' in class 'com.mchange.v2.c3p0.ComboPooledDataSource'
at bitronix.tm.utils.PropertyUtils.getSetter(PropertyUtils.java:318)
at bitronix.tm.utils.PropertyUtils.setDirectProperty(PropertyUtils.java:217)
at bitronix.tm.utils.PropertyUtils.setProperty(PropertyUtils.java:83)
at bitronix.tm.resource.common.XAPool.createXAFactory(XAPool.java:314)
at bitronix.tm.resource.common.XAPool.<init>(XAPool.java:63)
at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:89)
at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:76)
Thanks for looking into this..
ComboPooledDataSource has a property named JdbcUrl.Hence you can try using it instead of url.
dataSource.getDriverProperties().setProperty("jdbcUrl, properties.getProperty("jbpm.url"));
Hope this helps.
URL issue has been resolved. But after that I have found 'unable to find a bound object at name'. Please check and advise me.
For c3p0 migration, I have changed 'PoolingDataSource' to 'ComboPooledDataSource', after that I have configured the below setting in the init method.
Code:-
public static void init() throws Exception {
setPropertyMap();
properties = new Properties();
FileInputStream fileInput = new FileInputStream(new File("/home/data/settings."+map.get(System.getenv("spring_profiles_active"))+".properties"));
properties.load(fileInput);
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass("com.mchange.v2.c3p0.ComboPooledDataSource");
dataSource.setJdbcUrl(properties.getProperty("jbpm.url"));
dataSource.setUser(properties.getProperty("jbpm.username"));
dataSource.setPassword(properties.getProperty("jbpm.password"));
dataSource.setAcquireIncrement(Integer.parseInt(properties.getProperty("jdbc.acquireincrement")));
dataSource.setAcquireRetryDelay(Integer.parseInt(properties.getProperty("jdbc.acquireretrydelay")));
dataSource.setIdleConnectionTestPeriod(Integer.parseInt(properties.getProperty("jdbc.dleconnectiontestperiod")));
dataSource.setMaxPoolSize(Integer.parseInt(properties.getProperty("jdbc.maxpoolsize")));
dataSource.setMinPoolSize(Integer.parseInt(properties.getProperty("jdbc.minpoolsize")));
}
Error Log:-
Caused by: org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143)
at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:51)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:90)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906)
... 68 more
Caused by: javax.naming.NameNotFoundException: unable to find a bound object at name 'java:jboss/datasources/DS'
at bitronix.tm.jndi.BitronixContext.lookup(BitronixContext.java:83)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
... 75 more
JarClassLoader: Warning: com/mchange/Debug.class in lib/c3p0-0.9.5.1.jar is
persistence.xml:-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="org.jbpm.persistence.jpa.testcon">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/DS</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
<!--<property name="hibernate.hbm2ddl.auto" value="validate" />-->
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
web.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Origin, X-Requested-With, Content-Type</param-value>
</init-param>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Date</param-value>
</init-param>
</filter>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>com.test.hibernate.HibernateFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- To be used only when we need to deploy multiple wars in one container -->
<env-entry>
<env-entry-name>spring.profiles.active</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>testuat</env-entry-value>
</env-entry>
</web-app>
Main program calls init method.
public static void main(String[] argv) {
try {
DataSource.init();
applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
..........
}
catch (Exception e) {
e.printStackTrace();
log.error(e.getStackTrace());
}
}
Thanks for looking into this..
I tried to reproduce the same example in this question using JSF 2.2.6 and Tomcat 7.0: JSF navigation rule doesn't work on form submit, I also read the JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output and respected all the recommandations provided by BalusC's answer, then I also consulted this question JSF 2 with HTML pages instead of XHTML because I want to use only .html files (I know i can use .xhtml but i need to understand the reason why this is not working).
I tried to make it simple as much as possible so any one could reproduce that:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.html</param-value>
</context-param>
</web-app>
faces-config.xml (Navigation rules are not needed as it's provided dynamicly):
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<navigation-rule>
<display-name>index.html</display-name>
<from-view-id>/index.html</from-view-id>
<navigation-case>
<from-outcome>welcomePage</from-outcome>
<to-view-id>/welcome.html</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
BeanFilm.java:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class BeanFilm implements Serializable {
private String recherche = new String();
public String getRecherche() {
return recherche;
}
public void setRecherche(String recherche) {
this.recherche = recherche;
}
public String doRecherche() {
return "welcomePage";
}
}
index.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Accueil</title>
</head>
<body jsf:id="body" >
<h1>Plain HTML5 with JSF</h1>
<form jsf:id="form">
<input type="text" jsf:id="recherche" jsf:value="#{beanFilm.recherche}"/>
<input type="submit" jsf:value="Submit" jsf:id="searchButton" jsf:action="#{beanFilm.doRecherche}"/>
</form>
<ui:debug/>
</body>
</html>
welcome.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Accueil</title>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
The issue:
The exact problem is that when i click on the submit the method BeanFilm#doRecherch() is never called (using a breakpoint) and i can't really understand why? another information wich may be useful, is that in HTML code source attributes are still like jsf:id="searchButton"does this mean that the HTML wasn't generated?
So I'm trying to update a JSP project that my company has from PrimeFaces 4.0 to PrimeFaces 5.0, and I'm getting a NullPointerException from org.primefaces.context.PrimeFacesContext.release(PrimeFacesContext.java:26) when I don't implement my own Authorization Filter. When I do, it comes on the line filterChain.doFilter(servletRequest,servletResponse);
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.LEGACY_WIDGET_NAMESPACE</param-name>
<param-value>true</param-value>
</context-param>
<!--<context-param>-->
<!--<param-name>primefaces.CLIENT_SIDE_VALIDATION</param-name>-->
<!--<param-value>true</param-value>-->
<!--</context-param>-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/login.xhtml</location>
</error-page>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
<!-- <filter>
<filter-name>authFilter</filter-name>
<filter-class>web.AuthFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>authFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>-->
</web-app>
and my faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.1">
</faces-config>
and my AuthFilter.java, which causes the error when the last two servlet-mappings of my web.xml file are uncommented (and the contents of doFilter are un-commented):
package web;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class AuthFilter implements Filter {
#Override
public void init(FilterConfig filterConfig) throws ServletException {
}
#Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
// if (servletRequest instanceof HttpServletRequest) {
// HttpServletRequest req = ((HttpServletRequest) servletRequest);
// if (req.getRequestURL().toString().contains("/application/")) {
// BusinessLayer bl = (BusinessLayer) req.getSession().getAttribute("businessLayer");
// if (bl == null || bl.getClient() == null) {
// ((HttpServletResponse) servletResponse).sendRedirect("/login.html");
// }
// }
// }
// filterChain.doFilter(servletRequest, servletResponse);
}
#Override
public void destroy() {
}
}
It should probably be noted here that the above code works fine un-commented with PrimeFaces 4.0
Turns out my problem was caused by the Maven download of PrimeFaces; downloading straight from their site and manually putting the .JAR into my WEB-INF/lib folder fixed everything. They really need to fix that.
In my GWT project the servlets are defined in war/WEB-INF/web.xml file; but when I run it Jetty gives a ClassNotFoundException for every one of them; like the one below:
java.lang.ClassNotFoundException: tr.gov.gib.mhdb.vimer.vimerapp.server.CSGWTDownloadServletImpl at
java.lang.ClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:352) at
org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:337) at
org.mortbay.util.Loader.loadClass(Loader.java:91) at
org.mortbay.util.Loader.loadClass(Loader.java:71) at
org.mortbay.jetty.servlet.Holder.doStart(Holder.java:73) at
org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:233) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616) at
org.mortbay.jetty.servlet.Context.startContext(Context.java:140) at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220) at
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513) at
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448) at
com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.
java:463) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at
org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at
org.mortbay.jetty.Server.doStart(Server.java:222) at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39) at
com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:667) at
com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:500) at
com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1055) at
com.google.gwt.dev.DevModeBase.run(DevModeBase.java:804) at
com.google.gwt.dev.DevMode.main(DevMode.java:309)
edit: There is also this: javax.servlet.UnavailableException: tr.gov.gib.mhdb.vimer.vimerapp.server.CSGWTDownloadServletImpl
My web.xml goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>generalService</servlet-name>
<servlet-class>tr.gov.gib.mhdb.vimer.vimerapp.server.GeneralServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>fetchTree</servlet-name>
<servlet-class>tr.gov.gib.mhdb.vimer.vimerapp.server.MyTreeServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>generalService</servlet-name>
<url-pattern>/tr.gov.gib.mhdb.vimer.vimerapp.Vimer/generalService</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fetchTree</servlet-name>
<url-pattern>/tr.gov.gib.mhdb.vimer.vimerapp.Vimer/fetchTree</url-pattern>
</servlet-mapping>
</web-app>
You might have forgot to add #RemoteServiceRelativePath("name") in your Service class, where name is the same name as the one in <servlet-name>.
I have little experience with configuring Spring and I'm having a hard time doing so. What I'm trying to do, is successfully map a url to a Controller using annotations. Furthermore, I'd like to have acces to the HttpRequest and optionally the HttpResponse. This is because I'd like to use Jackson to write and parse json directly to/from the bytestreams. Now I know Spring has JSON views using Jackson built in, but I'd like to get a decent foothold first as now I can't seem to get the mapping properly configured.
web.xml
<display-name>Kerris 2</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/*-config.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
app-confix.xml
<context:annotation-config />
<context:component-scan base-package="servlet" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
DayController
package servlet;
#Controller
#RequestMapping("/days/*")
public class DayController {
private DayDAO dayDao;
#RequestMapping(method = RequestMethod.GET)
public #ResponseBody void test(HttpResponse response){
System.out.println("Days GET");
}
#RequestMapping(method = RequestMethod.POST)
public #ResponseBody void test2(HttpRequest request, HttpResponse response){
System.out.println("Days POST");
}
public void setDaydao(DayDAO dayDao) {
this.dayDao = dayDao;
System.out.println("Days Dao assigned");
}
}
When I look at my server log I can see the following lines in there
INFO: Mapped URL path [/days/*] onto handler 'dayController'
INFO: Mapped URL path [/days/*.*] onto handler 'dayController'
INFO: Mapped URL path [/days/*/] onto handler 'dayController'
Also when I test the application at contextroot/ I see the standard Hello World! page. When I try contextroot/days/ I get a 404. When I try contextroot/days/test also 404. Could anybody point me at what I'm doing wrong?
Found out what I was doing wrong. As the n00b I am I didn't realize I have to specifically define a DispatcherServlet which hands the request over to the controller.
Web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/*-config.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>api</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
api-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="servlet" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
</beans>
When I try to call {contextroot}/api/days/ the request reaches the controller.