Adding faces-config.xml to Web Project Result to RES_NOT_FOUND - google-app-engine

It is quite strange when I add faces-config.xml file in WEB-INF in my project it cause me an error "RES_NOT_FOUND"
note: I have try <link type="text/css" rel="stylesheet" href="style.css" />
and it's working fine without the faces-config.xml. I also try to move it inside resources folder
I have try to use this code to add a css file for my .xhtml page
<h:head>
<h:outputStylesheet name="styles.css" />
</h:head>
it will generate the following
<link type="text/css" rel="stylesheet" href="RES_NOT_FOUND">
I am using JSF 2.2 + Google App Engine as I follow the tutorial from this site
http://java.wildstartech.com/Java-Platform-Enterprise-Edition/JavaServer-Faces/javaserver-faces-22/configuring-jsf-22-to-run-on-the-google-app-engine-using-eclipse
the tutorial went good except until I try to import a external files like .css, .js, and image files; and when I access it directly from the link like localhost:8080/style.css the css file will display correctly.
here is my code
the web.xml
<?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">
<display-name>
My App
</display-name>
<description>
Template JSF 2.2 application configured to run on the Google
AppEngine for Java.
</description>
<!-- ***** Designate client-side state saving. ***** -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<!-- Set the default suffix for JSF pages to .xhtml -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Disable use of threading for single-threaded environments such as the Google AppEngine. -->
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</param-value>
<!-- <description>
When enabled, the runtime initialization and default ResourceHandler
implementation will use threads to perform their functions. Set this
value to false if threads aren't desired (as in the case of running
within the Google Application Engine).
Note that when this option is disabled, the ResourceHandler will not
pick up new versions of resources when ProjectStage is development.
</description>-->
</context-param>
<!-- ***** Specify JBoss Expression Language Over Default -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- ***** Load the JavaServer Faces Servlet ***** -->
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config1.xml</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>2147483647</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
</web-app>
the index.xhtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>There is Hope!</title>
</f:facet>
<h:outputStylesheet name="style.css" />
</h:head>
<h:body>
<h:graphicImage url="logo.png"/>//this line works!
<br />
Hello from Facelets
<br />
<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
</h:body>
</html>
the appengine-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://kenai.com/projects/nbappengine/downloads/download/schema/appengine-web.xsd appengine-web.xsd'>
<application>RetailSmarts</application>
<version>1</version>
<!--Allows App Engine to send multiple requests to one instance in parallel:-->
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<sessions-enabled>true</sessions-enabled>
<async-session-persistence enabled="true"></async-session-persistence>
</appengine-web-app>
the faces-config.xml(without this my web project works fine but I plan to use it later for these What is the use of faces-config.xml in JSF 2?
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" 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_2.xsd">
<application>
<lifecycle>
<phase-listener>package.SessionPhaseListener</phase-listener>
</lifecycle>
</application>
</faces-config>
the SessionPhaseListener.java
public class SessionPhaseListener implements PhaseListener, Serializable {
private static final long serialVersionUID = 1L;
#Override
public void afterPhase(PhaseEvent arg0) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("CURRENT_TIME", System.currentTimeMillis());
}
#Override
public void beforePhase(PhaseEvent arg0) {
}
#Override
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
}
the tutorial stated I need to add the PhaseListener to Ensure the Contents of HttpSession Are Saved
Can anyone point which part of my project causes the error. I really want to use faces-config.xml without having a error. My whole point is, I cannot import css, js and other file with faces-config.xml present in my project. Is there any configuration or information I missed for JSF and GAE setup.

Related

GCP - Cloud endpoints service_name and configuration

I am studying Google Cloud Endpoints and I have some doubts about configuration.
I already work with appengine, but endpoints it is a little confuse for me.
I did this example:
https://cloud.google.com/endpoints/docs/frameworks/java/get-started-frameworks-java
I did some changes for test other possibilities:
appengine-web.xml
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
<module>endpointsmodule</module>
<basic-scaling>
<max-instances>1</max-instances>
</basic-scaling>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
<!-- [START env_variables] -->
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.service.prefix}.endpoints.${endpoints.project.id}.appspot.com" />
<env-var name="ENDPOINTS_SERVICE_VERSION" value="1.0.0" />
</env-variables>
<!-- [END env_variables] -->
</appengine-web-app>
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_3_1.xsd"
version="3.1">
<!-- Wrap the backend with Endpoints Frameworks v2. -->
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.echo.Echo,com.example.echo.Echo2</param-value>
</init-param>
</servlet>
<!-- Route API method requests to the backend. -->
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/endpointsmodule/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Add a filter that fetches the service config from service management. -->
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>
<!-- Add a filter that performs Endpoints logging and monitoring. -->
<!-- [START api_management] -->
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.service.prefix}.endpoints.${endpoints.project.id}.appspot.com</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<!-- [END api_management] -->
</web-app>
pom.xml
<endpoints.project.id>myprojectid</endpoints.project.id>
<endpoints.service.prefix>mymodule</endpoints.service.prefix>
openapi.json
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "xxx"
},
"host": "myprojectid.appspot.com",
"basePath": "/endpointsmodule",
"schemes": [
"https"
],
The doubts are:
Whats is the purpose of service_name? I did deploy of openapi.json and appengine module but in my Google Console still appear the name of my project in "service name".
this configuration: ENDPOINTS_CONFIG_ID, I can not see anywhere in my Google Console.
I would like that my endpoints receive requets in "enpoints-module"(appengine) that is appengine, not a default module.
All requests to endpoints happen through _ah/api ?
I am trying to do a request for this path:
https://myprojectid.appspot.com/endpointsmodule/echo/v1/echo
What is the correct value to ENDPOINTS_CONFIG_ID and ENDPOINTS_SERVICE_VERSION?
The exception when appengine starts:
repackaged.com.google.api.config.ServiceConfigException: Failed to fetch default config version for service 'myserviceprefix.endpoints.myprojectid.appspot.com'. No versions exist!
The Endpoints service name is host field set in the OpenAPI specification. This has to match both the environment variable ENDPOINTS_SERVICE_NAME and the endpoints.serviceName filter parameter.

