use of javax.servlet.ServletRequest in project gocd by gocd.
the class LocaleResolverTest method shouldSetLocaleStringToCurrentThread.
@Test
public void shouldSetLocaleStringToCurrentThread() throws IOException, ServletException {
when(req.getLocale()).thenReturn(new Locale("ja"));
CurrentLocale.setLocaleString("en");
localeResolver.doFilter(req, res, new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
localeInside = CurrentLocale.getLocaleString();
}
});
assertThat(CurrentLocale.getLocaleString(), is("en"));
assertThat(localeInside, is("ja"));
}
use of javax.servlet.ServletRequest in project gocd by gocd.
the class LocaleResolverTest method shouldFixThreadLocaleEvenIfFilterFails.
@Test
public void shouldFixThreadLocaleEvenIfFilterFails() throws IOException, ServletException {
when(req.getLocale()).thenReturn(new Locale("ja"));
CurrentLocale.setLocaleString("en");
final RuntimeException exception = new RuntimeException("Oh no!");
try {
localeResolver.doFilter(req, res, new FilterChain() {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
throw exception;
}
});
fail("exception should have been bubbled up");
} catch (RuntimeException e) {
assertThat(e, sameInstance(exception));
}
assertThat(CurrentLocale.getLocaleString(), is("en"));
}
use of javax.servlet.ServletRequest in project entando-core by entando.
the class ContentListFilterTag method doEndTag.
@Override
public int doEndTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
if (!this.isRightKey()) {
StringBuilder message = new StringBuilder();
for (int i = 0; i < IContentListWidgetHelper.allowedMetadataFilterKeys.length; i++) {
if (i != 0) {
message.append(",");
}
message.append(IContentListWidgetHelper.allowedMetadataFilterKeys[i]);
}
throw new RuntimeException("The key '" + this.getKey() + "' is unknown; " + "Please use a valid one - " + message);
}
IContentListWidgetHelper helper = (IContentListWidgetHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_LIST_HELPER, this.pageContext);
IContentListTagBean parent = (IContentListTagBean) findAncestorWithClass(this, IContentListTagBean.class);
String contentType = parent.getContentType();
EntitySearchFilter filter = helper.getFilter(contentType, (IEntityFilterBean) this, reqCtx);
if (null != filter) {
parent.addFilter(filter);
}
} catch (Throwable t) {
_logger.error("error in end tag", t);
throw new JspException("Tag error detected ", t);
}
return super.doEndTag();
}
use of javax.servlet.ServletRequest in project entando-core by entando.
the class ContentTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
IContentViewerHelper helper = (IContentViewerHelper) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_VIEWER_HELPER, this.pageContext);
String contentId = (this.getContentId() != null && this.getContentId().trim().length() > 0) ? this.getContentId() : null;
ContentRenderizationInfo renderInfo = helper.getRenderizationInfo(contentId, this.getModelId(), this.isPublishExtraTitle(), reqCtx);
String renderedContent = (null != renderInfo) ? renderInfo.getRenderedContent() : "";
if (null != this.getVar()) {
this.pageContext.setAttribute(this.getVar(), renderedContent);
} else {
this.pageContext.getOut().print(renderedContent);
}
if (null != renderInfo && null != this.getAttributeValuesByRoleVar()) {
this.pageContext.setAttribute(this.getAttributeValuesByRoleVar(), renderInfo.getAttributeValues());
}
} catch (Throwable t) {
_logger.error("error in doStartTag", t);
throw new JspException("Error detected while initialising the tag", t);
}
return EVAL_PAGE;
}
use of javax.servlet.ServletRequest in project entando-core by entando.
the class SearcherTag method doStartTag.
@Override
public int doStartTag() throws JspException {
ServletRequest request = this.pageContext.getRequest();
RequestContext reqCtx = (RequestContext) request.getAttribute(RequestContext.REQCTX);
try {
String word = request.getParameter("search");
SearcherTagHelper helper = new SearcherTagHelper();
List<String> result = helper.executeSearch(word, reqCtx);
this.pageContext.setAttribute(this.getListName(), result);
request.setAttribute("search", word);
} catch (Throwable t) {
_logger.error("error in do start tag", t);
// ApsSystemUtils.logThrowable(e, this, "doStartTag");
throw new JspException("Error detected while initialising the tag", t);
}
return SKIP_BODY;
}
Aggregations