use of jakarta.servlet.ServletRequest in project tomcat by apache.
the class Request method setRequest.
/**
* Set a wrapped HttpServletRequest to pass to the application. Components
* wishing to wrap the request should obtain the request via
* {@link #getRequest()}, wrap it and then call this method with the
* wrapped request.
*
* @param applicationRequest The wrapped request to pass to the application
*/
public void setRequest(HttpServletRequest applicationRequest) {
// Check the wrapper wraps this request
ServletRequest r = applicationRequest;
while (r instanceof HttpServletRequestWrapper) {
r = ((HttpServletRequestWrapper) r).getRequest();
}
if (r != facade) {
throw new IllegalArgumentException(sm.getString("request.illegalWrap"));
}
this.applicationRequest = applicationRequest;
}
use of jakarta.servlet.ServletRequest in project spring-security by spring-projects.
the class JaasApiIntegrationFilterTests method assertJaasSubjectEquals.
private void assertJaasSubjectEquals(final Subject expectedValue) throws Exception {
MockFilterChain chain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
// See if the subject was updated
Subject currentSubject = Subject.getSubject(AccessController.getContext());
assertThat(currentSubject).isEqualTo(expectedValue);
// run so we know the chain was executed
super.doFilter(request, response);
}
};
this.filter.doFilter(this.request, this.response, chain);
// ensure that the chain was actually invoked
assertThat(chain.getRequest()).isNotNull();
}
use of jakarta.servlet.ServletRequest in project spring-framework by spring-projects.
the class ViewResolverTests method internalResourceViewResolverWithSpecificContextBeans.
@Test
public void internalResourceViewResolverWithSpecificContextBeans() throws Exception {
this.wac.registerSingleton("myBean", TestBean.class);
this.wac.registerSingleton("myBean2", TestBean.class);
this.wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
Properties props = new Properties();
props.setProperty("key1", "value1");
vr.setAttributes(props);
Map<String, Object> map = new HashMap<>();
map.put("key2", 2);
vr.setAttributesMap(map);
vr.setExposedContextBeanNames(new String[] { "myBean2" });
vr.setApplicationContext(this.wac);
HttpServletRequest request = new MockHttpServletRequest(this.sc) {
@Override
public RequestDispatcher getRequestDispatcher(String path) {
return new MockRequestDispatcher(path) {
@Override
public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
assertThat(forwardRequest.getAttribute("rc") == null).as("Correct rc attribute").isTrue();
assertThat(forwardRequest.getAttribute("key1")).isEqualTo("value1");
assertThat(forwardRequest.getAttribute("key2")).isEqualTo(2);
assertThat(forwardRequest.getAttribute("myBean")).isNull();
assertThat(forwardRequest.getAttribute("myBean2")).isSameAs(wac.getBean("myBean2"));
}
};
}
};
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
View view = vr.resolveViewName("example1", Locale.getDefault());
view.render(new HashMap<String, Object>(), request, this.response);
}
use of jakarta.servlet.ServletRequest in project spring-framework by spring-projects.
the class FormTag method doEndTag.
/**
* Closes the '{@code form}' block tag and removes the form object name
* from the {@link jakarta.servlet.jsp.PageContext}.
*/
@Override
public int doEndTag() throws JspException {
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
ServletRequest request = this.pageContext.getRequest();
if (processor != null && request instanceof HttpServletRequest) {
writeHiddenFields(processor.getExtraHiddenFields((HttpServletRequest) request));
}
Assert.state(this.tagWriter != null, "No TagWriter set");
this.tagWriter.endTag();
return EVAL_PAGE;
}
use of jakarta.servlet.ServletRequest in project spring-framework by spring-projects.
the class UrlTag method doEndTag.
@Override
public int doEndTag() throws JspException {
String url = createUrl();
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
ServletRequest request = this.pageContext.getRequest();
if ((processor != null) && (request instanceof HttpServletRequest)) {
url = processor.processUrl((HttpServletRequest) request, url);
}
if (this.var == null) {
// print the url to the writer
try {
this.pageContext.getOut().print(url);
} catch (IOException ex) {
throw new JspException(ex);
}
} else {
// store the url as a variable
this.pageContext.setAttribute(this.var, url, this.scope);
}
return EVAL_PAGE;
}
Aggregations