Java Code Examples for io.undertow.server.HttpServerExchange#addResponseWrapper()
The following examples show how to use
io.undertow.server.HttpServerExchange#addResponseWrapper() .
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: SingleSignOnAuthenticationMechanism.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) { Cookie cookie = exchange.getRequestCookies().get(cookieName); if (cookie != null) { final String ssoId = cookie.getValue(); log.tracef("Found SSO cookie %s", ssoId); try (SingleSignOn sso = this.singleSignOnManager.findSingleSignOn(ssoId)) { if (sso != null) { if(log.isTraceEnabled()) { log.tracef("SSO session with ID: %s found.", ssoId); } Account verified = getIdentityManager(securityContext).verify(sso.getAccount()); if (verified == null) { if(log.isTraceEnabled()) { log.tracef("Account not found. Returning 'not attempted' here."); } //we return not attempted here to allow other mechanisms to proceed as normal return AuthenticationMechanismOutcome.NOT_ATTEMPTED; } final Session session = getSession(exchange); registerSessionIfRequired(sso, session); securityContext.authenticationComplete(verified, sso.getMechanismName(), false); securityContext.registerNotificationReceiver(new NotificationReceiver() { @Override public void handleNotification(SecurityNotification notification) { if (notification.getEventType() == SecurityNotification.EventType.LOGGED_OUT) { singleSignOnManager.removeSingleSignOn(sso); } } }); log.tracef("Authenticated account %s using SSO", verified.getPrincipal().getName()); return AuthenticationMechanismOutcome.AUTHENTICATED; } } clearSsoCookie(exchange); } exchange.addResponseWrapper(responseListener); return AuthenticationMechanismOutcome.NOT_ATTEMPTED; }
Example 2
Source File: EncodingHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { next.handleRequest(exchange); } else if (encodings.isNoEncodingsAllowed()) { noEncodingHandler.handleRequest(exchange); } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); next.handleRequest(exchange); } }
Example 3
Source File: ValidatorHandler.java From light-rest-4j with Apache License 2.0 | 5 votes |
private void validateResponse(HttpServerExchange exchange, OpenApiOperation openApiOperation) { exchange.addResponseWrapper((factory, exchange12) -> new StoreResponseStreamSinkConduit(factory.create(), exchange12)); exchange.addExchangeCompleteListener((exchange1, nextListener) ->{ Status status = responseValidator.validateResponse(exchange, openApiOperation); if(status != null) { logger.error("Response validation error: {} \n with response body: {}", status.getDescription(), new String(exchange.getAttachment(StoreResponseStreamSinkConduit.RESPONSE))); } nextListener.proceed(); }); }
Example 4
Source File: ResponseEncodeHandler.java From light-4j with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange); if (encodings == null || !exchange.isResponseChannelAvailable()) { Handler.next(exchange, next); } else if (encodings.isNoEncodingsAllowed()) { setExchangeStatus(exchange, NO_ENCODING_HANDLER); return; } else { exchange.addResponseWrapper(encodings); exchange.putAttachment(AllowedContentEncodings.ATTACHMENT_KEY, encodings); Handler.next(exchange, next); } }
Example 5
Source File: DumpHandler.java From light-4j with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.isInIoThread()) { exchange.dispatch(this); return; } if(isEnabled()) { Map<String, Object> result = new LinkedHashMap<>(); //create rootDumper which will do dumping. RootDumper rootDumper = new RootDumper(config, exchange); //dump request info into result right away rootDumper.dumpRequest(result); //only add response wrapper when response config is not set to "false" if(config.isResponseEnabled()) { //set Conduit to the conduit chain to store response body exchange.addResponseWrapper((factory, exchange12) -> new StoreResponseStreamSinkConduit(factory.create(), exchange12)); } //when complete exchange, dump response info to result, and log the result. exchange.addExchangeCompleteListener((exchange1, nextListener) ->{ rootDumper.dumpResponse(result); //log the result DumpHelper.logResult(result, config); nextListener.proceed(); }); } Handler.next(exchange, next); }
Example 6
Source File: ManagementHttpServer.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(exchange.getRequestHeaders().contains(Headers.UPGRADE)) { exchange.addResponseWrapper((factory, ex) -> { StreamSinkConduit ret = factory.create(); if(exchange.getResponseHeaders().contains(Headers.UPGRADE)) { exchange.getResponseHeaders().add(Headers.CONTENT_LENGTH, "0"); } return ret; }); } next.handleRequest(exchange); }
Example 7
Source File: ResponseRateLimitingHandler.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.addResponseWrapper(WRAPPER); next.handleRequest(exchange); }
Example 8
Source File: ResponseDelayingHandler.java From divolte-collector with Apache License 2.0 | 4 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { exchange.addResponseWrapper(WRAPPER); next.handleRequest(exchange); }