/**
  * Creates a {@link org.apache.camel.spi.RestConfiguration} instance based on the definition
  *
  * @param context the camel context
  * @return the configuration
  * @throws Exception is thrown if error creating the configuration
  */
 public RestConfiguration asRestConfiguration(CamelContext context) throws Exception {
   RestConfiguration answer = new RestConfiguration();
   if (component != null) {
     answer.setComponent(CamelContextHelper.parseText(context, component));
   }
   if (scheme != null) {
     answer.setScheme(CamelContextHelper.parseText(context, scheme));
   }
   if (host != null) {
     answer.setHost(CamelContextHelper.parseText(context, host));
   }
   if (port != null) {
     answer.setPort(CamelContextHelper.parseInteger(context, port));
   }
   if (bindingMode != null) {
     answer.setBindingMode(bindingMode.name());
   }
   if (!componentProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : componentProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setComponentProperties(props);
   }
   if (!endpointProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : endpointProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setEndpointProperties(props);
   }
   if (!consumerProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : consumerProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setConsumerProperties(props);
   }
   return answer;
 }
  /**
   * Determines if redelivery is enabled by checking if any of the redelivery policy settings may
   * allow redeliveries.
   *
   * @return <tt>true</tt> if redelivery is possible, <tt>false</tt> otherwise
   * @throws Exception can be thrown
   */
  private boolean determineIfRedeliveryIsEnabled() throws Exception {
    // determine if redeliver is enabled either on error handler
    if (getRedeliveryPolicy().getMaximumRedeliveries() != 0) {
      // must check for != 0 as (-1 means redeliver forever)
      return true;
    }
    if (retryWhilePolicy != null) {
      return true;
    }

    // or on the exception policies
    if (!exceptionPolicies.isEmpty()) {
      // walk them to see if any of them have a maximum redeliveries > 0 or retry until set
      for (OnExceptionDefinition def : exceptionPolicies.values()) {

        if (def.getRedeliveryPolicy() != null) {
          String ref = def.getRedeliveryPolicyRef();
          if (ref != null) {
            // lookup in registry if ref provided
            RedeliveryPolicy policy =
                CamelContextHelper.mandatoryLookup(camelContext, ref, RedeliveryPolicy.class);
            if (policy.getMaximumRedeliveries() != 0) {
              // must check for != 0 as (-1 means redeliver forever)
              return true;
            }
          } else {
            Integer max =
                CamelContextHelper.parseInteger(
                    camelContext, def.getRedeliveryPolicy().getMaximumRedeliveries());
            if (max != null && max != 0) {
              // must check for != 0 as (-1 means redeliver forever)
              return true;
            }
          }
        }

        if (def.getRetryWhilePolicy() != null || def.getRetryWhile() != null) {
          return true;
        }
      }
    }

    return false;
  }
 /**
  * Creates a {@link org.apache.camel.spi.RestConfiguration} instance based on the definition
  *
  * @param context the camel context
  * @return the configuration
  * @throws Exception is thrown if error creating the configuration
  */
 public RestConfiguration asRestConfiguration(CamelContext context) throws Exception {
   RestConfiguration answer = new RestConfiguration();
   if (component != null) {
     answer.setComponent(CamelContextHelper.parseText(context, component));
   }
   if (apiComponent != null) {
     answer.setApiComponent(CamelContextHelper.parseText(context, apiComponent));
   }
   if (scheme != null) {
     answer.setScheme(CamelContextHelper.parseText(context, scheme));
   }
   if (host != null) {
     answer.setHost(CamelContextHelper.parseText(context, host));
   }
   if (port != null) {
     answer.setPort(CamelContextHelper.parseInteger(context, port));
   }
   if (apiContextPath != null) {
     answer.setApiContextPath(CamelContextHelper.parseText(context, apiContextPath));
   }
   if (apiContextRouteId != null) {
     answer.setApiContextRouteId(CamelContextHelper.parseText(context, apiContextRouteId));
   }
   if (apiContextIdPattern != null) {
     // special to allow #name# to refer to itself
     if ("#name#".equals(apiComponent)) {
       answer.setApiContextIdPattern(context.getName());
     } else {
       answer.setApiContextIdPattern(CamelContextHelper.parseText(context, apiContextIdPattern));
     }
   }
   if (apiContextListing != null) {
     answer.setApiContextListing(apiContextListing);
   }
   if (contextPath != null) {
     answer.setContextPath(CamelContextHelper.parseText(context, contextPath));
   }
   if (hostNameResolver != null) {
     answer.setRestHostNameResolver(hostNameResolver.name());
   }
   if (bindingMode != null) {
     answer.setBindingMode(bindingMode.name());
   }
   if (skipBindingOnErrorCode != null) {
     answer.setSkipBindingOnErrorCode(skipBindingOnErrorCode);
   }
   if (enableCORS != null) {
     answer.setEnableCORS(enableCORS);
   }
   if (jsonDataFormat != null) {
     answer.setJsonDataFormat(jsonDataFormat);
   }
   if (xmlDataFormat != null) {
     answer.setXmlDataFormat(xmlDataFormat);
   }
   if (!componentProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : componentProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setComponentProperties(props);
   }
   if (!endpointProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : endpointProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setEndpointProperties(props);
   }
   if (!consumerProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : consumerProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setConsumerProperties(props);
   }
   if (!dataFormatProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : dataFormatProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setDataFormatProperties(props);
   }
   if (!apiProperties.isEmpty()) {
     Map<String, Object> props = new HashMap<String, Object>();
     for (RestPropertyDefinition prop : apiProperties) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setApiProperties(props);
   }
   if (!corsHeaders.isEmpty()) {
     Map<String, String> props = new HashMap<String, String>();
     for (RestPropertyDefinition prop : corsHeaders) {
       String key = prop.getKey();
       String value = CamelContextHelper.parseText(context, prop.getValue());
       props.put(key, value);
     }
     answer.setCorsHeaders(props);
   }
   return answer;
 }