当前位置: 首页>>代码示例>>Java>>正文


Java ServerHttpRequest.getHeaders方法代码示例

本文整理汇总了Java中org.springframework.http.server.ServerHttpRequest.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ServerHttpRequest.getHeaders方法的具体用法?Java ServerHttpRequest.getHeaders怎么用?Java ServerHttpRequest.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.http.server.ServerHttpRequest的用法示例。


在下文中一共展示了ServerHttpRequest.getHeaders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upgrade

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
@Override
public void upgrade(ServerHttpRequest request, ServerHttpResponse response,
		String selectedProtocol, List<WebSocketExtension> selectedExtensions, Principal user,
		WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException {

	HttpHeaders headers = request.getHeaders();
	InetSocketAddress localAddr = request.getLocalAddress();
	InetSocketAddress remoteAddr = request.getRemoteAddress();

	StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user);
	StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session);

	List<Extension> extensions = new ArrayList<Extension>();
	for (WebSocketExtension extension : selectedExtensions) {
		extensions.add(new WebSocketToStandardExtensionAdapter(extension));
	}

	upgradeInternal(request, response, selectedProtocol, extensions, endpoint);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractStandardUpgradeStrategy.java

示例2: upgradeInternal

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
		String selectedProtocol, List<Extension> extensions, Endpoint endpoint)
		throws HandshakeFailureException {

	HttpServletRequest servletRequest = getHttpServletRequest(request);
	HttpServletResponse servletResponse = getHttpServletResponse(response);

	TyrusServerContainer serverContainer = (TyrusServerContainer) getContainer(servletRequest);
	TyrusWebSocketEngine engine = (TyrusWebSocketEngine) serverContainer.getWebSocketEngine();
	Object tyrusEndpoint = null;
	boolean success;

	try {
		// Shouldn't matter for processing but must be unique
		String path = "/" + random.nextLong();
		tyrusEndpoint = createTyrusEndpoint(endpoint, path, selectedProtocol, extensions, serverContainer, engine);
		getEndpointHelper().register(engine, tyrusEndpoint);

		HttpHeaders headers = request.getHeaders();
		RequestContext requestContext = createRequestContext(servletRequest, path, headers);
		TyrusUpgradeResponse upgradeResponse = new TyrusUpgradeResponse();
		UpgradeInfo upgradeInfo = engine.upgrade(requestContext, upgradeResponse);
		success = SUCCESS.equals(upgradeInfo.getStatus());
		if (success) {
			if (logger.isTraceEnabled()) {
				logger.trace("Successful request upgrade: " + upgradeResponse.getHeaders());
			}
			handleSuccess(servletRequest, servletResponse, upgradeInfo, upgradeResponse);
		}
	}
	catch (Exception ex) {
		unregisterTyrusEndpoint(engine, tyrusEndpoint);
		throw new HandshakeFailureException("Error during handshake: " + request.getURI(), ex);
	}

	unregisterTyrusEndpoint(engine, tyrusEndpoint);
	if (!success) {
		throw new HandshakeFailureException("Unexpected handshake failure: " + request.getURI());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:AbstractTyrusRequestUpgradeStrategy.java

示例3: handleInitialRequest

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
/**
 * Handle the first request for receiving messages on a SockJS HTTP transport
 * based session.
 * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request
 * after writing the open frame. Streaming-based transports ("xhr_streaming",
 * "eventsource", and "htmlfile") leave the response open longer for further
 * streaming of message frames but will also close it eventually after some
 * amount of data has been sent.
 * @param request the current request
 * @param response the current response
 * @param frameFormat the transport-specific SocksJS frame format to use
 */
public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response,
		SockJsFrameFormat frameFormat) throws SockJsException {

	this.uri = request.getURI();
	this.handshakeHeaders = request.getHeaders();
	this.principal = request.getPrincipal();
	this.localAddress = request.getLocalAddress();
	this.remoteAddress = request.getRemoteAddress();

	synchronized (this.responseLock) {
		try {
			this.response = response;
			this.frameFormat = frameFormat;
			this.asyncRequestControl = request.getAsyncRequestControl(response);
			this.asyncRequestControl.start(-1);

			disableShallowEtagHeaderFilter(request);

			// Let "our" handler know before sending the open frame to the remote handler
			delegateConnectionEstablished();

			handleRequestInternal(request, response, true);

			// Request might have been reset (e.g. polling sessions do after writing)
			this.readyToSend = isActive();
		}
		catch (Throwable ex) {
			tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to open session", getId(), ex);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:45,代码来源:AbstractHttpSockJsSession.java

示例4: getContentType

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
@Test
public void getContentType() throws Exception {
	MultipartFile part = new MockMultipartFile("part", "", "application/json", "content".getBytes("UTF-8"));
	this.mockRequest.addFile(part);
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");

	HttpHeaders headers = request.getHeaders();
	assertNotNull(headers);
	assertEquals(MediaType.APPLICATION_JSON, headers.getContentType());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:RequestPartServletServerHttpRequestTests.java

示例5: beforeBodyWrite

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
    if (body instanceof Response) {


        Response responseBody = (Response) body;
        if (body == null) {
            responseBody = new UnknownResponse();
            responseBody.setResultCode(HttpStatus.OK.value());
            responseBody.setResultMessage(HttpStatus.OK.getReasonPhrase());
        } else {
            if (responseBody.getResultCode() == null) {
                responseBody.setResultCode(HttpStatus.OK.value());
                responseBody.setResultMessage(HttpStatus.OK.getReasonPhrase());
            }
            if (responseBody.getResultMessage() == null) {
                try {
                    responseBody.setResultMessage(HttpStatus.valueOf(responseBody.getResultCode()).getReasonPhrase());
                } catch (IllegalArgumentException e) {
                    responseBody.setResultMessage("Unknown");
                }
            }
        }
        HttpHeaders httpHeaders = request.getHeaders();
        Map<String, List<String>> requestHeader = responseBody.getRequestHeader();
        for (Map.Entry<String, List<String>> entry : httpHeaders.entrySet()) {
            requestHeader.put(entry.getKey(), entry.getValue());
        }
        responseBody.setMethod(request.getMethod().name());
        return responseBody;
    } else {
        return body;
    }
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:35,代码来源:ResponseEntityAdvice.java

示例6: doHandshake

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
@Override
public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, Map<String, Object> attributes) throws HandshakeFailureException {

	WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHeaders());
	if (logger.isTraceEnabled()) {
		logger.trace("Processing request " + request.getURI() + " with headers=" + headers);
	}
	try {
		if (HttpMethod.GET != request.getMethod()) {
			response.setStatusCode(HttpStatus.METHOD_NOT_ALLOWED);
			response.getHeaders().setAllow(Collections.singleton(HttpMethod.GET));
			if (logger.isErrorEnabled()) {
				logger.error("Handshake failed due to unexpected HTTP method: " + request.getMethod());
			}
			return false;
		}
		if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) {
			handleInvalidUpgradeHeader(request, response);
			return false;
		}
		if (!headers.getConnection().contains("Upgrade") && !headers.getConnection().contains("upgrade")) {
			handleInvalidConnectHeader(request, response);
			return false;
		}
		if (!isWebSocketVersionSupported(headers)) {
			handleWebSocketVersionNotSupported(request, response);
			return false;
		}
		if (!isValidOrigin(request)) {
			response.setStatusCode(HttpStatus.FORBIDDEN);
			return false;
		}
		String wsKey = headers.getSecWebSocketKey();
		if (wsKey == null) {
			if (logger.isErrorEnabled()) {
				logger.error("Missing \"Sec-WebSocket-Key\" header");
			}
			response.setStatusCode(HttpStatus.BAD_REQUEST);
			return false;
		}
	}
	catch (IOException ex) {
		throw new HandshakeFailureException(
				"Response update failed during upgrade to WebSocket: " + request.getURI(), ex);
	}

	String subProtocol = selectProtocol(headers.getSecWebSocketProtocol(), wsHandler);
	List<WebSocketExtension> requested = headers.getSecWebSocketExtensions();
	List<WebSocketExtension> supported = this.requestUpgradeStrategy.getSupportedExtensions(request);
	List<WebSocketExtension> extensions = filterRequestedExtensions(request, requested, supported);
	Principal user = determineUser(request, wsHandler, attributes);

	if (logger.isTraceEnabled()) {
		logger.trace("Upgrading to WebSocket, subProtocol=" + subProtocol + ", extensions=" + extensions);
	}
	this.requestUpgradeStrategy.upgrade(request, response, subProtocol, extensions, user, wsHandler, attributes);
	return true;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:60,代码来源:AbstractHandshakeHandler.java

示例7: getHeadersToUse

import org.springframework.http.server.ServerHttpRequest; //导入方法依赖的package包/类
private List<String> getHeadersToUse(ServerHttpRequest request, boolean isPreFlight) {
	HttpHeaders headers = request.getHeaders();
	return (isPreFlight ? headers.getAccessControlRequestHeaders() : new ArrayList<String>(headers.keySet()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:DefaultCorsProcessor.java


注:本文中的org.springframework.http.server.ServerHttpRequest.getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。