use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class ServletUriComponentsBuilder method initFromRequest.
/**
* Initialize a builder with a scheme, host,and port (but not path and query).
*/
private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest request) {
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
String scheme = uriComponents.getScheme();
String host = uriComponents.getHost();
int port = uriComponents.getPort();
ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder();
builder.scheme(scheme);
builder.host(host);
if (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443)) {
builder.port(port);
}
return builder;
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleNoHandlerFoundException.
@Test
public void handleNoHandlerFoundException() throws Exception {
ServletServerHttpRequest req = new ServletServerHttpRequest(new MockHttpServletRequest("GET", "/resource"));
NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(), req.getServletRequest().getRequestURI(), req.getHeaders());
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 404, response.getStatus());
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class JettyRequestUpgradeStrategy method upgrade.
@Override
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user, WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException {
Assert.isInstanceOf(ServletServerHttpRequest.class, request, "ServletServerHttpRequest required");
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
Assert.isInstanceOf(ServletServerHttpResponse.class, response, "ServletServerHttpResponse required");
HttpServletResponse servletResponse = ((ServletServerHttpResponse) response).getServletResponse();
Assert.isTrue(this.factory.isUpgradeRequest(servletRequest, servletResponse), "Not a WebSocket handshake");
JettyWebSocketSession session = new JettyWebSocketSession(attributes, user);
JettyWebSocketHandlerAdapter handlerAdapter = new JettyWebSocketHandlerAdapter(wsHandler, session);
WebSocketHandlerContainer container = new WebSocketHandlerContainer(handlerAdapter, selectedProtocol, selectedExtensions);
try {
containerHolder.set(container);
this.factory.acceptWebSocket(servletRequest, servletResponse);
} catch (IOException ex) {
throw new HandshakeFailureException("Response update failed during upgrade to WebSocket: " + request.getURI(), ex);
} finally {
containerHolder.remove();
}
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class AbstractHttpRequestTests method resetRequest.
protected void resetRequest() {
this.servletRequest = new MockHttpServletRequest();
this.servletRequest.setAsyncSupported(true);
this.request = new ServletServerHttpRequest(this.servletRequest);
}
use of org.springframework.http.server.ServletServerHttpRequest in project spring-framework by spring-projects.
the class HttpSockJsSessionTests method setup.
@Before
public void setup() {
super.setUp();
this.frameFormat = new DefaultSockJsFrameFormat("%s");
this.servletResponse = new MockHttpServletResponse();
this.response = new ServletServerHttpResponse(this.servletResponse);
this.servletRequest = new MockHttpServletRequest();
this.servletRequest.setAsyncSupported(true);
this.request = new ServletServerHttpRequest(this.servletRequest);
}
Aggregations