Example usage for org.springframework.http.server ServletServerHttpRequest ServletServerHttpRequest

List of usage examples for org.springframework.http.server ServletServerHttpRequest ServletServerHttpRequest

Introduction

In this page you can find the example usage for org.springframework.http.server ServletServerHttpRequest ServletServerHttpRequest.

Prototype

public ServletServerHttpRequest(HttpServletRequest servletRequest) 

Source Link

Document

Construct a new instance of the ServletServerHttpRequest based on the given HttpServletRequest .

Usage

From source file:com.expedia.seiso.web.resolver.ResolverUtils.java

public ServletServerHttpRequest wrapRequest(HttpServletRequest request) {
    return new ServletServerHttpRequest(request);
}

From source file:platform.filter.HttpPutDeleteFormContentFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    if (("PUT".equals(request.getMethod()) || "DELETE".equals(request.getMethod())
            || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
        HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
            @Override/*from w ww .  j  a  v a 2  s. com*/
            public InputStream getBody() throws IOException {
                return request.getInputStream();
            }
        };
        MultiValueMap<String, String> formParameters = formConverter.read(null, inputMessage);
        HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);
        filterChain.doFilter(wrapper, response);
    } else {
        filterChain.doFilter(request, response);
    }
}

From source file:newcontroller.handler.impl.DefaultRequest.java

@Override
public <T> T body(Class<T> clazz) {
    MediaType mediaType = MediaType.parseMediaType(this.request.getContentType());
    HttpMessageConverter converter = HttpMessageConvertersHelper.findConverter(this.converters, clazz,
            mediaType);//from  www  . j av  a 2 s . c om
    try {
        return clazz.cast(converter.read(clazz, new ServletServerHttpRequest(this.request)));
    } catch (IOException e) {
        throw new UncheckedIOException(e); // TODO
    }
}

From source file:com.nagarro.core.resolver.RestHandlerExceptionResolver.java

@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) {
    if (statusCodeMappings.containsKey(ex.getClass().getSimpleName())) {
        response.setStatus(statusCodeMappings.get(ex.getClass().getSimpleName()).intValue());
    } else {//from   w  ww  .  ja v  a  2s  .c  o m
        response.setStatus(DEFAULT_STATUS_CODE);
    }
    logger.warn(
            "Translating exception [" + ex.getClass().getName() + "]: " + YSanitizer.sanitize(ex.getMessage()));
    logger.error(ExceptionUtils.getStackTrace(ex));

    final List<ErrorWsDTO> errorList;
    if (ex instanceof WebserviceValidationException) {
        errorList = getWebserviceErrorFactory()
                .createErrorList(((WebserviceValidationException) ex).getValidationObject());
    } else {
        errorList = getWebserviceErrorFactory().createErrorList(ex);
    }
    final ErrorListWsDTO errorListDto = new ErrorListWsDTO();
    errorListDto.setErrors(errorList);

    final ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request);
    final ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

    try {
        return writeWithMessageConverters(errorListDto, inputMessage, outputMessage);
    } catch (final Exception handlerException) {
        logger.error("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
    }
    return null;
}

From source file:com.epam.reportportal.auth.OAuthSuccessHandler.java

@Override
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {
    OAuth2Authentication oauth = (OAuth2Authentication) authentication;
    OAuth2AccessToken accessToken = tokenServicesFacade.get().createToken(ReportPortalClient.ui,
            oauth.getName(), oauth.getUserAuthentication(), oauth.getOAuth2Request().getExtensions());

    MultiValueMap<String, String> query = new LinkedMultiValueMap<>();
    query.add("token", accessToken.getValue());
    query.add("token_type", accessToken.getTokenType());
    URI rqUrl = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request))
            .replacePath("/ui/authSuccess.html").replaceQueryParams(query).build().toUri();

    eventPublisher.publishEvent(new UiUserSignedInEvent(authentication));

    getRedirectStrategy().sendRedirect(request, response, rqUrl.toString());
}

From source file:io.pivotal.cla.mvc.util.UrlBuilder.java

public String build() {
    String url = UriComponentsBuilder //
            .fromHttpRequest(new ServletServerHttpRequest(request))//
            .replacePath(path) //
            .replaceQueryParams(params) //
            .build() //
            .toUriString(); //

    this.path = null;
    this.params.clear();
    if (url.contains("ngrok.io")) {
        url = url.replaceFirst(":80", "");
        url = url.replaceFirst("http:", "https:");
    }/*from w w  w.  j a v  a  2  s .co m*/
    return url;
}

