Retrieves the complete request body from the request

@param exchange The Undertow HttpServerExchange
@return A body object containing the request body

@throws IOException
513301
protected String getRequestBody(HttpServerExchange exchange) throws IOException {
        String body = "";
        if (RequestUtils.isPostPutPatch(exchange)) {
            exchange.startBlocking();
            body = IOUtils.toString(exchange.getInputStream(), Default.ENCODING.toString());
        }

        return body;
    }
1097528
protected void nextHandler(HttpServerExchange exchange) throws Exception {
        if (this.attachment.hasBasicAuthentication()) {
            HttpHandler httpHandler = RequestUtils.wrapBasicAuthentication(
                    Application.getInstance(LocaleHandler.class),
                    this.attachment.getUsername(),
                    getPassword());
            
            httpHandler.handleRequest(exchange);
        } else {
            Application.getInstance(LocaleHandler.class).handleRequest(exchange);    
        }
    }
1161666
@Override
   public Object invoke(Exchange exchange, Object o)
   {
      BindingOperationInfo bop = exchange.getBindingOperationInfo();
      MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
      List<Object> params = null;
      if (o instanceof List) {
         params = CastUtils.cast((List<?>) o);
      } else if (o != null) {
         params = new MessageContentsList(o);
      }
      final Object tb = (factory == null) ? targetBean : this.getServiceObject(exchange);
      final Method method = (bop == null) ? null : md.getMethod(bop);
      if (method == null)
      {
         throw Messages.MESSAGES.missingBindingOpeartionAndDispatchedMethod();
      }
      //performance optimization, adjustMethodAndParams currently looks for @UseAsyncMethod (which is expensive) and only performs actions if it's found
      final Method fm = checkForUseAsyncMethod ? adjustMethodAndParams(md.getMethod(bop), exchange, params, tb.getClass()) : method;
      return invoke(exchange, tb, fm, params);
   }
460583
@Override
    public void handleRequest(final HttpServerExchange exchange) throws Exception {
        if(exchange.isInIoThread()) {
            exchange.dispatch(this);
            return;
        }
        SecurityContext context = exchange.getSecurityContext();
        if (context.authenticate()) {
            if(!exchange.isComplete()) {
               next.handleRequest(exchange);
            }
        } else {
            if(exchange.getStatusCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
                ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
                src.getOriginalResponse().sendError(exchange.getStatusCode());
            } else {
                exchange.endExchange();
            }
        }
    }
757991
@Override
    public void process(Exchange exchange) throws Exception {
        if (log.isTraceEnabled()) {
            log.trace(exchange.toString());
        }

        if (pin.isOpen()) {

            KuraGPIOAction messageAction = exchange.getIn().getHeader(KuraGPIOConstants.CAMEL_KURA_GPIO_ACTION,
                    getAction(), KuraGPIOAction.class);

            if (messageAction == null) {
                log.trace("No action pick up body");
                output(exchange);
            } else {
                log.trace("action= {} ", action);
                switch (messageAction) {

                case TOGGLE:
                    pin.setValue(!pin.getValue());
                    break;

                case LOW:
                    pin.setValue(false);
                    break;

                case HIGH:
                    pin.setValue(true);
                    break;

                case BLINK:

                    pool.submit(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                Thread.sleep(getEndpoint().getDelay());
                                pin.setValue(!pin.getValue());
                                Thread.sleep(getEndpoint().getDuration());
                                pin.setValue(!pin.getValue());
                            } catch (Exception e) {
                                log.error("Thread interruption into BLINK sequence", e);
                            }
                        }
                    });

                    break;

                default:
                    log.error("Any action set found");
                    break;
                }
            }
        } else {
            log.warn("Pin {} is close", pin.getIndex());
        }
    }
155344
public static InputStream getRequestInputStream(ExternalContext ec)
            throws IOException
    {
        RequestType type = getRequestType(ec);
        if (type.isRequestFromClient())
        {
            Object req = ec.getRequest();
            if (type.isPortlet())
            {
                return (InputStream) _runMethod(req, "getPortletInputStream");
            }
            else
            {
                return ((ServletRequest) ec.getRequest()).getInputStream();
            }
        }

        return null;
    }
707391
private static UriComponentsBuilder getBuilder(@Nullable ServerWebExchange exchange) {

		return exchange == null //
				? UriComponentsBuilder.fromPath("/") //
				: UriComponentsBuilder.fromHttpRequest(exchange.getRequest());
	}
