コード例 #1
0
  protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
      throws Exception {
    // split remaining path to get API name and method
    final String[] pathElements = remaining.split("/");
    String apiNameStr;
    String methodName;
    switch (pathElements.length) {
      case 1:
        apiNameStr = "";
        methodName = pathElements[0];
        break;
      case 2:
        apiNameStr = pathElements[0];
        methodName = pathElements[1];
        break;
      default:
        throw new CamelException(
            "Invalid URI path ["
                + remaining
                + "], must be of the format "
                + collection.getApiNames()
                + "/<operation-name>");
    }

    try {
      // get API enum from apiName string
      final E apiName = getApiName(apiNameStr);

      final T endpointConfiguration = createEndpointConfiguration(apiName);
      final Endpoint endpoint = createEndpoint(uri, methodName, apiName, endpointConfiguration);

      // set endpoint property inBody
      setProperties(endpoint, parameters);

      // configure endpoint properties and initialize state
      endpoint.configureProperties(parameters);

      return endpoint;
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof IllegalArgumentException) {
        throw new CamelException(
            "Invalid URI path prefix ["
                + remaining
                + "], must be one of "
                + collection.getApiNames());
      }
      throw e;
    }
  }