use of javax.faces.context.ExternalContext in project oxAuth by GluuFederation.
the class ServerUtil method getRequestOrNull.
/**
* Safe retrieves http request from FacesContext
*
* @return http
*/
public static HttpServletRequest getRequestOrNull() {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null)
return null;
ExternalContext externalContext = facesContext.getExternalContext();
if (externalContext == null)
return null;
Object request = externalContext.getRequest();
if (request == null || !(request instanceof HttpServletRequest))
return null;
return (HttpServletRequest) request;
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class ExceptionHandlerTest method setUp.
@Before
public void setUp() throws Exception {
FacesContextMocker.mockFacesContext();
ExternalContext externalContext = mock(ExternalContext.class);
when(FacesContext.getCurrentInstance().getExternalContext()).thenReturn(externalContext);
servletContext = mock(ServletContext.class);
when(FacesContext.getCurrentInstance().getExternalContext().getContext()).thenReturn(servletContext);
InputStream input = new FileInputStream(ERROR_MESSAGES_PROPERTIES_PATH);
when(servletContext.getResourceAsStream(anyString())).thenReturn(input);
UIViewRoot viewRoot = mock(UIViewRoot.class);
when(FacesContext.getCurrentInstance().getViewRoot()).thenReturn(viewRoot);
when(viewRoot.getChildren()).thenReturn(new ArrayList<>());
wrappedExceptionHandler = mock(javax.faces.context.ExceptionHandler.class);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class EffortsBeanTest method testGetGrouping_GroupingIsNullCookieIsNull.
@Test
public void testGetGrouping_GroupingIsNullCookieIsNull() throws NoSuchFieldException {
EffortsGrouping defaultGrouping = BY_PROJECTS;
FacesContext facesContext = createMock(FacesContext.class);
ExternalContext externalContext = createMock(ExternalContext.class);
HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
Cookie[] cookies = new Cookie[0];
setField(effortsBean, "facesContext", facesContext);
expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes();
expect(externalContext.getRequest()).andReturn(httpServletRequest);
expect(externalContext.getResponse()).andReturn(httpServletResponse);
expect(httpServletRequest.getCookies()).andReturn(cookies).anyTimes();
replay(facesContext, externalContext, httpServletRequest);
EffortsGrouping expected = defaultGrouping;
EffortsGrouping actual = effortsBean.getGrouping();
assertEquals(expected, actual);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class EffortsBeanTest method testGetGrouping_GroupingIsNullCookieIsNotNull.
@Test
public void testGetGrouping_GroupingIsNullCookieIsNotNull() throws NoSuchFieldException {
FacesContext facesContext = createMock(FacesContext.class);
ExternalContext externalContext = createMock(ExternalContext.class);
HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
Cookie[] cookies = new Cookie[] { new Cookie("efforts_grouping", BY_PROJECTS.toString()) };
setField(effortsBean, "facesContext", facesContext);
expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes();
expect(externalContext.getRequest()).andReturn(httpServletRequest);
expect(externalContext.getResponse()).andReturn(httpServletResponse);
expect(httpServletRequest.getCookies()).andReturn(cookies);
replay(facesContext, externalContext, httpServletRequest);
EffortsGrouping expected = BY_PROJECTS;
EffortsGrouping actual = effortsBean.getGrouping();
assertEquals(expected, actual);
}
use of javax.faces.context.ExternalContext in project ART-TIME by Artezio.
the class FacesMessageInterceptor method aroundInvoke.
@AroundInvoke
public Object aroundInvoke(InvocationContext ic) throws Exception {
FacesContext facesContext = FacesContext.getCurrentInstance();
Object result = ic.proceed();
if (facesContext == null)
return result;
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.getFlash().setKeepMessages(true);
FacesMessage annotation = ic.getMethod().getAnnotation(FacesMessage.class);
String onCompleteMessageKey = annotation.onCompleteMessageKey();
Locale locale = externalContext.getRequestLocale();
String messageBundleName = facesContext.getApplication().getMessageBundle();
ResourceBundle messageBundle = ResourceBundle.getBundle(messageBundleName, locale);
facesContext.addMessage(null, new javax.faces.application.FacesMessage(messageBundle.getString(onCompleteMessageKey)));
return result;
}
Aggregations