Example usage for org.springframework.web.context.request RequestContextHolder setRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder setRequestAttributes

Introduction

In this page you can find the example usage for org.springframework.web.context.request RequestContextHolder setRequestAttributes.

Prototype

public static void setRequestAttributes(@Nullable RequestAttributes attributes) 

Source Link

Document

Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.

Usage

From source file:org.ngrinder.agent.controller.AgentManagerControllerTest.java

@Before
public void setMockRequest() {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addHeader("User-Agent", "Win");
    SecurityContextHolderAwareRequestWrapper reqWrapper = new SecurityContextHolderAwareRequestWrapper(req,
            "U");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(reqWrapper));
}

From source file:io.jmnarloch.spring.boot.hystrix.Demo.java

@Before
public void setUp() throws Exception {

    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
    requestId = UUID.randomUUID().toString();
}

From source file:at.ac.univie.isc.asio.spring.ContextPropagator.java

/**
 * Set the stored context as the current thread's local context.
 *//*  w  w  w .  ja va 2  s .c o  m*/
public ContextPropagator publish() {
    final Thread current = Thread.currentThread();
    if (current == origin) {
        log.warn(Scope.SYSTEM.marker(), "publishing context to origin {} again", origin);
    } else {
        log.debug(Scope.SYSTEM.marker(), "publishing context from {} to {}", origin, current);
    }
    RequestContextHolder.setRequestAttributes(stored);
    return this;
}

From source file:br.com.caelum.vraptor.ioc.spring.SpringProviderTest.java

@Before
public void init() {
    servletContext = mock(ServletContext.class);

    session = new HttpSessionMock(servletContext, "session");
    request = new HttpServletRequestMock(session, mock(MutableRequest.class));

    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);
}

From source file:com.expressui.domain.service.SetupSession.java

@Override
public void afterPropertiesSet() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);//from   ww w  .  j  a v  a 2s .  co  m
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}

From source file:org.craftercms.core.url.impl.ExtractRequestAttributesUrlTransformerTest.java

private void setUpTestRequestAttributes() {
    RequestContextHolder.setRequestAttributes(new StubRequestAtrributes());
}

From source file:com.github.hateoas.forms.spring.AffordanceBuilderFactoryTest.java

@Before
public void setUp() {
    request = MockMvcRequestBuilders.get("http://example.com/").buildRequest(new MockServletContext());
    final RequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);
}

From source file:com.mitchellbosecke.pebble.spring.PebbleViewResolverTest.java

@Before
public void initRequest() {
    this.request.setContextPath(CONTEXT_PATH);
    this.request.getSession().setMaxInactiveInterval(600);

    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
}

From source file:nl.ctrlaltdev.harbinger.evidence.EvidenceCollectorTest.java

@Test
public void shouldEnhanceWithRequest() {
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, response));
    evidence = collector.enhanceAndStore(evidence);
    assertEquals("8.8.8.8", evidence.getIp());
}

From source file:org.terasoluna.gfw.web.token.transaction.TransactionTokenInterceptorTest.java

@Before
public void setUp() throws Exception {

    // prepare request object
    request = new MockHttpServletRequest();
    request.setRequestURI("/token/first");
    request.setMethod("GET");

    // prepare response object
    response = new MockHttpServletResponse();

    // set ServletRequestAttributes to RequestContextHolder
    ServletRequestAttributes attributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(attributes);

    // prepare intercepter instance
    interceptor = new TransactionTokenInterceptor();
}