Search in sources :

Example 36 with ServletRequest

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"));
}
Also used : CurrentLocale(com.thoughtworks.go.i18n.CurrentLocale) Locale(java.util.Locale) ServletException(javax.servlet.ServletException) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) FilterChain(javax.servlet.FilterChain) IOException(java.io.IOException) Test(org.junit.Test)

Example 37 with ServletRequest

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"));
}
Also used : CurrentLocale(com.thoughtworks.go.i18n.CurrentLocale) Locale(java.util.Locale) ServletException(javax.servlet.ServletException) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) FilterChain(javax.servlet.FilterChain) IOException(java.io.IOException) Test(org.junit.Test)

Example 38 with ServletRequest

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();
}
Also used : ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) IContentListWidgetHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListWidgetHelper) IContentListTagBean(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentListTagBean) RequestContext(com.agiletec.aps.system.RequestContext) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 39 with ServletRequest

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;
}
Also used : ContentRenderizationInfo(com.agiletec.plugins.jacms.aps.system.services.dispenser.ContentRenderizationInfo) ServletRequest(javax.servlet.ServletRequest) IContentViewerHelper(com.agiletec.plugins.jacms.aps.system.services.content.widget.IContentViewerHelper) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Example 40 with ServletRequest

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;
}
Also used : SearcherTagHelper(com.agiletec.plugins.jacms.aps.tags.util.SearcherTagHelper) ServletRequest(javax.servlet.ServletRequest) JspException(javax.servlet.jsp.JspException) RequestContext(com.agiletec.aps.system.RequestContext)

Aggregations

ServletRequest (javax.servlet.ServletRequest)314 HttpServletRequest (javax.servlet.http.HttpServletRequest)188 ServletResponse (javax.servlet.ServletResponse)183 HttpServletResponse (javax.servlet.http.HttpServletResponse)118 FilterChain (javax.servlet.FilterChain)113 Test (org.junit.Test)82 IOException (java.io.IOException)65 ServletException (javax.servlet.ServletException)64 Filter (javax.servlet.Filter)41 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)28 Injector (com.google.inject.Injector)26 JspException (javax.servlet.jsp.JspException)26 RequestContext (com.agiletec.aps.system.RequestContext)25 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 FilterConfig (javax.servlet.FilterConfig)24 MockFilterChain (org.springframework.mock.web.MockFilterChain)24 ServletContext (javax.servlet.ServletContext)23 HttpSession (javax.servlet.http.HttpSession)21 ServletTestUtils.newFakeHttpServletRequest (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletRequest)18 ServletTestUtils.newFakeHttpServletResponse (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletResponse)18