I am using the Cruise Control jetty container to deploy a Groovlet application. It appears that if I change the groovy files in the webapp directory that Jetty does not recompile the source and the changes aren't reflected in the webapp. How can I modify my web.xml file to check for updates on every load? I'm just using a simple web.xml:
<web-app>
<servlet>
<servlet-name>GroovyServlet</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GroovyServlet</servlet-name>
<url-pattern>*.groovy</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>myApp.groovy</welcome-file>
</welcome-file-list>
</web-app>
GroovyScriptEngine checks the last-modification date of the source file. If it is newer than the last cache entry, a recompile will certainly done.
Related
I need to be able to restrict jsp to run from only /jsp for security reasons. Any way how?
I found I can do this
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
to
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/jsp/*</url-pattern>
</servlet-mapping>
in conf/web.xml
any one know if I can match directory and extension eg /jsp/*.jsp?
I'm using JSF 2.2 and OmniFaces ExtensionlessURLs to remove the file extensions from my URLs:
www.exmaple.com/appname/login.xhtml -> .../appname/login.
Now when I navigate to www.example.com/appname/ I always get forwarded to www.exmaple.com/appname/login. Is it possible to prevent this redirect and to instead serve login.xhtml from www.example.com/appname/?
My .xhtml-files are stored in /WebContent/html/.
Relevant details from my web.xml:
<welcome-file-list>
<welcome-file>login.xhtml</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>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/html/*.xhtml</param-value>
</context-param>
From the showcase:
Advanced configuration
See package documentation for configuration settings as to mapping, filtering and forwarding behavior.
From the package documentation:
Welcome files
If a <welcome-file> is defined in web.xml that's scanned by FacesViews AND REDIRECT_TO_EXTENSIONLESS is used (which is the default, see below), it's necessary to define an extensionless welcome file to prevent a request to / being redirected to /[welcome file]. E.g. without this http://example.com will redirect to say http://example.com/index.
For example:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
In other words, edit your welcome file to say login instead of login.xhtml.
Unrelated to the concrete problem: note though that you seem to have a general misunderstanding of the exact meaning of a "welcome file", because it's a bit strange that you could possibly have a login.xhtml file in every single folder. See also Set default home page via <welcome-file> in JSF project
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
I am trying to enable compression and packaging of my css and js files in Richfaces 4.3.3 using the inbuilt optimisation features, but nothing I try seems to have any effect and all script and CSS files are still being loaded as separate entities - I've enabled the optimisation feature in my web.xml as follows
<context-param>
<param-name>org.richfaces.resourceOptimization.enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceMapping.packedStages</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceOptimization.compressionStages</param-name>
<param-value>Production</param-value>
</context-param>
<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>
the links on my pages are being included like so
<h:outputStylesheet name="bootstrap.css" library="css" />
or
<h:outputScript library="js" name="bootstrap-dropdown.js" />
and these files are in the WEB-INF/resources folder. I may be mistaken, but I would then expect that richfaces would detect these files and add them into the packed.css and packed.js files, but these files are still being loaded separately. One final thing to note is that I have my PROJECT_STAGE set as follows in my faces-config.xml file
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
Any pointers or tips anyone could give me would be greatly appreciated!
You misunderstand how it works.
org.richfaces.resourceOptimization.enabled=true
means "when you're looking for resources, load the optimized ones." It doesn't create the packed.js/packed.css, those were created when the richfaces*.jar was built.
If you want your own resources being processed take a look at the richfaces maven plugin.