316343
@Override
    public HttpOutputStreamImpl getBody() {
        if (null == this.body) {
            if (HttpDispatcher.useEE7Streams()) {
                this.body = new HttpOutputStreamEE7(this.isc);
            } else {
                this.body = new HttpOutputStreamImpl(this.isc);
            }
            this.body.setVirtualConnection(this.connlink.getVirtualConnection());
            if (this.message != null) {
                long messageContentLength = getContentLength();
                if (messageContentLength != -1) { //it's set
                    this.body.setContentLength(getContentLength());
                }
            }
        }
        return this.body;
    }
1162029
private void attachFormDataBody(final HttpServerExchange exchange) throws IOException {
        Object data;
        FormParserFactory formParserFactory = FormParserFactory.builder().build();
        FormDataParser parser = formParserFactory.createParser(exchange);
        if (parser != null) {
            FormData formData = parser.parseBlocking();
            data = BodyConverter.convert(formData);
            exchange.putAttachment(REQUEST_BODY, data);
        }
    }
1084906
protected function doProcess(Exchange $exchange, SerializableArray $processingContext)
    {
        $itinerary = $exchange->getItinerary();

        if ($itinerary->getProcessorIdsCount() > 0) {
            $exchangeBackup = clone $exchange;

            // Take the next processor
            $processorId = $itinerary->shiftProcessorId();
            if (!$this->container->has($processorId)) {
                throw new \RuntimeException("Processor with $processorId not found in container.");
            }
            $processor = $this->container->get($processorId);
            if (!$processor instanceof ProcessorInterface) {
                throw new \RuntimeException('Processors must implement ProcessorInterface.');
            }

            // Prepend this processor
            $itinerary->unShiftProcessorId($this->getId());

            try {
                $processor->process($exchange);
            } catch (ProcessingException $exception) {
                $originalException = $exception->getOriginalException();

                // We try to catch the exception
                foreach ($this->catches as $catch) {
                    if ($this->evaluator->evaluateWithExchange($catch->getCondition(), $exchange, $originalException)) {
                        $exchange->setIn($exchangeBackup->getIn());
                        $exchange->setOut(null);
                        $exchange->setItinerary($catch->getItinerary());
                        if ($this->finallyItinerary) {
                            $exchange->getItinerary()->append($this->finallyItinerary);
                        }

                        return;
                    }
                }

                // If it's not catch, we just let go, if the exchange is retried, we will come to this processor again
                throw $originalException;
            }
        } elseif ($this->finallyItinerary) {
            $exchange->getItinerary()->prepend($this->finallyItinerary);
        }
    }
238314
protected Authentication getAuthenticationCookie(HttpServerExchange exchange) {
        Authentication authentication = Authentication.create().withSubject(null);
        
        String cookieValue = getCookieValue(exchange, this.config.getAuthenticationCookieName());
        if (StringUtils.isNotBlank(cookieValue)) {
            try {
                String decryptedValue = Application.getInstance(Crypto.class).decrypt(cookieValue, this.config.getAuthenticationCookieEncryptionKey());
                
                JwtConsumer jwtConsumer = new JwtConsumerBuilder()
                        .setRequireSubject()
                        .setVerificationKey(new HmacKey(this.config.getAuthenticationCookieSignKey().getBytes(StandardCharsets.UTF_8)))
                        .setJwsAlgorithmConstraints(new AlgorithmConstraints(ConstraintType.WHITELIST, AlgorithmIdentifiers.HMAC_SHA512))
                        .build();
                
                JwtClaims jwtClaims = jwtConsumer.processToClaims(decryptedValue);
                String expiresClaim = jwtClaims.getClaimValue(ClaimKey.EXPIRES.toString(), String.class);
                
                if (("-1").equals(expiresClaim)) {
                    authentication = Authentication.create()
                            .withSubject(jwtClaims.getSubject())
                            .twoFactorAuthentication(jwtClaims.getClaimValue(ClaimKey.TWO_FACTOR.toString(), Boolean.class));
                } else if (LocalDateTime.parse(jwtClaims.getClaimValue(ClaimKey.EXPIRES.toString(), String.class), DateUtils.formatter).isAfter(LocalDateTime.now())) {
                    authentication = Authentication.create()
                            .withExpires(LocalDateTime.parse(jwtClaims.getClaimValue(ClaimKey.EXPIRES.toString(), String.class), DateUtils.formatter))
                            .withSubject(jwtClaims.getSubject())
                            .twoFactorAuthentication(jwtClaims.getClaimValue(ClaimKey.TWO_FACTOR.toString(), Boolean.class));
                } else {
                    //Ignore this and use default authentication
                }
            } catch (MalformedClaimException | InvalidJwtException  e) {
                LOG.error("Failed to parse authentication cookie", e);
                authentication.invalidate();
            }
        }

        return authentication;
    }