Deploy vaadin app to Google App Engine - Error NOT_FOUND

I successfully deployed a Vaadin application, but when calling it I see ERROR : NOT_FOUND
I suppose that my default page is not found,because the default page is selected wrong.
Question:
How can I point (I suppose in my web.xml) to my default page?
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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GoogleAppVaadin701Project</display-name>
<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>
Vaadin eclipse plugin does not create web.xml which works for vaadin application. In the book of vaadin you can find section about web.xml - https://vaadin.com/book/vaadin7/-/page/application.environment.html
following is basic servlet definition and mapping based on the book which works fine. Just change the UI parameter to point to your UI implementation
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>
com.vaadin.server.GAEVaadinServlet
</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>com.example.higoogle.HigoogleUI</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

Struts 2 GAE No action mapped for namespace [/]

I'm learning Struts 2 for a project requirement and I've met some issues.
Following this tutorial at:
http://www.mkyong.com/google-app-engine/google-app-engine-struts-2-example/
And what I've done extra:
Added an index.jsp into the war folder
Changed web.xml to
<?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">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.mkyong.listener.Struts2ListenerOnGAE</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Now, when I rebuild and loads
http://localhost:8888
Rather then seeing the content I should have in my index.jsp, I'm getting a
Error 404 There is no Action mapped for namespace [/] and action name [] associated with context path [].
Can someone point me to the right direction? I've seen some other similar questions in SO but their solutions do not work for this specific example of Struts 2 + GAE.
My struts.xml
<struts>
<package name="user" namespace="/User" extends="struts-default">
<action name="Login">
<result>pages/login.jsp</result>
</action>
<action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
<result name="SUCCESS">pages/welcome_user.jsp</result>
</action>
</package>
</struts>
Folder structure
I cant post images so, http://i.imgur.com/KSPmaMr.png
Exact same libraries used for download
http://www[dot]mediafire[dot]com/?utliwvcmo63o8l7
ok ,i got your problem,
change your struts.xml to this
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="Login">
<result>pages/login.jsp</result>
</action>
<action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
<result name="SUCCESS">pages/welcome_user.jsp</result>
</action>
</package>
</struts>
I guess this will work, because filterDispatcher search for struts.xml file in root folder if you put your struts.xml file in root directory.
#Eleazar I followed the mykong tutorial link that you mentioned in your question. There is no use of index.html as far as I see that tutorial. <welcome-list> file is used when the is no action mentioned on application startup.
On step:8 in that tutorial they has provided the url which is http://localhost:8888/User/Login.action you need to run the test. Its got nothing to do with file in welcome list...
UPDATE:
You are getting that error because you have added struts2 filter as /*, and your action namespace is for /User. There is not action namespace for /. Adding package with name="default" with namespace="/" i.e <package name="default" extends="struts-default" namespace="/"></package> will resolve you issue. It will hit <welcome-file>

Google App Engine - JSF - Facelets - Why not *.xhtml as a url-pattern?

I'm migrating an existing app from Tomcat to GAE. When testing locally, the xhtml pages are loaded as static pages. All processing is bypassed including my filter. However, if I reference a page that doesn't exist, my security filter forwards the request to the login.xhtml and the JSF/facelet renders fine.
Any idea why the xhtml pages are getting processed?
Other integrations: eclipse Helios, gae 1.6.5, maven (eclipse/m2), moharra 2.0.9, richfaces 4.2.0, spring 3.1.1
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">
<!-- https://community.jboss.org/wiki/HowToUseRichFaces40WithGoogleAppEngine -->
<context-param>
<param-name>com.sun.faces.enableThreading</param-name>
<param-value>false</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.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<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>
<filter>
<filter-name>SecurityFilter</filter-name>
<filter-class>com.xyz.web.filter.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SecurityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/org.richfaces.resources/*</url-pattern>
</servlet-mapping>
</web-app>
Update:
It works if I add the following mapping and refer to the page with .jsf extension. Referring to the .xhtml directly, still loads the source. Is it typical configuration to refer to .jsf extension for a .xhtml? If so, how do you configure the app so the source isn't available when accessed via .xhtml?
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
If I correctly understand your needs, you should add
<static-files>
<exclude path="/**.xhtml" />
</static-files>
in appengine-web.xml
If you skip this, your web browser will get reply from "static file server", not from JSF.

googleapp engine hello world 500 server error?

Trying out the hello world tutorial for googleapp engine. But get the 500 server error when I try to go on the deployed app.
http://chemstest.appspot.com/
The index works, but then the servlet gives me the error. Its written in java. I saw some things about case errors in web.xml but the app name and java class are all named in lowercase.
The servlet:
package com.chems.hellogoogleapp;
import java.io.IOException;
import javax.servlet.http.*;
#SuppressWarnings("serial")
public class hellogoogleappServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, James");
}
}
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>hellogoogleapp</servlet-name>
<servlet-class>com.chems.hellogoogleapp.hellogoogleappServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hellogoogleapp</servlet-name>
<url-pattern>/hellogoogleapp</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
appengine-xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>chemstest</application>
<version>1</version>
<!--
By default, App Engine sends requests serially to a given web server.
To allow App Engine to send multiple requests in parallel specify:
<threadsafe>true</threadsafe>
-->
<!-- Configure java.util.logging -->
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
Hopefully an easy one to solve?

Resources