I've written a quick GWT app with the following code:
MyTaskService
package com.google.gwt.mytasks.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("taskAction")
public interface MyTasksService extends RemoteService {
public void addTask(String title, String description);
}
web.xml
<?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>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>MyTasks.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyTasksService</servlet-name>
<servlet-class>com.google.gwt.mytasks.server.MyTasksServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyTasksService</servlet-name>
<url-pattern>/mytasks/taskAction</url-pattern>
</servlet-mapping>
</web-app>
Module.gwt.xml
<module rename-to='mytasks'>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
<entry-point class="com.google.gwt.mytasks.client.MyTasks"/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
Every time I click on the submit button I get the following error:
com.google.gwt.user.client.rpc.StatusCodeException: 404
Error 404 NOT_FOUND
HTTP ERROR: 404NOT_FOUND
RequestURI=/com.google.gwt.mytasks.MyTasks/taskActionPowered by
Jetty://
The problem seems to be that GWT isn't renaming the module before publishing, i you have a look at RemoteServiceRelativePath annotation documentation it defines the servlet path as GWT.getModuleBaseURL() + value(), being value() the value given to the annotation. One easy solution that might work would be to define the servlet mapping at the path the module is looking at.
Instead of:
<servlet-mapping>
<servlet-name>MyTasksService</servlet-name>
<url-pattern>/mytasks/taskAction</url-pattern>
</servlet-mapping>
Use:
<servlet-mapping>
<servlet-name>MyTasksService</servlet-name>
<url-pattern>/com.google.gwt.mytasks.MyTasks/taskAction</url-pattern>
</servlet-mapping>
Related
I have read this SO question, which suggests to add index.html, and I've done that, in addition to adding it in my <welcome-file-list>. The error still persists.
I am running TomEE 8.0.0-M1 with Java EE8 (and thus JSF 2.3), Java 11, and am running this through Intellij.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Project Structure
Web Facet
Error
Type: Status Report
Message: Not found
Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
URLs I have tried
http://localhost:8080
http://localhost:8080/MeetPatient
http://localhost:8080/MeetPatient/web
What should I do in order to for index.xhtml to be found?
File uploads are working for small files (under the default 2MB limit), but will not work for larger files. I'm using JSF on Tomcat 8.0 and have modified my web.xml appropriately to increase the limit. I've put breakpoints in the constructor of javax.servlet.MultipartConfig so I can see it reads the web.xml configuration. When the action is called though, it defaults back to the default of 2MB (specifically in Request.parseParts(...) the wrapper's config is null, so uses the connector's default).
WEB.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<multipart-config>
<max-file-size>-1</max-file-size>
<max-request-size>-1</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>
home.xhtml
<h:form id="contentFormId" enctype="multipart/form-data">
...
<h:inputFile style="display:none;" id="fileUpload" value="#{bean.uploadItem}">
</h:inputFile>
<h:commandButton id="browse" action="#{bean.fileUploadListener}" value="Add Files" onclick="$('#contentFormId-fileUpload').click()">
</h:commandButton>
...
</h:form>
context.xml
<?xml version="1.0" encoding="utf-8"?>
<Context allowCasualMultipartParsing="true"
...
</Context>
Updated
After creating a simplified application, it appears that the Rewrite library is causing a different container wrapper to be used in the request.
Without Rewrite:
Request.getWrapper() returns StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TestWeb].StandardWrapper[Faces Servlet]
With Rewrite #URLMapping annotation:
Request.getWrapper() returns StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TestWeb].StandardWrapper[default]
So it seems that I need to configure this application's default container similar to how Faces is configured, or find a way to get Rewrite to delegate to the Faces Servlet container. Editing the maxPostSize in Tomcat is an option (change the default), but not one I want to take if I can avoid it.
I don't like this solution, but it serves my purposes for now. It seems like it should default to the FacesServlet's settings because that's the final destination after rewrite.
My solution was to move (or copy) the multipart-config setting to the default servlet in web.xml:
<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>default</servlet-name>
<multipart-config>
<max-file-size>-1</max-file-size>
<max-request-size>-1</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>
I created an Enterprise application, with an EJB and a war module. I added some XHTML files in the Web Pages folders organized like this:
Web Pages
WEB-INF
web.xml
protected
testNavigation2.xhtml
testNavigation.xhtml
I also configured the Faces Servlet with the url-pattern *.xhtml.
Having deployed my application I can access without problems the URL: host/projectname/testNavigation.xhtml. The testNavigation.xhtml file is shown.
But I can't access: host/projectname/protected/testNavigation2.xhtml. Using that URL results in:
HTTP Status 404 - /protected/testNavigation2.xhtml Not Found in
ExternalContext as a Resource
The server console (I'm using Glassfish 4.1) reports:
Warning: Context path from ServletContext: /meteocal-project-war
differs from path from bundle: meteocal-project-war Warning:
JSF1064: unable to find or serve resource,
/protected/testNavigation2.xhtml.
How can I make xhtml files accessible from subfolders? I did actually a lot of research on this and judging from what I've read the behaviour I'm experimenting seems weird.
I don't think this is needed, but I'll post the content of web.xml in case I'm wrong:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>protected/testNavigation2.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Thanks for your attention,
I'll greatly appreciate any help you can give
This answer has been posted by Tiny in a comment. I report that here to mark it as an answer.
You might have forgotten to deploy the application after you created the folder named protected having that XHTML file - testNavigation2.xhtml under the application root. Redeploy the application all over again from scratch.
NetBeans basically requires a hard deploy whenever you create folders in your application. If it were to happen even after you made a hard deploy, scan the file system on your operating system to see, if there is a folder named protected having the said XHTML file in the deployed WAR file. The symptom basically is only that the newly created folder protected itself along with the mentioned XHTML file is unavailable in the deployed WAR file.
by Tiny
Well, when i try to access my page in this way:
http://XXX.XXX.XXX.XX:8080/Odontonew
I got the error:
type Status report
message /Odontonew/
description The requested resource (/Odontonew/) is not available.
But if i try to acces in this way:
http://XXX.XXX.XXX.XX:8080/Odontonew/index.jon
This works fine. So i have sure my problem is in web.xml but i don't know where, see bellow my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd"
id="WebApp_ID">
<display-name>Odontonew</display-name>
<!-- Configuracao do Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Configuracao DO JSF -->
<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>*.jon</url-pattern>
</servlet-mapping>
<!-- Servlet para Direcionar imagens -->
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>br.com.odontonew.util.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/pictures/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jon</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>primefaces.THEME</param-name>
<param-value>afterwork</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>pictureDirectory</param-name>
<param-value>${user.home}/webapp/Odontonew/pictures/</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>${user.home}/webapp/Odontonew/tmp/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
In root folder of my project i have the page "index.xhtml", but i wanna access the project with the path: http://XXX.XXX.XXX.XX:8080/Odontonew (without the index.jon or index.html).
It's caused because your <welcome-file>index.jon</welcome-file> does not physically exist in the root folder. There's only an index.xhtml. When a folder is being requested in the URL like /, then the servletcontainer will first check if the physical file as specified in <welcome-file> is present, so that it can decide whether to continue the request or return a 404. The servletcontainer does at that point not take the mappings of any registered servlets into account. In your particular case, index.jon is a virtual URL and does not represent a physically existing file, hence the 404.
You can solve this by placing an empty but physically existing index.jon file next to index.xhtml file in the same folder. This way you fool the servletcontainer that the index.jon really exists and then it will continue the request which will ultimately hit the FacesServlet who serves the index.xhtml.
An alternative is to change the FacesServlet URL pattern of *.jon to *.xhtml so that you never need to fiddle with virtual URLs. If you really need it to be *.jon for some unclear reason, then again another alternative is to rename the physical file from index.xhtml to index.jon and set javax.faces.DEFAULT_SUFFIX context parameter to .jon.
Note that the concrete problem is essentially unrelated to JSF. It's related to basic servlets. You'd have exactly the same problem when using a different kind of servlet.
See also:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
As stated in many answers on the topic, welcome file entry represents a physical file path relative to the current URL path ending with /. As you most plausibly don't have any index.jon file in your root directory, you get the error.
So, you can either create a physical file index.jon in you root folder (don't worry, the one rendered will be index.xhtml), or simply switch to *.xhtml URL pattern to get rid of this unnecessary stuff altogether.
I'm having trouble using RichFaces 3.3.2 and Facelets 1.1.14 under Weblogic 10.3.4 and 10.3.5 (aka 11g). I have an xhtml file with the expression #{empty messages}, and on the console I get the following exception:
SEVERE: Error Rendering View[/index.xhtml]
javax.el.ELException: //media/DADOS/data/java/wl1034/user_projects/domains/wlrep1034/autodeploy/SimpleJSFa/index.xhtml:
ELResolver cannot handle a null base Object with identifier 'messages'
at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
at com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
The messages variable really does not exist at this point, but that's why I used an empty statement. It works fine on Tomcat 5.5 and Websphere 6.1.
The complete xhtml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich">
<body>
<h1>Bean Message: #{TestBean.greeting}</h1>
Are there messages pending? #{messages == null || empty messages} .
</body>
</html>
TestBean.java:
package eg.bean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
public class TestBean {
private String greeting = "Hello, World!";
public TestBean() {
// Uncommenting the following line puts an object in the session, under the
// key "messages", and then the page displays properly.
// addSomeMessages();
}
public String getGreeting() {
return greeting;
}
public void setGreeting( String message ) {
this.greeting = message;
}
public void addSomeMessages() {
// This method is not being called for this example, but this is where
// I would add a list of messages to be displayed to the user, and place it
// on session scope (not advisable, I know, but bear with me)
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
List<String> messages = new ArrayList<String>();
messages.add( "A message.");
request.getSession().setAttribute( "messages", messages );
}
}
I can only guess that somehow a different implementation of ELResolver is being used by Weblogic, which could be caused by classloader conflicts, but I've been fiddling with it for a while and am getting nowhere.
I have the following jars in WEB-INF/lib:
commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
jsf-api.jar
jsf-facelets.jar
jsf-impl.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
SimpleJSF.jar
My faces-config.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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_1_2.xsd">
<managed-bean>
<managed-bean-name>TestBean</managed-bean-name>
<managed-bean-class>eg.bean.TestBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<resource-bundle>
<base-name>RepositoryBundle</base-name>
<var>bundle</var>
</resource-bundle>
</application>
</faces-config>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<!-- Use Documents Saved as *.xhtml -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</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.disableVersionTracking</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/sense.taglib.xml</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>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sensedia.repository.web.startup.SensediaFaceletViewHandler</param-value>
</context-param>
<context-param>
<param-name>com.prime.facestrace.DISABLE_TRACE</param-name>
<param-value>false</param-value>
</context-param>
<!-- ********************** SERVLETS ********************** -->
<!-- Faces Servlet -->
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- ********************** FILTERS ********************** -->
<filter>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>FacesServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
EDIT: I was deploying as a standalone war file, but I also tried packaging as an EAR module. Problem persists. When deploying as an EAR file I added a weblogic.xml jar besides my own web.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
I also added an application.xml to the ear's META-INF directory, simply referencing the war module. I also added a weblogic-application.xml file besides that one, to further specify classloader isolation:
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<application-param>
<param-name>webapp.encoding.default</param-name>
<param-value>UTF-8</param-value>
</application-param>
<prefer-application-packages>
<package-name>org.mozilla.*</package-name>
<package-name>javax.jws.*</package-name>
<package-name>com.sun.*</package-name>
<package-name>javax.xml.rpc.*</package-name>
<package-name>javax.xml.soap.*</package-name>
</prefer-application-packages>
</weblogic-application>
Actually, the EL implementation is supposed to be provided by the container itself. A classpath conflict would only lead to class/method definition errors like LinkageError, NoClassDefFoundError, AbstractMethodError, etc. This is not the case here, but this indeed look much like a bug in Weblogic's EL implementation. Since I don't use WebLogic, I can't test/confirm this.
You could try to use the following expression instead
#{messages == null || empty messages}
Or you could try to totally replace the EL implementation, for example the JBoss one (which allows passing method arguments). Just drop jboss-el.jar in /WEB-INF/lib and add the following to the web.xml
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
It turns out to be a classloader issue after all. I had packaged the JSF 1.2 jars into my application's WEB-INF/lib folder:
jsf-api.jar
jsf-impl.jar
Weblogic 10.3.x has its own implementation, located in MW_HOME/wlserver/common/deployable-libraries/jsf-1.2.war (and the 2.0 version in jsf-2.0.war). I replaced the above jars in my own webapp with the following jars from jsf-1.2.war!/WEB-INF/lib:
glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar
wls.jsf.di.jar
I also had to remove all the packages in the prefer-application-packages element in weblogic.xml:
<!--
<prefer-application-packages>
<package-name>org.mozilla.*</package-name>
<package-name>javax.jws.*</package-name>
<package-name>com.sun.*</package-name>
<package-name>javax.xml.rpc.*</package-name>
<package-name>javax.xml.soap.*</package-name>
</prefer-application-packages>
-->
After this, the page displayed correctly. (It did cause other problems, such as a ViewExpiredException on every page, but that's another problem, I think...)