853845
@Override
    public void process(Exchange exchange) throws Exception {
        log.debug(exchange.toString());

        if (pin instanceof GPIOPin) {

            GPIOAction messageAction = exchange.getIn().getHeader(DeviceIOConstants.CAMEL_DEVICE_IO_ACTION,
                    getEndpoint().getAction(), GPIOAction.class);

            if (messageAction != null) {
                switch (messageAction) {
                case HIGH:
                    setValue(true);
                    break;
                case LOW:
                    setValue(false);
                    break;
                case TOGGLE:
                    setValue(!pin.getValue());
                    break;
                case BLINK:
                    pool.submit(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                Thread.sleep(getEndpoint().getDelay());
                                pin.setValue(!pin.getValue());
                                Thread.sleep(getEndpoint().getDuration());
                                pin.setValue(!pin.getValue());
                            } catch (Exception e) {
                                log.error("Thread interruption into BLINK sequence", e);
                            }
                        }
                    });

                    break;
                default:
                    break;
                }
            } else {
                if (pin.getDirection() == GPIOPinConfig.DIR_OUTPUT_ONLY && exchange.getIn().getBody() != null) {
                    setValue(exchange.getIn().getBody(Boolean.class));
                } else if ((pin.getDirection() == GPIOPinConfig.DIR_OUTPUT_ONLY && exchange.getIn().getBody() == null)
                        || pin.getDirection() == GPIOPinConfig.DIR_INPUT_ONLY) {
                    exchange.getIn().setBody(pin.getValue(), Boolean.class);
                    exchange.getIn().setHeader(DeviceIOConstants.CAMEL_DEVICE_IO_PIN, pin.getDescriptor().getID());
                    exchange.getIn().setHeader(DeviceIOConstants.CAMEL_DEVICE_IO_NAME, pin.getDescriptor().getName());
                    exchange.getIn().setHeader(DeviceIOConstants.CAMEL_DEVICE_IO_TIMESTAMP, System.currentTimeMillis());

                }
            }
        }
    }
314242
void recoverExchange(String exchangeName, ResourceDeclaration exchangeDeclaration)
      throws Exception {
    try {
      log.info("Recovering exchange {} via {}", exchangeName, this);
      exchangeDeclaration.invoke(getRecoveryChannel());
    } catch (Exception e) {
      log.error("Failed to recover exchange {} via {}", exchangeName, this, e);
      if (throwOnRecoveryFailure() || Exceptions.isCausedByConnectionClosure(e))
        throw e;
    }
  }
354886
public Status validateResponse(final HttpServerExchange exchange, final SwaggerOperation swaggerOperation) {
        requireNonNull(exchange, "An exchange is required");
        requireNonNull(swaggerOperation, "A swagger operation is required");

        io.swagger.models.Response swaggerResponse = swaggerOperation.getOperation().getResponses().get(Integer.toString(exchange.getStatusCode()));
        if (swaggerResponse == null) {
            swaggerResponse = swaggerOperation.getOperation().getResponses().get("default"); // try the default response
        }

        if (swaggerResponse == null) {
            return new Status("ERR11015", exchange.getStatusCode(), swaggerOperation.getPathString().original());
        }

        if (swaggerResponse.getSchema() == null) {
            return null;
        }
        String body = exchange.getOutputStream().toString();

        if (body == null || body.length() == 0) {
            return new Status("ERR11016", swaggerOperation.getMethod(), swaggerOperation.getPathString().original());
        }
        return schemaValidator.validate(body, swaggerResponse.getSchema());
    }
7723
def get_exchange(self, vhost, name):
        
        vhost = quote(vhost, '')
        name = quote(name, '')
        path = Client.urls['exchange_by_name'] % (vhost, name)
        exch = self._call(path, 'GET')
        return exch
174917
public void handleDirectRequest(HttpServerExchange exchange) {
        Log.Info(this,"direct link path:"+exchange.getRelativePath());
        exchange.setResponseCode(200);
        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/html; charset=utf-8");
        exchange.getResponseSender().send( "Hello there, "+exchange.getRequestPath() );
    }
688487
public static Map<String, String> getRequestParameters(HttpServerExchange exchange) {
        Objects.requireNonNull(exchange, Required.HTTP_SERVER_EXCHANGE.toString());

        final Map<String, String> requestParamater = new HashMap<>();
        final Map<String, Deque<String>> queryParameters = exchange.getQueryParameters();
        queryParameters.putAll(exchange.getPathParameters());
        queryParameters.entrySet().forEach(entry -> requestParamater.put(entry.getKey(), entry.getValue().element()));

        return requestParamater;
    }