Problem definition:
We have a public facing tomcat which we wish to single password protect a webapp on the prodution facing tomcat only. This can be done by adding a new user & role to the production tomcat-users.xml and adding the corresponding and sections to the webapps WEB-INF/web.xml
The problem is, because you have to change the actually webapp, it means the developers using eclipse cant access the site, unless they remove the lines and remember to re-apply them before releasing. It is not possible to edit the eclipse tomcats tomcat-users.xml (found in workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf as it gets overwritten when you stop/start tomcat.
Question:
Is there any other way of doing authentication only on the server, or alternately a way of getting the user into eclipses tomcat?
Below is what went into the web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>
Entire Application
</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>gamer</role-name>
</auth-constraint>
</security-constraint>
<!-- Define the Login Configuration for this Application -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Invigation only</realm-name>
</login-config>
One brute-force solution would be to add the needed things into web.xml during the final build process using a script. It isn't clean, and I'm sure there are better ways, but it eliminates the developer pain point.
Related
Problem
As far as I understand in RAP every single servlet request should go through the Equinox Servlet Bridge. This includes the Help pages, which are JSP files inside the org.eclipse.help.webapp plugin.
I have the following Servlet Mapping in the Web.xml:
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
If I deploy my application into websphere, then I cannot open the help, and I get this error:
It seems, that WebSphere simply ignores my will, that I want to handle even the "/index.jsp" url with the equinox servlet.
Already Tried
I tried the com.ibm.ws.webcontainer.enableJspMappingOverride custom property of the web container, but it did not help.
In the documentation it is stated:
When a url-pattern is defined in the jsp-property-group of the
web.xml, file, it is typically mapped to, and handled by the
JavaServer Page (JSP) engine. If you have applications that must
override this mapping so that they can handle and serve the JSP
content themselves, set the
com.ibm.ws.webcontainer.enableJspMappingOverride property to true.
I also added the following snippet to the web xml, but it also did not help:
<jsp-config>
<jsp-property-group>
<description>Enables using help webapp JSP pages with Websphere</description>
<url-pattern>*.jsp</url-pattern>
</jsp-property-group>
</jsp-config>
Do you have any idea how to make WebSphere to leave my requests with *.jsp URLs alone, and let equinox bridge to make its work?
It seems, that the custom property is neccessary, but not enough. I need an extra servlet mapping as described here.
So the mapping should look like this:
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
In the moment the best way to redeploy an application to our glassfish servers is:
stop domain (so we don't get lots of exceptions because querys comming in while redeploy)
remove the application from the domain folder
start domain
deploy compelete application
Is there s.t. I miss that would make the process less time consuming.
Thanks Hasan
You should be able to use NetBeans integrated hot-deployment to deploy faster. NetBeans detects the files that have changed and copies only these to the deployment folder.
To enable explicitly (it should be enabled by default):
Go to Project -> Properties -> Build -> Run
Enable "Deploy on Save"
Make sure you have the following in your web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
You can ignore the exceptions on redeployment.
Another option would be to checkout JRebel.
I have a JSF project in Eclipse. Now every time I make changes to the .xhtml files, I have to stop Tomcat server, and then start Tomcat server again.
Is there any other way where I can continuously build and test my application without restarting the server every time I make changes?
There are at least two changes you need to make when you need to develop a JSF project:
Tell Eclipse to automatically publish changes by changing the Tomcat settings as follows (doubleclick Tomcat server entry in Servers view to get this screen):
It namely defaults to "Never publish automatically".
Tell JSF that the webapp is currently in development mode by adding the following to web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
This will change some internal workings to make the developers easier such as disabling the Facelet cache and reloading resources. Don't forget to remove this when building a production release because this affects performance. This setting can alternatively also be set by JNDI.
The alternative is to migrate from the barebones Tomcat server to a normal JEE server such as WildFly, Payara, Liberty, etc. For them, the above described Eclipse setting is not necessary anymore and you can even live edit bean methods (on Tomcat, you'd still need to restart the whole server for them).
facelets.REFRESH_PERIOD: –
interval compiler checks for page changes – lower values useful during development
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
(or)
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
you can set any one of the above. change in web.xml
set to -1 if you don't want to effect changes made.(default value)
check this link.
Edit: as #BalusC told, above will work for jsf 1.x, For jsf 2.X change publishing settings and javax.faces.PROJECT_STAGE in web.xml.
I am trying just to run a servlet on my local Tomcat with Eclipse.
But I keep getting this error and do not have any idea what to do differently.
I actually recorded it here : http://www.screenr.com/ZyD8
Many thanks!
Also I changed the web.xml to this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="3.0"
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" >
<display-name>
TEST3
</display-name>
<welcome-file-list>
<welcome-file>
TEST3
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
helloServlet
</servlet-name>
<servlet-class>
HelloServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
helloServlet
</servlet-name>
<url-pattern>
/hello
</url-pattern>
</servlet-mapping>
</web-app>
I have seen your link.
When ever you run any dynamic web project. By default Servlet container (which is Tomcat in this case) searches for files specified in wel-come list. Check your web.xml, it should contains entry like
<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>
You haven't created file from any of the above list. So, running
http://localhost:8080/TEST2 will give you 404 error.
Rather run : http://localhost:8080/TEST2/HelloSerlvet will invoke the servlet which you have created.
Edit: Check Project Menu of eclipse and verify "Build Automatically" is checked and Servlet container is running (http://localhost:8080).
Edit 2: Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder. Create /WEB-INF/classes
under /WebContent (default in eclipse)
This is based on the answer from Hardik Mishra with some highlights:
1. From the file explorer (not from Eclipse), Manually create the "/WEB-INF/classes" under /WebContent
2. Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder to the folder you just created above.
3. go to the file explorer, not from Eclipse, since the Eclipse "project Explorer" may have some filters that doesnot show the classes folder. You should see the .class files compiled under this directory
Try to test it again. If it does not work, restart Eclipse for one time and then it should work.
I have been seeing these types of issue for quite sometime and have seen multiple solutions which work for some and rest still face the same issue.
One of the simple solution is traverse to the .java/.jsp/etc., right click and select run from server option.
I found this solution to be simple yet effective way of running.
path Java Resource->src->->example.java-->right click-->run as-->run on server.
Even after this also you can face few issues like port 8005 not available, please follow the below link to clean out your current Apache setting and re-setting the same.
TOMCAT - HTTP Status 404
Deployment error:Starting of Tomcat failed, the server port 8080 is already in use
Hope this finding was helpful.
Normally, when you modify the web.xml file, you should "clean" Tomcat. Just right-click on Tomcat in Eclipse and clean. Do same for project. You may also stop Tomcat, remove the app from Tomcat (right-click on app under Tomcat and remove) and then add it back. Restart Tomcat.
I am gonna divide this problem in two scenarios:
scenario 1: you are trying to run/execute html/jsp file but getting this error.
scenario 2: you have successfully executed jsp/html file but it is not executing next servlet file. example: there is jsp submit form in webcontent/webapp, it is getting executed but after filling and submitting form you are getting this error.
Scenario 1:
Make sure that your jsp/html file are in webcontent/webapp folder that you created at the time of project creation.
check web.xml file where content should be like this:
try changing tomcat server version.
Scenario 2:
at this level your main culprit is web.xml file where you have to check Servlet mapping thoroughly or add webservlet annotation at file level.
I'm noticing a lot of issues operating the "hot deploying" of JSF pages in the following environment:
Eclipse Indigo(latest version)
Tomcat 5.5
JSF 1.2
Facelets View Handler
I noticed that, if I modify an already rendered xhtml page (for example the CSS style of an element) and then re-publish(through Eclipse or manually copying the xhtml file inside Tomcat) this page (maintaining the servlet container up), it doesn't show me the current changes.
I also, in vain, setup the following configuration on my web application:
<Context
docBase="mywebapp"
path="/mywebapp"
reloadable="true"
cachingAllowed="false">
My last tought is that the Restore-View Phase of a typical JSF page processing, does not check if the client-view (the xhtml page of course) has changed from the last time it has been loaded in the FacesContext.
If so, how can i force the building of a new UIViewRoot object for each submitted request??
I'm a lot frustrating in restarting the tomcat server for each change in jsf pages.
Thanks a lot for your support.
Try adding the following to your web.xml config file:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
It tells JSF to re-render the Facelet. See how I put "1". In a Prod environment you would always put "-1" to disable this feature, since the facelets shouldn't be changing in a Prod environment.
You also need to make sure you can Hot Deploy class and JSP resources. You can find how to do that here:
http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/