Java Code Examples for io.undertow.server.HttpServerExchange#getQueryString()
The following examples show how to use
io.undertow.server.HttpServerExchange#getQueryString() .
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: SinglePortConfidentialityHandler.java From quarkus-http with Apache License 2.0 | 6 votes |
protected URI getRedirectURI(HttpServerExchange exchange, int port) throws URISyntaxException { String host = exchange.getHostName(); String queryString = exchange.getQueryString(); String uri = exchange.getRequestURI(); if(exchange.isHostIncludedInRequestURI()) { int slashCount = 0; for(int i = 0; i < uri.length(); ++i) { if(uri.charAt(i) == '/') { slashCount++; if(slashCount == 3) { uri = uri.substring(i); break; } } } } return new URI("https", null, host, port, uri, queryString == null || queryString.length() == 0 ? null : queryString, null); }
Example 2
Source File: HttpErrorLoggerExtension.java From hawkular-metrics with Apache License 2.0 | 6 votes |
@Override public void exchangeEvent(HttpServerExchange exchange, ExchangeCompletionListener.NextListener nextListener) { int httpStatusCode = exchange.getStatusCode(); if (httpStatusCode >= StatusCodes.BAD_REQUEST) { final String path; final String query = exchange.getQueryString(); if (!query.isEmpty()) { path = exchange.getRequestPath() + "?" + query; } else { path = exchange.getRequestPath(); } HttpString method = exchange.getRequestMethod(); log.warnf("Endpoint %s %s fails with HTTP code: %d", method, path, httpStatusCode); } nextListener.proceed(); }
Example 3
Source File: RequestTimeLogger.java From hawkular-metrics with Apache License 2.0 | 6 votes |
@Override public void exchangeEvent(HttpServerExchange exchange, NextListener nextListener) { try { long end = System.currentTimeMillis(); long duration = end - start; if (duration > this.timeThreshold) { String method = exchange.getRequestMethod().toString(); String query = exchange.getQueryString(); String request_url = exchange.getRequestURI() + (query.isEmpty() ? "" : ("?" + query)); HeaderMap headers = exchange.getRequestHeaders(); if (headers.contains(tenantHeader)) { String tenantId = headers.get(tenantHeader, 0); log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, tenant-id: %s", method, request_url, duration, timeThreshold, tenantId); } else { log.warnf("Request %s %s took: %d ms, exceeds %d ms threshold, no tenant", method, request_url, duration, timeThreshold); } } } finally { if (nextListener != null) { nextListener.proceed(); } } }
Example 4
Source File: LearningPushHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String fullPath; String requestPath; if(exchange.getQueryString().isEmpty()) { fullPath = exchange.getRequestURL(); requestPath = exchange.getRequestPath(); } else{ fullPath = exchange.getRequestURL() + "?" + exchange.getQueryString(); requestPath = exchange.getRequestPath() + "?" + exchange.getQueryString(); } doPush(exchange, fullPath); String referrer = exchange.getRequestHeaders().getFirst(Headers.REFERER); if (referrer != null) { String accept = exchange.getRequestHeaders().getFirst(Headers.ACCEPT); if (accept == null || !accept.contains("text/html")) { //if accept contains text/html it generally means the user has clicked //a link to move to a new page, and is not a resource load for the current page //we only care about resources for the current page exchange.addExchangeCompleteListener(new PushCompletionListener(fullPath, requestPath, referrer)); } } next.handleRequest(exchange); }
Example 5
Source File: SinglePortConfidentialityHandler.java From lams with GNU General Public License v2.0 | 6 votes |
protected URI getRedirectURI(HttpServerExchange exchange, int port) throws URISyntaxException { String host = exchange.getHostName(); String queryString = exchange.getQueryString(); String uri = exchange.getRequestURI(); if(exchange.isHostIncludedInRequestURI()) { int slashCount = 0; for(int i = 0; i < uri.length(); ++i) { if(uri.charAt(i) == '/') { slashCount++; if(slashCount == 3) { uri = uri.substring(i); break; } } } } return new URI("https", null, host, port, uri, queryString == null || queryString.length() == 0 ? null : queryString, null); }
Example 6
Source File: SikulixServer.java From SikuliX1 with MIT License | 6 votes |
private String[] getScriptArgs(final HttpServerExchange exchange) { String[] args = {}; Optional<String> argsString = Optional.empty(); String queryString = exchange.getQueryString(); if (queryString != null) { Matcher matcher = PATTERN_QUERY_ARGS.matcher(queryString); if (matcher.find()) { argsString = Optional.of(matcher.group("args")); } } if (exchange.getRequestMethod().equals(Methods.POST)) { FormData form = exchange.getAttachment(FormDataParser.FORM_DATA); if (form != null) { argsString = Optional.ofNullable(form.getLast("args")).map(fVal -> fVal.getValue()); } } if (argsString.isPresent()) { StringBuilder buf = new StringBuilder(); String[] tokens = argsString.get().split(";"); args = new String[tokens.length]; for (int i=0; i<tokens.length; i++) { args[i] = URLUtils.decode(tokens[i], "UTF-8", true, buf); } } return args; }
Example 7
Source File: LearningPushHandler.java From quarkus-http with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { String fullPath; String requestPath; if(exchange.getQueryString().isEmpty()) { fullPath = exchange.getRequestURL(); requestPath = exchange.getRequestPath(); } else{ fullPath = exchange.getRequestURL() + "?" + exchange.getQueryString(); requestPath = exchange.getRequestPath() + "?" + exchange.getQueryString(); } doPush(exchange, fullPath); String referrer = exchange.getRequestHeader(HttpHeaderNames.REFERER); if (referrer != null) { String accept = exchange.getRequestHeader(HttpHeaderNames.ACCEPT); if (accept == null || !accept.contains("text/html")) { //if accept contains text/html it generally means the user has clicked //a link to move to a new page, and is not a resource load for the current page //we only care about resources for the current page exchange.addExchangeCompleteListener(new PushCompletionListener(fullPath, requestPath, referrer)); } } next.handleRequest(exchange); }
Example 8
Source File: SetAttributeTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final StringBuilder sb = new StringBuilder("URI: " + exchange.getRequestURI() + " relative: " + exchange.getRelativePath() + " QS:" + exchange.getQueryString()); for (Map.Entry<String, Deque<String>> param : exchange.getQueryParameters().entrySet()) { sb.append(" " + param.getKey() + ": " + param.getValue().getFirst()); } exchange.writeAsync(sb.toString()); }
Example 9
Source File: UndertowServerHttpRequest.java From java-technology-stack with MIT License | 5 votes |
private static URI initUri(HttpServerExchange exchange) throws URISyntaxException { Assert.notNull(exchange, "HttpServerExchange is required."); String requestURL = exchange.getRequestURL(); String query = exchange.getQueryString(); String requestUriAndQuery = StringUtils.isEmpty(query) ? requestURL : requestURL + "?" + query; return new URI(requestUriAndQuery); }
Example 10
Source File: JDBCLogHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public void logMessage(String pattern, HttpServerExchange exchange) { JDBCLogAttribute jdbcLogAttribute = new JDBCLogAttribute(); if (pattern.equals("combined")) { jdbcLogAttribute.pattern = pattern; } jdbcLogAttribute.remoteHost = ((InetSocketAddress) exchange.getSourceAddress()).getAddress().getHostAddress(); SecurityContext sc = exchange.getSecurityContext(); if (sc == null || !sc.isAuthenticated()) { jdbcLogAttribute.user = null; } else { jdbcLogAttribute.user = sc.getAuthenticatedAccount().getPrincipal().getName(); } jdbcLogAttribute.query = exchange.getQueryString(); jdbcLogAttribute.bytes = exchange.getResponseContentLength(); if (jdbcLogAttribute.bytes < 0) { jdbcLogAttribute.bytes = 0; } jdbcLogAttribute.status = exchange.getStatusCode(); if (jdbcLogAttribute.pattern.equals("combined")) { jdbcLogAttribute.virtualHost = exchange.getRequestHeader(HttpHeaderNames.HOST); jdbcLogAttribute.method = exchange.getRequestMethod(); jdbcLogAttribute.referer = exchange.getRequestHeader(HttpHeaderNames.REFERER); jdbcLogAttribute.userAgent = exchange.getRequestHeader(HttpHeaderNames.USER_AGENT); } this.pendingMessages.add(jdbcLogAttribute); int state = stateUpdater.get(this); if (state == 0) { if (stateUpdater.compareAndSet(this, 0, 1)) { this.executor = exchange.getWorker(); this.executor.execute(this); } } }
Example 11
Source File: StuckThreadDetectionHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void handleRequest(HttpServerExchange exchange) throws Exception { // Save the thread/runnable // Keeping a reference to the thread object here does not prevent // GC'ing, as the reference is removed from the Map in the finally clause Long key = Thread.currentThread().getId(); MonitoredThread monitoredThread = new MonitoredThread(Thread.currentThread(), exchange.getRequestURI() + exchange.getQueryString()); activeThreads.put(key, monitoredThread); if (timerKey == null) { synchronized (this) { if (timerKey == null) { timerKey = exchange.getIoThread().schedule(new StuckThreadTask(exchange.getIoThread()), 1, TimeUnit.SECONDS); } } } try { next.handleRequest(exchange); } finally { activeThreads.remove(key); if (monitoredThread.markAsDone() == MonitoredThreadState.STUCK) { completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis())); } } }
Example 12
Source File: QueryStringAttribute.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { String qs = exchange.getQueryString(); if(qs.isEmpty() || !includeQuestionMark) { return qs; } return '?' + qs; }
Example 13
Source File: StuckThreadDetectionHandler.java From lams with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void handleRequest(HttpServerExchange exchange) throws Exception { // Save the thread/runnable // Keeping a reference to the thread object here does not prevent // GC'ing, as the reference is removed from the Map in the finally clause Long key = Thread.currentThread().getId(); MonitoredThread monitoredThread = new MonitoredThread(Thread.currentThread(), exchange.getRequestURI() + exchange.getQueryString()); activeThreads.put(key, monitoredThread); if(timerKey == null) { synchronized (this) { if(timerKey == null) { timerKey = exchange.getIoThread().executeAfter(stuckThreadTask, 1, TimeUnit.SECONDS); } } } try { next.handleRequest(exchange); } finally { activeThreads.remove(key); if (monitoredThread.markAsDone() == MonitoredThreadState.STUCK) { completedStuckThreadsQueue.add( new CompletedStuckThread(monitoredThread.getThread(), monitoredThread.getActiveTimeInMillis())); } } }
Example 14
Source File: JDBCLogHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public void logMessage(String pattern, HttpServerExchange exchange) { JDBCLogAttribute jdbcLogAttribute = new JDBCLogAttribute(); if (pattern.equals("combined")) { jdbcLogAttribute.pattern = pattern; } jdbcLogAttribute.remoteHost = ((InetSocketAddress) exchange.getConnection().getPeerAddress()).getAddress().getHostAddress(); SecurityContext sc = exchange.getSecurityContext(); if (sc == null || !sc.isAuthenticated()) { jdbcLogAttribute.user = null; } else { jdbcLogAttribute.user = sc.getAuthenticatedAccount().getPrincipal().getName(); } jdbcLogAttribute.query = exchange.getQueryString(); jdbcLogAttribute.bytes = exchange.getResponseContentLength(); if (jdbcLogAttribute.bytes < 0) { jdbcLogAttribute.bytes = 0; } jdbcLogAttribute.status = exchange.getStatusCode(); if (jdbcLogAttribute.pattern.equals("combined")) { jdbcLogAttribute.virtualHost = exchange.getRequestHeaders().getFirst(Headers.HOST); jdbcLogAttribute.method = exchange.getRequestMethod().toString(); jdbcLogAttribute.referer = exchange.getRequestHeaders().getFirst(Headers.REFERER); jdbcLogAttribute.userAgent = exchange.getRequestHeaders().getFirst(Headers.USER_AGENT); } this.pendingMessages.add(jdbcLogAttribute); int state = stateUpdater.get(this); if (state == 0) { if (stateUpdater.compareAndSet(this, 0, 1)) { this.executor = exchange.getConnection().getWorker(); this.executor.execute(this); } } }
Example 15
Source File: QueryStringAttribute.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { String qs = exchange.getQueryString(); if(qs.isEmpty() || !includeQuestionMark) { return qs; } return '?' + qs; }
Example 16
Source File: UndertowServerHttpRequest.java From spring-analysis-note with MIT License | 5 votes |
private static URI initUri(HttpServerExchange exchange) throws URISyntaxException { Assert.notNull(exchange, "HttpServerExchange is required"); String requestURL = exchange.getRequestURL(); String query = exchange.getQueryString(); String requestUriAndQuery = (StringUtils.hasLength(query) ? requestURL + "?" + query : requestURL); return new URI(requestUriAndQuery); }
Example 17
Source File: ClientSideCookieEventHandler.java From divolte-collector with Apache License 2.0 | 5 votes |
private static String getFullUrl(final HttpServerExchange exchange) { final String queryString = exchange.getQueryString(); final String requestUrl = exchange.getRequestURL(); return Strings.isNullOrEmpty(queryString) ? requestUrl : requestUrl + '?' + queryString; }
Example 18
Source File: LogoutHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final HeaderMap requestHeaders = exchange.getRequestHeaders(); final HeaderMap responseHeaders = exchange.getResponseHeaders(); String referrer = responseHeaders.getFirst(REFERER); String protocol = exchange.getRequestScheme(); String host = null; if (referrer != null) { try { URI uri = new URI(referrer); protocol = uri.getScheme(); host = uri.getHost() + portPortion(protocol, uri.getPort()); } catch (URISyntaxException e) { } } if (host == null) { host = requestHeaders.getFirst(HOST); if (host == null) { exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR); return; } } /* * Main sequence of events: * * 1. Redirect to self using user:pass@host form of authority. This forces Safari to overwrite its cache. (Also * forces FF and Chrome, but not absolutely necessary) Set the exit flag as a state signal for step 3 * * 2. Send 401 digest without a nonce stale marker, this will force FF and Chrome and likely other browsers to * assume an invalid (old) password. In the case of Opera, which doesn't invalidate under such a circumstance, * send an invalid realm. This will overwrite its auth cache, since it indexes it by host and not realm. * * 3. The credentials in 307 redirect wlll be transparently accepted and a final redirect to the console is * performed. Opera ignores these, so the user must hit escape which will use javascript to perform the redirect * * In the case of Internet Explorer, all of this will be bypassed and will simply redirect to the console. The console * MUST use a special javascript call before redirecting to logout. */ String userAgent = requestHeaders.getFirst(USER_AGENT); boolean opera = userAgent != null && userAgent.contains("Opera"); boolean win = !opera && userAgent != null && (userAgent.contains("MSIE") || userAgent.contains("Trident")); String rawQuery = exchange.getQueryString(); boolean exit = rawQuery != null && rawQuery.contains(EXIT); if (win) { responseHeaders.add(LOCATION, protocol + "://" + host + "/"); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } else { // Do the redirects to finish the logout String authorization = requestHeaders.getFirst(AUTHORIZATION); boolean digest = true; Map<String, Deque<String>> parameters = exchange.getQueryParameters(); if (parameters.containsKey(MECHANISM)) { digest = !BASIC.equals(parameters.get(MECHANISM).getFirst()); } if (authorization != null && authorization.length() > BASIC.length() && BASIC.equalsIgnoreCase(authorization.substring(0, BASIC.length()))) { digest = false; ByteBuffer decode = FlexBase64.decode(authorization.substring(6)); authorization = new String(decode.array(), decode.arrayOffset(), decode.limit(), UTF_8); } if (authorization == null || !authorization.contains("enter-login-here")) { if (!exit) { responseHeaders.add(LOCATION, protocol + "://enter-login-here:blah@" + host + "/logout?" + EXIT + "&" + MECHANISM + "=" + (digest ? DIGEST : BASIC)); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); return; } mechanism(opera, digest).sendChallenge(exchange, null); String reply = "<html><script type='text/javascript'>window.location=\"" + protocol + "://" + host + "/\";</script></html>"; exchange.setStatusCode(StatusCodes.UNAUTHORIZED); exchange.getResponseSender().send(reply, IoCallback.END_EXCHANGE); return; } // Success, now back to the login screen responseHeaders.add(LOCATION, protocol + "://" + host + "/"); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } }