I wrote a simple application using vaadin.
#Title("PMC")
#Component("pmcVaadin")
#Scope("prototype")
public class PmcUi extends UI {
#Autowired
private ContentLayout contentLayout;
#Autowired
private TabContent tabs;
#Override
protected void init(VaadinRequest request) {
VerticalLayout mainLayout = new VerticalLayout();
// mainLayout.addComponent(contentLayout.getContent());
mainLayout.addComponent(tabs.createTab("Projects", "Developers"));
mainLayout.setSizeFull();
setContent(mainLayout);
}
}
Tabs - my TabContent component, extended from TabSheet.
But when I click on the tab I've got an error:
Communication problem Take note of any unsaved data, and click here or press ESC to continue. *UIDL could not be read from server. Check servlets mappings. Error code: 404*
My web.xml looks like this
<?xml version="1.0"?>
<web-app 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"
version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/pmc-web-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>another-pmc-servlet</servlet-name>
<servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
<init-param>
<param-name>beanName</param-name>
<param-value>pmcVaadin</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>pmc-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>another-pmc-servlet</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>pmc-servlet</servlet-name>
<url-pattern>/JSP/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/WEB-INF/jsp/*</url-pattern>
</servlet-mapping>
</web-app>
And I get access to the page using URL http://localhost:8080/pmc-web/VAADIN.
In order to resolve the problem I added mapper for /* to vaadin servlet.
<servlet-mapping>
<servlet-name>another-pmc-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Related
I'm quite new at PrimeFaces as I am migrating from IceFaces.
My IceFaces application shows with a single url, page content changes and when hitting F5, current view get refreshed, without reloading the page referred by the url.
I expect this behaviour in my Primefaces app too, but this doesn't happen, as I go back to the page referred by the url, the login page in my case.
Is this an expected behaviour?
Below the web.xml:
<web-app 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-app_4_0.xsd" version="4.0">
<display-name>oweb20-mainweb</display-name>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>none</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/extras/extras.xml</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>
<servlet-name>StickyCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.StickyCaptchaServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>250</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>75</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>StickyCaptcha</servlet-name>
<url-pattern>/stickyImg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
The faces-config.xml contains beans and navigation cases and rules, here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.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-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>SessionBean</managed-bean-name>
<managed-bean-class>com.sia.mainweb.web.SessionBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>updateManager</property-name>
<value>#{UIUpdateManager}</value>
</managed-property>
</managed-bean>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>caseHome</from-outcome>
<to-view-id>/Home.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
To navigate between pages, in actions, I use to return the case of the page I want to go, without redirecting to that page:
public String home_action() {
logger.info(BaseLogging.methodName() + getTraceEnteringUser());
String caseName;
if (userAuthenticated()) {
boolean canContinue = checkUserFingerprint();
if (canContinue) {
caseName = "caseHome";
}
} else {
caseName = "caseNotLoggedOn";
}
logger.info(BaseLogging.methodName() + getTraceExitingUser());
return this.getNavigationManager().navigateTo(caseName); //returns caseName
}
Receiving this error from console:
*org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB- INF/spring-dispatcher-servlet.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/spring-dispatcher-servlet.xml]*
That's the error I receive from:
<?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"
id="WebApp_ID" version="2.5">
<display-name>fj21-tarefas</display-name>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I doing
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
to change the default context from springmvc, but it is not working. Already took some advice here to write a servlet-name tag to the file name-context.xml convention, same error.
You should try changing the servlet name. Expected Spring web-context metadata XML file name should servletname-servlet.xml, this was expected filename till Spring 4, not sure if it is changed in spring 5.
. As your servlet name is springmvc, filename should be springmvc-servlet.xml.
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/app-name/*</url-pattern>
</servlet-mapping>
Make your web.xml look like this, taken straight from the Spring documentation:
<web-app>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I am trying to add rest api within my application so i added two servlet one for handling JSF request another for Rest API request.
web.xml
<?xml version="1.0"?>
<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"
>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>-1</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>redmond</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>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.infinite.npsc.webapi</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.infinite.npsc.webapi.CorsFilter</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
so, for example i want to call api as
http://localhost:5081/ApplicationFormFillingProcess-portlet/api/savePayment/2075-531345
but now i get an error of com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
if i changed jersey servlet url mapping from
<url-pattern>/api/*</url-pattern>
to
<url-pattern>/*</url-pattern>
i can call the api. but my images and other static contents are not loaded.
I'm trying to install Javamelody in my Spring application. I configured on localhost and can access Javamelody with URL:
http://localhost:9080/myapp/stats
Server: webSphere 7.0 and my web.xml config is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="myapp">
<display-name>myapp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:net/bull/javamelody/monitoring-spring.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
<init-param>
<param-name>monitoring-path</param-name>
<param-value>/stats</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>myapp.web.AppInit</listener-class>
</listener>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
<servlet>
<servlet-name>javascript</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>page</servlet-name>
<display-name>page</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>unificator</servlet-name>
<display-name>unificator</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>webservicesoap</servlet-name>
<display-name>webservicesoap</display-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javascript</servlet-name>
<url-pattern>/validation.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>page</servlet-name>
<url-pattern>/page/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/home/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/users/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/contacts/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>0</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
However, this config in production environment is not working. If I go to
http://app.gtrwe.dev.corp/myapp/stats
I get 404 error. Also I have servlets in my web.xml
I am looking for help on how to set this up.
It seems that IBM WebSphere may encounter the ERROR 404 if no servlet is mapped to either /* or /monitoring, as mentioned here
I want to use a REST call in Spring MVC on my webapp and return a JSON, I've tried following mkyong's tutorial on this.http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
However it isn't working, when I call
http://localhost:8080/openRepairsClient/jan.peeters#student.kdg.be
I get a 404 error.
This is my code:
#Controller
public class OpenRepairsRest {
#Autowired
private RepairService repairService;
#Autowired
private UserService userService;
#RequestMapping(value = "/openRepairsClient/{username}")
public #ResponseBody
List<Repair> openRepairsInJson(#PathVariable("username") String username) {
List<Repair> openRepairs = null;
try {
openRepairs = repairService.findOpenRepairsByClient((Client) userService.getUser(username));
} catch (UserServiceException ex) {
Logger.getLogger(OpenRepairsRest.class.getName()).log(Level.SEVERE, null, ex);
}
return openRepairs;
}
}
And yes I'm sure the username exists, otherwise I would get a userservice exception.
My web.xml file:
<web-app version="3.1" 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-app_3_1.xsd">
<!-- welcome files -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- context parameters -->
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/jsf/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
</context-param>
<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>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/mytags.taglib.xml</param-value>
</context-param>
<!-- listeners -->
<listener>
<!-- Required for Faces to kick in -->
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Load applicationContext in ServletContextListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Frontcontrollers -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/dispatcher-servlet.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<filter>
<filter-name>Authentication Filter</filter-name>
<filter-class>be.kdg.repaircafe.filters.AuthenticationFilter</filter-class>
</filter>
<!-- Mappings -->
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>be.kdg.repaircafe.servlets.LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/LogoutServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/errorpages/error.jsp</location>
</error-pag
e>
Your error is in the url, it appears that you forgot to write the project name and the word rest. Try with this url:
http://localhost:8080/SpringMVC/rest/openRepairsClient/jan.peeters#student.kdg.be
You can try it with this simplified version of your code:
#Controller
public class OpenRepairsRest {
#RequestMapping(value = "/openRepairsClient/{username}")
public #ResponseBody
List<Shop> openRepairsInJson(#PathVariable("username") String username) {
Shop exampleShop = new Shop();
exampleShop.setName("exampleName");
exampleShop.setStaffName(new String[] { username });
List<Shop> openShops = new ArrayList<Shop>();
openShops.add(exampleShop);
return openShops;
}
}
You need to put your app name in url, example: http://localhost:8080/MyApp/openRepairsClient/jan.peeters#student.kdg.be