Package org.springframework.http.server

Examples of org.springframework.http.server.ServletServerHttpResponse$ServletResponseHttpHeaders


    List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
    if (acceptedMediaTypes.isEmpty()) {
      acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
    }
    MediaType.sortByQualityValue(acceptedMediaTypes);
    HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse());
    Class<?> returnValueType = returnValue.getClass();
    if (this.messageConverters != null) {
      for (MediaType acceptedMediaType : acceptedMediaTypes) {
        for (HttpMessageConverter messageConverter : this.messageConverters) {
          if (messageConverter.canWrite(returnValueType, acceptedMediaType)) {
View Full Code Here


    return new ServletServerHttpRequest(servletRequest);
  }

  private HttpOutputMessage createHttpOutputMessage(NativeWebRequest webRequest) throws Exception {
    HttpServletResponse servletResponse = (HttpServletResponse) webRequest.getNativeResponse();
    return new ServletServerHttpResponse(servletResponse);
  }
View Full Code Here

  @Override
  public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
      throws ServletException, IOException {

    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);

    HandshakeInterceptorChain chain = new HandshakeInterceptorChain(this.interceptors, this.wsHandler);
    HandshakeFailureException failure = null;

    try {
      if (logger.isDebugEnabled()) {
        logger.debug(servletRequest.getMethod() + " " + servletRequest.getRequestURI());
      }
      Map<String, Object> attributes = new HashMap<String, Object>();
      if (!chain.applyBeforeHandshake(request, response, attributes)) {
        return;
      }
      this.handshakeHandler.doHandshake(request, response, this.wsHandler, attributes);
      chain.applyAfterHandshake(request, response, null);
      response.close();
    }
    catch (HandshakeFailureException ex) {
      failure = ex;
    }
    catch (Throwable ex) {
View Full Code Here

    this.request = new ServletServerHttpRequest(this.servletRequest);
  }

  protected void resetResponse() {
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
  }
View Full Code Here

  @Override
  public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
      throws ServletException, IOException {

    ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
    ServerHttpResponse response = new ServletServerHttpResponse(servletResponse);

    try {
      this.sockJsService.handleRequest(request, response, getSockJsPath(servletRequest), this.webSocketHandler);
    }
    catch (Throwable ex) {
View Full Code Here

  public void handleInfoGetWildflyNPE() throws Exception {
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
    ServletOutputStream ous = mock(ServletOutputStream.class);
    given(mockResponse.getHeaders("Access-Control-Allow-Origin")).willThrow(NullPointerException.class);
    given(mockResponse.getOutputStream()).willReturn(ous);
    this.response = new ServletServerHttpResponse(mockResponse);

    handleRequest("GET", "/echo/info", HttpStatus.OK);

    verify(mockResponse, times(1)).getOutputStream();
  }
View Full Code Here

    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);
  }
View Full Code Here

   * @param webRequest the web request to create an output message from
   * @return the output message
   */
  protected ServletServerHttpResponse createOutputMessage(NativeWebRequest webRequest) {
    HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
    return new ServletServerHttpResponse(response);
  }
View Full Code Here

   */
  protected <T> void writeWithMessageConverters(T returnValue, MethodParameter returnType, NativeWebRequest webRequest)
      throws IOException, HttpMediaTypeNotAcceptableException {

    ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
    ServletServerHttpResponse outputMessage = createOutputMessage(webRequest);
    writeWithMessageConverters(returnValue, returnType, inputMessage, outputMessage);
  }
View Full Code Here

    if (returnValue == null) {
      return;
    }

    ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
    ServletServerHttpResponse outputMessage = createOutputMessage(webRequest);

    Assert.isInstanceOf(HttpEntity.class, returnValue);
    HttpEntity<?> responseEntity = (HttpEntity<?>) returnValue;
    if (responseEntity instanceof ResponseEntity) {
      outputMessage.setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
    }

    HttpHeaders entityHeaders = responseEntity.getHeaders();
    if (!entityHeaders.isEmpty()) {
      outputMessage.getHeaders().putAll(entityHeaders);
    }

    Object body = responseEntity.getBody();

    // Try even with null body. ResponseBodyAdvice could get involved.
    writeWithMessageConverters(body, returnType, inputMessage, outputMessage);

    // Ensure headers are flushed even if no body was written
    outputMessage.getBody();
  }
View Full Code Here

TOP

Related Classes of org.springframework.http.server.ServletServerHttpResponse$ServletResponseHttpHeaders

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.