Java Code Examples for io.undertow.util.HttpString#tryFromString()

The following examples show how to use io.undertow.util.HttpString#tryFromString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndertowXhrTransport.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example 2
Source File: UndertowXhrTransport.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example 3
Source File: MethodPredicate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
MethodPredicate(String[] methods) {
    HttpString[] values = new HttpString[methods.length];
    for(int i = 0; i < methods.length; ++i) {
        values[i] = HttpString.tryFromString(methods[i]);
    }
    this.methods = values;
}
 
Example 4
Source File: ResponseHeaderAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{o,") && token.endsWith("}")) {
        final HttpString headerName = HttpString.tryFromString(token.substring(4, token.length() - 1));
        return new ResponseHeaderAttribute(headerName);
    }
    return null;
}
 
Example 5
Source File: RequestHeaderAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ExchangeAttribute build(final String token) {
    if (token.startsWith("%{i,") && token.endsWith("}")) {
        final HttpString headerName = HttpString.tryFromString(token.substring(4, token.length() - 1));
        return new RequestHeaderAttribute(headerName);
    }
    return null;
}
 
Example 6
Source File: UndertowXhrTransport.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.undertowBufferSupport.httpClientConnect(this.httpClient, clientCallback, url, worker, this.optionMap);
}
 
Example 7
Source File: RequestIDHandler.java    From galeb with Apache License 2.0 4 votes vote down vote up
public static HttpString requestIdHeader() {
    return HttpString.tryFromString(System.getProperty("REQUESTID_HEADER", SystemEnv.REQUESTID_HEADER.getValue()));
}
 
Example 8
Source File: ChunkReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public int handle(ByteBuffer buf) throws IOException {
    while (buf.hasRemaining()) {
        final byte b = buf.get();
        if (state == STATE_TRAILER_NAME) {
            if (b == '\r') {
                if (builder.length() == 0) {
                    state = STATE_ENDING;
                } else {
                    throw UndertowMessages.MESSAGES.couldNotDecodeTrailers();
                }
            } else if (b == '\n') {
                if (builder.length() == 0) {
                    attachable.putAttachment(trailerAttachmentKey, headerMap);
                    return -1;
                } else {
                    throw UndertowMessages.MESSAGES.couldNotDecodeTrailers();
                }
            } else if (b == ':') {
                httpString = HttpString.tryFromString(builder.toString().trim());
                state = STATE_TRAILER_VALUE;
                builder.setLength(0);
            } else {
                builder.append((char) b);
            }
        } else if (state == STATE_TRAILER_VALUE) {
            if (b == '\n') {
                headerMap.put(httpString, builder.toString().trim());
                httpString = null;
                builder.setLength(0);
                state = STATE_TRAILER_NAME;
            } else if (b != '\r') {
                builder.append((char) b);
            }
        } else if (state == STATE_ENDING) {
            if (b == '\n') {
                if (attachable != null) {
                    attachable.putAttachment(trailerAttachmentKey, headerMap);
                }
                return -1;
            } else {
                throw UndertowMessages.MESSAGES.couldNotDecodeTrailers();
            }
        } else {
            throw new IllegalStateException();
        }
    }
    return 0;
}