當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。