Search in sources :

Example 66 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project littlefisher-system by littlefishercoder.

the class SuccessControllerAdvice method beforeBodyWrite.

@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
    if (request instanceof ServletServerHttpRequest) {
        ServletServerHttpRequest httpRequest = (ServletServerHttpRequest) request;
        String servletPath = httpRequest.getServletRequest().getServletPath();
        if (servletPath.startsWith(BaseConstants.BASE_API_PREFIX)) {
            logger.debug("对{}开头的请求,返回信息进行封装", BaseConstants.BASE_API_PREFIX);
            if (!(body instanceof CommonResponse)) {
                return new CommonResponse(EnumResult.SUCCESS, body);
            }
        }
    }
    return body;
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest)

Example 67 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project CzechIdMng by bcvsolutions.

the class RequestResourceResolver method resolve.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> T resolve(HttpServletRequest nativeRequest, Class<T> domainType, T objectToUpdate) throws HttpMessageNotReadableException {
    ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest);
    IncomingRequest incoming = new IncomingRequest(request);
    MediaType contentType = request.getHeaders().getContentType();
    for (HttpMessageConverter converter : messageConverters) {
        if (!converter.canRead(PersistentEntityResource.class, contentType)) {
            continue;
        }
        T obj = (T) read(domainType, incoming, converter, objectToUpdate);
        if (obj == null) {
            throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, domainType));
        }
        return obj;
    }
    throw new HttpMessageNotReadableException(String.format(NO_CONVERTER_FOUND, domainType, contentType));
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) PersistentEntityResource(org.springframework.data.rest.webmvc.PersistentEntityResource) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MediaType(org.springframework.http.MediaType) IncomingRequest(org.springframework.data.rest.webmvc.IncomingRequest)

Example 68 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project portal by ixinportal.

the class MobileHandShakeInterceptor method beforeHandshake.

@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
    log.info("准备进行握手");
    if (request instanceof ServletServerHttpRequest) {
        List<String> appIds = request.getHeaders().get("appId");
        if (appIds.isEmpty()) {
            return false;
        }
        String appId = appIds.get(0);
        List<String> signatures = request.getHeaders().get("Content-Signature");
        if (StringUtils.isBlank(appId) || signatures.isEmpty()) {
            return false;
        }
        String signature = signatures.get(0);
        if (StringUtils.isBlank(signature)) {
            return false;
        }
        ApplicationInfo applicationInfo1 = applicationInfo.getApplicationInfo(appId);
        // }
        if (!signature.equals(Base64.encode(HMACSHA1.getHmacSHA1(appId, applicationInfo1.getSecretKey()), false))) {
            // secretKey // TODO: 2017/11/27
            return false;
        }
        attributes.put("appId", appId);
    // System.out.println(attributes.get("appId").toString());
    }
    return true;
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ApplicationInfo(com.itrus.portal.db.ApplicationInfo)

Example 69 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project connectors-workspace-one by vmware.

the class ConnectorRootController method getRoot.

@GetMapping(path = "/", produces = MediaTypes.HAL_JSON_VALUE)
public ResponseEntity<ResourceSupport> getRoot(HttpServletRequest servletRequest) {
    HttpRequest request = new ServletServerHttpRequest(servletRequest);
    ResourceSupport resource = new ResourceSupport();
    addMetadata(resource, request);
    addCards(resource, request);
    addImage(resource, request);
    addAuth(resource, request);
    return ResponseEntity.ok().cacheControl(CacheControl.maxAge(maxAge, unit)).body(resource);
}
Also used : HttpRequest(org.springframework.http.HttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) ResourceSupport(org.springframework.hateoas.ResourceSupport) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 70 with ServletServerHttpRequest

use of org.springframework.http.server.ServletServerHttpRequest in project spring-session by spring-projects.

the class SessionRepositoryMessageInterceptorTests method beforeHandshakeNullSession.

@Test
public void beforeHandshakeNullSession() throws Exception {
    ServletServerHttpRequest request = new ServletServerHttpRequest(new MockHttpServletRequest());
    assertThat(this.interceptor.beforeHandshake(request, null, null, null)).isTrue();
    verifyZeroInteractions(this.sessionRepository);
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)111 Test (org.junit.jupiter.api.Test)39 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)39 HttpRequest (org.springframework.http.HttpRequest)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 ServletServerHttpResponse (org.springframework.http.server.ServletServerHttpResponse)22 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 ServerHttpRequest (org.springframework.http.server.ServerHttpRequest)13 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)10 IOException (java.io.IOException)8 ServerHttpResponse (org.springframework.http.server.ServerHttpResponse)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 HttpHeaders (org.springframework.http.HttpHeaders)7 MediaType (org.springframework.http.MediaType)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 HttpInputMessage (org.springframework.http.HttpInputMessage)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 URI (java.net.URI)4 ResponseEntity (org.springframework.http.ResponseEntity)4