本文整理汇总了Java中org.springframework.http.server.ServletServerHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java ServletServerHttpRequest类的具体用法?Java ServletServerHttpRequest怎么用?Java ServletServerHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletServerHttpRequest类属于org.springframework.http.server包,在下文中一共展示了ServletServerHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeBodyWrite
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
ResponseJSONP responseJsonp = returnType.getMethodAnnotation(ResponseJSONP.class);
if(responseJsonp == null){
responseJsonp = returnType.getContainingClass().getAnnotation(ResponseJSONP.class);
}
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
String callbackMethodName = servletRequest.getParameter(responseJsonp.callback());
if (!IOUtils.isValidJsonpQueryParam(callbackMethodName)) {
if (logger.isDebugEnabled()) {
logger.debug("Invalid jsonp parameter value:" + callbackMethodName);
}
callbackMethodName = null;
}
JSONPObject jsonpObject = new JSONPObject(callbackMethodName);
jsonpObject.addParameter(body);
beforeBodyWriteInternal(jsonpObject, selectedContentType, returnType, request, response);
return jsonpObject;
}
示例2: fromHttpRequestResetsPortBeforeSettingIt
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("X-Forwarded-Proto", "https");
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", 443);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(80);
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https", result.getScheme());
assertEquals("84.198.58.199", result.getHost());
assertEquals(-1, result.getPort());
assertEquals("/rest/mobile/users/1", result.getPath());
}
示例3: beforeHandshake
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
System.out.println("before handshake");
ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request;
HttpSession session = servletRequest.getServletRequest().getSession(false);
Long uid = (Long)session.getAttribute("uid");
if(uid == null){
return false;
}
//如果uid==null,afterConnectionEstablished不执行,协议转换不成功,报下面的错误
//websocket.html?uid=1990:56 WebSocket connection to 'ws://localhost:8080/ws?uid=1990' failed: Error during WebSocket handshake: Unexpected response code: 500
attributes.put("uid", uid);
return true;
// 如果这里返回false,浏览器会报下面这个错误
// WebSocket connection to 'ws://localhost:8080/ws' failed: Error during WebSocket handshake: Unexpected response code: 200
}
示例4: doFilterInternal
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Override
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
@Override
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);
}
}
示例5: buildRequestLog
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
/**
* Build log message for request in bound.
*
* @param request Request in bound.
* @return Log message.
* @since 1.0.0
*/
protected String buildRequestLog(HttpServletRequest request) {
ServerHttpRequest httpRequest = new ServletServerHttpRequest(request);
StringBuilder sb = new StringBuilder("Server has received a request").append(StringUtils.LF)
.append(" > ").append(httpRequest.getMethod()).append(" ").append(httpRequest.getURI()).append
(StringUtils.LF);
Map<String, String> headers = httpRequest.getHeaders().toSingleValueMap();
for (Map.Entry<String, String> entry : headers.entrySet()) {
sb.append(" > ").append(entry.getKey()).append(": ").append(entry.getValue()).append(StringUtils.LF);
}
sb.append(extractRequestPayload(request));
return sb.toString();
}
示例6: beforeBodyWriteInternal
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Override
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) {
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
for (String name : this.jsonpQueryParamNames) {
String value = servletRequest.getParameter(name);
if (value != null) {
if (!isValidJsonpQueryParam(value)) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring invalid jsonp parameter value: " + value);
}
continue;
}
MediaType contentTypeToUse = getContentType(contentType, request, response);
response.getHeaders().setContentType(contentTypeToUse);
bodyContainer.setJsonpFunction(value);
break;
}
}
}
示例7: resolveArgument
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws IOException, HttpMediaTypeNotSupportedException {
ServletServerHttpRequest inputMessage = createInputMessage(webRequest);
Type paramType = getHttpEntityType(parameter);
Object body = readWithMessageConverters(webRequest, parameter, paramType);
if (RequestEntity.class == parameter.getParameterType()) {
return new RequestEntity<Object>(body, inputMessage.getHeaders(),
inputMessage.getMethod(), inputMessage.getURI());
}
else {
return new HttpEntity<Object>(body, inputMessage.getHeaders());
}
}
示例8: isResourceNotModified
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
private boolean isResourceNotModified(ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) {
List<String> ifNoneMatch = inputMessage.getHeaders().getIfNoneMatch();
long ifModifiedSince = inputMessage.getHeaders().getIfModifiedSince();
String eTag = addEtagPadding(outputMessage.getHeaders().getETag());
long lastModified = outputMessage.getHeaders().getLastModified();
boolean notModified = false;
if (!ifNoneMatch.isEmpty() && (inputMessage.getHeaders().containsKey(HttpHeaders.IF_UNMODIFIED_SINCE)
|| inputMessage.getHeaders().containsKey(HttpHeaders.IF_MATCH))) {
// invalid conditional request, do not process
}
else if (lastModified != -1 && StringUtils.hasLength(eTag)) {
notModified = isETagNotModified(ifNoneMatch, eTag) && isTimeStampNotModified(ifModifiedSince, lastModified);
}
else if (lastModified != -1) {
notModified = isTimeStampNotModified(ifModifiedSince, lastModified);
}
else if (StringUtils.hasLength(eTag)) {
notModified = isETagNotModified(ifNoneMatch, eTag);
}
return notModified;
}
示例9: readWithMessageConverters
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Override
protected <T> Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter methodParam,
Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(servletRequest);
Object arg = readWithMessageConverters(inputMessage, methodParam, paramType);
if (arg == null) {
if (methodParam.getParameterAnnotation(RequestBody.class).required()) {
throw new HttpMessageNotReadableException("Required request body is missing: " +
methodParam.getMethod().toGenericString());
}
}
return arg;
}
示例10: initFromRequest
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
/**
* 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;
}
示例11: requestBodyAdvice
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void requestBodyAdvice() throws IOException {
RequestBodyAdvice requestAdvice = Mockito.mock(RequestBodyAdvice.class);
ResponseBodyAdvice<String> responseAdvice = Mockito.mock(ResponseBodyAdvice.class);
List<Object> advice = Arrays.asList(requestAdvice, responseAdvice);
RequestResponseBodyAdviceChain chain = new RequestResponseBodyAdviceChain(advice);
HttpInputMessage wrapped = new ServletServerHttpRequest(new MockHttpServletRequest());
given(requestAdvice.supports(this.paramType, String.class, this.converterType)).willReturn(true);
given(requestAdvice.beforeBodyRead(eq(this.request), eq(this.paramType), eq(String.class),
eq(this.converterType))).willReturn(wrapped);
assertSame(wrapped, chain.beforeBodyRead(this.request, this.paramType, String.class, this.converterType));
String modified = "body++";
given(requestAdvice.afterBodyRead(eq(this.body), eq(this.request), eq(this.paramType),
eq(String.class), eq(this.converterType))).willReturn(modified);
assertEquals(modified, chain.afterBodyRead(this.body, this.request, this.paramType,
String.class, this.converterType));
}
示例12: fromRequestWithForwardedHostAndPort
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Test
public void fromRequestWithForwardedHostAndPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(80);
request.setRequestURI("/mvc-showcase");
request.addHeader("X-Forwarded-Proto", "https");
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", "443");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
}
示例13: fromHttpRequest
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequest() throws URISyntaxException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(-1);
request.setRequestURI("/path");
request.setQueryString("a=1");
UriComponents result = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)).build();
assertEquals("http", result.getScheme());
assertEquals("localhost", result.getHost());
assertEquals(-1, result.getPort());
assertEquals("/path", result.getPath());
assertEquals("a=1", result.getQuery());
}
示例14: fromHttpRequestWithForwardedHostWithForwardedScheme
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestWithForwardedHostWithForwardedScheme() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(10080);
request.addHeader("X-Forwarded-Host", "example.org");
request.addHeader("X-Forwarded-Proto", "https");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("example.org", result.getHost());
assertEquals("https", result.getScheme());
assertEquals(-1, result.getPort());
}
示例15: fromHttpRequestWithForwardedProtoAndDefaultPort
import org.springframework.http.server.ServletServerHttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestWithForwardedProtoAndDefaultPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setScheme("http");
request.setServerName("localhost");
request.setServerPort(80);
request.setRequestURI("/mvc-showcase");
request.addHeader("X-Forwarded-Proto", "https");
request.addHeader("X-Forwarded-Host", "84.198.58.199");
request.addHeader("X-Forwarded-Port", "443");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
}