From source file:org.springframework.cloud.aws.messaging.endpoint.AbstractNotificationMessageHandlerMethodArgumentResolver.java

private HttpInputMessage createInputMessage(NativeWebRequest webRequest) throws IOException {
    HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
    return new ServletServerHttpRequest(servletRequest);
}

From source file:gumga.framework.presentation.exceptionhandler.ErrorMessageHandlerExceptionResolver.java

/**
 * Copied from//from   w w w.  j av  a2  s .c  om
 * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver}
 */
@SuppressWarnings("unchecked")
private ModelAndView handleResponseBody(Object returnValue, ServletWebRequest webRequest)
        throws ServletException, IOException {

    HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest());
    List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
    if (acceptedMediaTypes.isEmpty()) {
        acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
    }
    MediaType.sortByQualityValue(acceptedMediaTypes);
    try (ServletServerHttpResponse 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)) {
                        messageConverter.write(returnValue, acceptedMediaType, outputMessage);
                        return new ModelAndView();
                    }
                }
            }
        }
        if (logger.isWarnEnabled()) {
            logger.warn("Could not find HttpMessageConverter that supports return type [" + returnValueType
                    + "] and " + acceptedMediaTypes);
        }
    }

    return null;
}

From source file:com.nagarro.core.resolver.OAuth2ExceptionHandlerExceptionResolver.java

@Override
protected ModelAndView doResolveException(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler, final Exception ex) {
    if (!OAuth2Exception.class.isAssignableFrom(ex.getClass())) {
        return null;
    }/*from www .j a va 2 s . com*/

    //TokenEndpoint exception handlers logic
    ResponseEntity<OAuth2Exception> responseEntity = null;
    final Exception exceptionToTranslate;
    if (ClientRegistrationException.class.isAssignableFrom(ex.getClass())) {
        exceptionToTranslate = new BadClientCredentialsException();
    } else {
        exceptionToTranslate = ex;
    }

    //Exception translation by WebResponseExceptionTranslator
    try {
        responseEntity = webResponseExceptionTranslator.translate(exceptionToTranslate);
    } catch (final Exception e) {
        logger.error("Translating of [" + exceptionToTranslate.getClass().getName() + "] resulted in Exception",
                e);
        return null;
    }

    final ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(request);
    final ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

    //get translated headers
    outputMessage.getHeaders().putAll(responseEntity.getHeaders());

    //set status
    outputMessage.setStatusCode(responseEntity.getStatusCode());

    final ErrorListWsDTO errorListDto = new ErrorListWsDTO();
    errorListDto.setErrors(getWebserviceErrorFactory().createErrorList(ex));

    try {
        return writeWithMessageConverters(errorListDto, inputMessage, outputMessage);
    } catch (final Exception handlerException) {
        logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException);
    }
    return null;
}

From source file:org.awesomeagile.webapp.config.SslRedirectConfig.java

@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override//from  w  w  w .  j a va2s.  c  o  m
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
            Server server = tomcat.getServer();

            Service service = new StandardService();
            service.setName("ssl-redirect-service");
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            connector.setPort(sslRedirectPort);
            service.addConnector(connector);
            server.addService(service);

            Engine engine = new StandardEngine();
            service.setContainer(engine);

            Host host = new StandardHost();
            host.setName("ssl-redirect-host");
            engine.addChild(host);
            engine.setDefaultHost(host.getName());

            Context context = new StandardContext();
            context.addLifecycleListener(new Tomcat.FixContextListener());
            context.setName("ssl-redirect-context");
            context.setPath("");
            host.addChild(context);

            Wrapper wrapper = context.createWrapper();
            wrapper.setServlet(new HttpServlet() {
                @Override
                public void service(HttpServletRequest req, HttpServletResponse res)
                        throws ServletException, IOException {
                    ServletServerHttpRequest r = new ServletServerHttpRequest(req);
                    UriComponentsBuilder b = UriComponentsBuilder.fromHttpRequest(r);
                    b.scheme("https");
                    b.port(null);
                    res.sendRedirect(b.toUriString());
                }
            });
            wrapper.setName("ssl-redirect-servlet");
            context.addChild(wrapper);
            context.addServletMapping("/", wrapper.getName());

            return super.getTomcatEmbeddedServletContainer(tomcat);
        }
    };
}