GAE display index.html with JAX-RS - google-app-engine

I'm pretty sure this questions is very easy.
I built a app with google app engine. I use JPA and JAX-RS with Jersey.
my web.xml looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</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.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/resources/*</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>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
My index.html is in war/WEB-INF/index.html. What do i need to do to display it ?

index.html should go directly under war as in war/index.html.

keep your file in war folder itself,
Don't keep inside WEB-INF.
Once you have taken it out,
You just need to give localhost:8888/ it will display the welcome-file ie index.html
you can keep other Jsp's inside WEB-INF, it will just be invisible for direct URL access.

Related

Map a servlet to a cron url?

How do I map a servlet to a cron url? This question results from the comment to the answer in the following post: Use Cron jobs with Appengine Endpoints API
In my project the cron job is called as shown in the log in Google App Engine and the url https://[url-commented-out].appspot.com/_ah/api/stocksApi/v1/stocks executes properly when tested in the web browser and returns the proper value.
But I am getting the error 405: HTTP method GET not supported by this URL, when I try to run it in GAE. I've read https://cloud.google.com/appengine/docs/java/config/cron My code in cron.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/_ah/api/stocksApi/v1/stocks</url>
<description>Backend Process Stocks</description>
<schedule>every 1 minutes from 11:10 to 11:30</schedule>
<timezone>America/New_York</timezone>
</cron>
</cronentries>
My web.xml is:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>
[package].StocksEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>cron</web-resource-name>
<url-pattern>/_ah/api/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>ObjectifyFilter</filter-name>
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ObjectifyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
I am using Android Studio and have added a backend module by following HelloEndpoints and I have a StocksEndpoint.java
file with a getStocks(); method that returns stocks.
First add a servlet mapping for your cron to web.xml:
<!-- stock servlet -->
<servlet>
<servlet-name>StockServlet</servlet-name>
<servlet-class>YOUR.PACKAGE.HERE.StockServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StockServlet</servlet-name>
<url-pattern>/cron/stocks</url-pattern>
</servlet-mapping>
make sure to update the servlet class for your servlet!
Then finally put the new cron url in your cron.xml:
<cron>
<url>/cron/stocks</url>
<description>Backend Process Stocks</description>
<schedule>every 1 minutes from 11:10 to 11:30</schedule>
<timezone>America/New_York</timezone>
</cron>
Unfortunately urls under /_ah/api are restricted and cannot be called from within your App.
There are a couple of ways to go around this but the most accepted option is usually to use a regular servlet to serve Cron requests rather connecting to the endpoint.

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>

Jsp serverlet mapping url-pattern /* overrides the welcome-file

I'm building a site on Google app engine with Java.
There I'm trying to map jsp pages with servlet mapping as follows:
http://localhost:8080/<any text> should map to r.jsp
http://localhost:8080 should map to home.jsp
But those two urls always get mapped to r.jsp.
And my web.xml is as follows:
<servlet>
<servlet-name>r</servlet-name>
<jsp-file>/r.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>home</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>home</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
I also tried <url-pattern>""</url-pattern> instead of <url-pattern>/</url-pattern> and it also did not work
Any servlet mapping solution for this?
Change you web.xml to something like this
<servlet>
<servlet-name>r</servlet-name>
<jsp-file>/r.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/ewerw</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/rrrxdsfwef</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/xy1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>home</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>

An iceFaces - facelets URL bar address is not showing

My company has the Spring-Ifaces 1.8 standard to work with a IBM WAS 6.1 solution. After read the icefaces tutorials, i decide to implement a facelets solution to do a better template management.
In the faces-config.xml i put the next line to config the facelets:
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
The web.xml is configured to search the index.jsp as the main page on the context:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
The index forward to the first page on my navigation logic.
<body>
<jsp:forward page="paso1.iface" />
</body>
But on the browser URL bar address, i still seeing the http://server.com/context path.
When the form data is already written, i submit, run my action and the navigation rule send me to the next page.
But again, on the browser URL bar address, is still in the http://server.com/context path.
<navigation-rule>
<from-view-id>/step1.jspx</from-view-id>
<navigation-case>
<from-action>#{actionBean.action}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/step2.jspx</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{actionBean.action}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/step1.jspx</to-view-id>
</navigation-case>
</navigation-rule>
I can't use redirect, because there is some session data. And even i try using the standard Java EE Facelets tag com.sun.facelets.FaceletViewHandler, but the page can't be rendered.
How can I force or config properly the IceFaces Facelet to show me the webpage than I'm already step on?
--- web.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="WebApp_ID"
version="2.4"
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">
<display-name>venta-directa-web</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>uploadServlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SimpleCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.SimpleCaptchaServlet</servlet-class>
</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>
<servlet-name>ChineseCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.ChineseCaptchaServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>265</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>50</param-value>
</init-param>
</servlet>
<context-param>
<param-name>com.icesoft.faces.actionURLSuffix</param-name>
<param-value>.iface</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.debugDOMUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.delegateNonIface</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.heartbeatRetries</param-name>
<param-value>10</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.standardRequestScope</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.component.OutputTextTag</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>
<context-param>
<description>La cantidad en bytes de un archivo a subir por icefaces.</description>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>4048576</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>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</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>contextConfigLocation</param-name>
<param-value>
classpath:app-web-context.xml
classpath:app-core-context.xml
classpath:app-ws-context.xml
classpath:app-dao-context.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/mainservlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>uploadServlet</servlet-name>
<url-pattern>/uploadHtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SimpleCaptcha</servlet-name>
<url-pattern>/simpleImg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StickyCaptcha</servlet-name>
<url-pattern>/stickyImg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ChineseCaptcha</servlet-name>
<url-pattern>/chineseImg</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/checkService.jsp</location>
</error-page>
</web-app>
--- faces-config.xml app config ---
<application>
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
<locale-config>
<default-locale>es</default-locale>
<supported-locale>es</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>en_US</supported-locale>
</locale-config>
</application>
Hope somebody had an answer. Regards.
An ugly solution, but work for me. Is about override the Viewandler:
http://www.logikdev.com/2010/03/24/how-to-personalise-the-urls-with-faces-navigation/

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.

Resources