I have a Facelets(JSF 1.2 (myfaces)) web app and I want to customize my error page - which would seem to be a natural thing to do when an application matures.
I got really confused in the process.
I found the following:
I haven't found a way to customize Facelets' error page. I haven't found where the template is. I have found solutions with overriding the ViewHandler that would do sendRedirect(). I think this should be accomplishable without writing code, especially the ViewHandler.
I have found a way to switch off Facelets' error handling and using myFaces' one:
code:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_TEMPLATE_RESOURCE</param-name>
<param-value>/pages/public/errorPage.jsf</param-value>
</context-param>
Unfortunately I cannot seem to make myFaces find a JSF page. I need to use a jsf page because I want to use the site's layout which is fragmented over a few templates.
Source: http://wiki.apache.org/myfaces/Handling_Server_Errors
I tried a tomahawk solution:
web.xml:
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLER</param-name>
<param-value>org.apache.myfaces.tomahawk.util.ErrorRedirectJSFPageHandler</param-value>
</context-param>
faces-config.xml:
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>java.lang.Throwable</from-outcome>
<to-view-id>/pages/public/errorPage.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Source: http://wiki.apache.org/myfaces/Handling_Server_Errors
I found that I can use the container's error-handling via <error-page> in web.xml. I successfully forwarded to a jsf error page. Here the problem is that I cannot display the Exception - I don't know how.
Update: I found out how - with a ManagedBean:
public class ErrorDisplayBean {
public String getStackTrace() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestMap();
Throwable ex = (Throwable) requestMap.get("javax.servlet.error.exception");
...
}
}
see http://wiki.apache.org/myfaces/Handling_Server_Errors for the rest of the code.
What I want to accomplish: I want to use Facelets' error-handling mechanism without writing code and be able to display the Exception on a jsf page. If that is not possible, I'd like to use myFaces' error-handling again with displayin the Exception. I think one of them should be possible.
I think you can still make of configuration through your web.xml:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.xhtml</location>
</error-page>
Which can be used for error codes too..
Related
I am using icCube behind my own proxy to redirect login requests to a custom loginpage. At the start of icCube this works fine.
But when I hit the Logout button at the top of the IDE window, I see the following GWT messages:
POST /service.gwt?j_security_check_logout
POST /service.gwt?j_security_check_user
On the first one the icCube server returns an empty response. This seems to be all right.
On the second message the icCube server returns "performFormLogin". This displays the default icCube login window.
Any simple redirect did not work so far, because the service.gwt call expects serverdata.
Can anyone help me what to return to the client to get my own custom loginpage?
From icCube 5.1.8 it is possible to configure a servlet filter in icCube.xml to accept a URL for "redirection" on logout. This way, the Javascript code does not open anymore the FORM login but instead open the specified URL.
<filter>
<filter-name>GWT Authentication</filter-name>
<filter-class>crazydev.iccube.server.authentication.IcCubeGwtAuthenticationServletFilter</filter-class>
<init-param>
<param-name>gwtLogoutRedirectURL</param-name>
<param-value>http://www.google.com</param-value>
</init-param>
</filter>
Hope that helps.
I am developing a Java EE application using Jboss and the authentication.
I know JBoss has two files login.html and login-fail.html in order to use authentication.
The form in login.html file uses the action "j_security_check".
I was wondering if we could use this file but also if if we could develop our own action.
I would like to keep the action "j_security_check" but I would like to access my databse to set a session variable for example after a successful connection.
The missing keyword you're looking for is "Custom JBoss Login Module" :)
There are various examples which shows how to implement and integrate it in your app.
There is also JBoss documentation where your can get an overview of login modules already available in JBoss. DatabaseServerLoginModule is one of them and can probably be used with your database.
A simple demonstration of custom login page in a Servlet container can be found here.
In order to use your own login page with specific login module under JBoss do following:
Implement your own login page with 'j_security_check' action. BTW it's part of servlet API and is not JBoss specific.
Refer your login page in web.xml:
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login-failed.jsp</form-error-page>
</form-login-config>
</login-config>
Optional: Refer required login module in WEB-INF/jboss-web.xml if it's not used by default (login modules can be defined in standalone.xml)
<jboss-web>
<security-domain>org.example.YourSecurityDomain</security-domain>
</jboss-web>
Optional: deploy custom login module implementation within your application and register it in login-config.xml. Check JBoss example for details.
I am having trouble adding the JAX-RS 2.0 facet to an Eclipse 4.3. Dynamic Web project with Glassfish 4.0. I tried the approach noted here and the values that are filled in for the parameters with "Disabled Library Configuration" are:
JAX-RS servlet name: JAX-RS Servlet
JAX-RS servlet class name: javax.ws.rs.core.Application
URL mapping patterns: /jaxrs/*
That gets saved without any problems. Then, when I go back to the Project Properties, I get a pop-up that says "The currently displayed page contains invalid values". Acknowledging that, and getting to the JAX-RS facet page, all the fields are now empty, and instead of saying "Disabled Library Configuration", the Type says "Unknown Library Configuration". Going to the main Project Facets page and trying to uncheck the JAX-RS facet item gives a pop-up that says "Failed while uninstalling JAX-RS (REST Web Services) 2.0. Reason: Failed while uninstalling JAX-RS (REST Web Services) 2.0. The details say "Failed while uninstalling JAX-RS (REST Web Services) 2.0.
org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp"
I updated Eclipse to 4.3.1 and got the same behavior. The fields getting blanked out without any warning when they were initially saved, and not being able to uninstall the JAX-RS facet leads me to believe there's something wrong with my Eclipse install or project file (although I tried this with several projects and they all behaved the same).
Can anyone point me at a way to fix this?
I'm using Jersey as runtime and this is how I can configure directly in web.xml.
I did not have much luck using the project facet settings.
Hope this helps.
(change the provide package param below to fit yours)
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.paypal.l10n.nextgen.extractor.rest</param-value>
</init-param>
<init-param>
<param-name>unit:WidgetPU</param-name>
<param-value>persistence/widget</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have some resources in my jax-rs application i want to validate jax-rs request before it enters into the resource annotated by javax.ws.rs.Path. so, how can i create handler or filter for my resources .I have searched so many sites. their suggestions are use proxy or servlet filters . without using proxy or servlet filters can i create handler/ filter ?
Just like in JAX-WS SOAPHandler is available for soap request ,in the same way is there any handlers for validating jax-rs request.
Here Validating jax-rs request means pre-checking, post checking and Exception handling..
(I am using jersey jars)
You need to create a Filter that implements the ContainerResponseFilter or ContainerRequestFilter provided by Jersey. Then in your web.xml you define it like so:
<servlet>
<servlet-name>MY API</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.example.filters.ReqFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.example.filters.RespFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MY API</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
http://jersey.java.net/nonav/apidocs/1.6/jersey/com/sun/jersey/spi/container/ContainerRequestFilter.html
http://jersey.java.net/nonav/apidocs/1.6/jersey/com/sun/jersey/spi/container/ContainerResponseFilter.html
I need to implement a CAS Proxy Granting Ticket System.
So I need to understand the system. There is a good doc here, but I have no idea about the proxyCallback I need.
Could someone explain me that ?
The CAS will invoke the pgtURL to provide a special ticket that will enable that application to acquire new tickets for other applications.
This is the setup in web.xml:
<servlet>
<servlet-name>casproxy</servlet-name>
<servlet-class>edu.yale.its.tp.cas.proxy.ProxyTicketReceptor</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>casproxy</servlet-name>
<url-pattern>/casProxy/*</url-pattern>
</servlet-mapping>
To get a new ticket for another service with the special ticket:
SecurityContext sc = SecurityContextHolder.getContext();
CasAuthenticationToken auth = (CasAuthenticationToken)sc.getAuthentication();
String pgtIOU = auth.getProxyGrantingTicketIou();
String newTicket = ProxyTicketReceptor.getProxyTicket(pgtIOU, anotherService);
Then you redirect to that service giving to it the new ticket.