org.apache.camel.model.rest.RestDefinition类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(19.4k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.apache.camel.model.rest.RestDefinition类的一些代码示例,展示了RestDefinition类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestDefinition类的具体详情如下:
包路径:org.apache.camel.model.rest.RestDefinition
类名称:RestDefinition

RestDefinition介绍

暂无

代码示例

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {

    // use jetty for rest service
    restConfiguration("jetty").port("{{port}}").contextPath("api")
        // turn on json binding
        .bindingMode(RestBindingMode.json)
        // turn off binding error on empty beans
        .dataFormatProperty("disableFeatures", "FAIL_ON_EMPTY_BEANS")
        // enable swagger api documentation
        .apiContextPath("api-doc")
        .enableCORS(true);

    // define the rest service
    rest("/cart").consumes("application/json").produces("application/json")
      // get returns List<CartDto>
      .get().outType(CartDto[].class).description("Returns the items currently in the shopping cart")
        .to("bean:cart?method=getItems")
      // get accepts CartDto
      .post().type(CartDto.class).description("Adds the item to the shopping cart")
        .to("bean:cart?method=addItem")
      .delete().description("Removes the item from the shopping cart")
        .param().name("itemId").description("Id of item to remove").endParam()
        .to("bean:cart?method=removeItem");
  }
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
public void configure() throws Exception {
  // use the restlet component on port 8080 as the REST server
  // no need for binding to json/jaxb as the rest services are using plain text
  restConfiguration().component("restlet").port(8080);
  rest("/rest").consumes("application/text").produces("application/text")
    // ping rest service
    .get("ping")
      .route().routeId("ping")
      .transform(constant("PONG\n"))
    .endRest()
    // controlbus to start/stop the route
    .get("route/{action}")
      // use dynamic-to so the action is provided from the url
      .toD("controlbus:route?routeId=ping&action=${header.action}");
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {
    // see the application.properties file for setup of the rest configuration

    // rest services under the orders context-path
    rest("/orders")
      // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .get("{id}").outType(Order.class)
        .to("bean:orderService?method=getOrder(${header.id})")
        // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .post().type(Order.class)
        .to("bean:orderService?method=createOrder")
        // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .put().type(Order.class)
        .to("bean:orderService?method=updateOrder")
      .delete("{id}")
        .to("bean:orderService?method=cancelOrder(${header.id})");
  }
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {

    // configure rest-dsl
    restConfiguration()
      // to use spark-rest component and run on port 8080
      .component("spark-rest").port(8080);

    // rest services under the orders context-path
    rest("/orders")
      .get("{id}")
        .to("bean:orderService?method=getOrder(${header.id})")
      .post()
        .to("bean:orderService?method=createOrder")
      .put()
        .to("bean:orderService?method=updateOrder")
      .delete("{id}")
        .to("bean:orderService?method=cancelOrder(${header.id})");
  }
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {

    restConfiguration()
      // turn on json binding in rest-dsl
      .bindingMode(RestBindingMode.json);

    // define the rest service
    rest("/ratings/{ids}").produces("application/json")
      .get().to("bean:ratingService");
  }
}

代码示例来源:origin: camelinaction/camelinaction2

rest("/orders").description("Order services")
  .get("/ping").apiDocs(false)
    .to("direct:ping")
  .get("{id}").outType(Order.class)
    .description("Service to get details of an existing order")
    .param().name("id").description("The order id").endParam()
    .responseMessage().code(200).message("The order with the given id").endResponseMessage()
    .responseMessage().code(404).message("Order not found").endResponseMessage()
    .responseMessage().code(500).message("Server error").endResponseMessage()
    .to("bean:orderService?method=getOrder(${header.id})")
  .post().type(Order.class).outType(String.class)
    .description("Service to submit a new order")
    .responseMessage()
      .code(200).message("The created order id")
    .endResponseMessage()
    .responseMessage().code(400).message("Invalid input data").endResponseMessage()
    .responseMessage().code(500).message("Server error").endResponseMessage()
    .to("bean:orderService?method=createOrder")
  .put().type(Order.class)
    .description("Service to update an existing order")
    .responseMessage().code(400).message("Invalid input data").endResponseMessage()
    .responseMessage().code(500).message("Server error").endResponseMessage()
    .to("bean:orderService?method=updateOrder")
  .delete("{id}")

代码示例来源:origin: org.openksavi.sponge/sponge-rest-api

RestDefinition restDefinition = rest(RestApiConstants.BASE_URL).description("Sponge REST API")
  .consumes(RestApiConstants.APPLICATION_JSON_VALUE).produces(RestApiConstants.APPLICATION_JSON_VALUE)
  .post("/version").description("Get the Sponge version").type(RestGetVersionRequest.class).outType(RestGetVersionResponse.class)
    .param().name("body").type(body).description("Get Sponge version request").endParam()
    .responseMessage().code(200).message("The Sponge version response").endResponseMessage()
    .route().id("version")
      .setBody(exchange -> apiService.getVersion(exchange.getIn().getBody(RestGetVersionRequest.class), exchange))
    .endRest()
  .post("/login").description("Login").type(RestLoginRequest.class).outType(RestLoginResponse.class)
    .param().name("body").type(body).description("Login request").endParam()
    .responseMessage().code(200).message("The login response").endResponseMessage()
    .route().id("login")
      .setBody(exchange -> apiService.login(exchange.getIn().getBody(RestLoginRequest.class), exchange))
    .endRest()
  .post("/logout").description("Logout").type(RestLogoutRequest.class).outType(RestLogoutResponse.class)
    .param().name("body").type(body).description("Logout request").endParam()
    .responseMessage().code(200).message("The logout response").endResponseMessage()
    .route().id("logout")
      .setBody(exchange -> apiService.logout(exchange.getIn().getBody(RestLogoutRequest.class), exchange))
    .endRest()
  .post("/knowledgeBases").description("Get knowledge bases").type(RestGetKnowledgeBasesRequest.class)
      .outType(RestGetKnowledgeBasesResponse.class)
    .param().name("body").type(body).description("Get knowledge bases request").endParam()
    .responseMessage().code(200).message("The get knowledge bases response").endResponseMessage()
    .route().id("knowledgeBases")
      .setBody(exchange -> apiService.getKnowledgeBases(exchange.getIn().getBody(RestGetKnowledgeBasesRequest.class), exchange))
    .endRest()
  .post("/actions").description("Get actions").type(RestGetActionsRequest.class).outType(RestGetActionsResponse.class)
    .param().name("body").type(body).description("Get actions request").endParam()

代码示例来源:origin: RedHatWorkshops/dayinthelife-integration

rest("/location").description("Location information")
  .produces("application/json")
  .get("/contact/{id}").description("Location Contact Info")
    .responseMessage().code(200).message("Data successfully returned").endResponseMessage()
    .to("direct:getalllocationphone")

代码示例来源:origin: RedHatWorkshops/dayinthelife-integration

rest("/locations").description("Location information")
  .produces("application/json")
  .get("/").description("Retrieve all locations data")
    .to("direct:getlocationAll")
  .get("/{id}")
    .to("direct:getlocation")
  .get("/phone/{id}")
    .to("direct:phone")
  .post("/add")
    .to("direct:addlocation")

代码示例来源:origin: org.openksavi.sponge/sponge-rest-api-server

protected <I extends SpongeRequest, O extends SpongeResponse> void createOperation(RestDefinition restDefinition, String operation,
    String operationDescription, Class<I> requestClass, String requestDescription, Class<O> responseClass,
    String responseDescription, BiFunction<I, Exchange, O> operationHandler) {
  restDefinition.post(operation).description(operationDescription).type(requestClass).outType(responseClass).param().name("body")
      .type(body).description(requestDescription).endParam().responseMessage().code(200).message(responseDescription)
      .endResponseMessage().route().id("sponge-" + operation).process(exchange -> {
        String requestBody = exchange.getIn().getBody(String.class);
        if (logger.isDebugEnabled()) {
          logger.debug("REST API {} request: {}", operation, RestApiUtils.obfuscatePassword(requestBody));
        }
        try {
          setupResponse(operation, exchange,
              operationHandler.apply(getObjectMapper().readValue(requestBody, requestClass), exchange));
        } catch (Throwable processingException) {
          logger.info("REST API error", processingException);
          try {
            setupResponse(operation, exchange, apiService.createGenericErrorResponse(processingException, exchange));
          } catch (Throwable e) {
            logger.error("REST API send error response failure", e);
            throw e;
          }
        }
      }).endRest();
}

代码示例来源:origin: redhat-developer-demos/istio-tutorial

.bindingMode(RestBindingMode.auto);
rest("/").get().produces("text/plain")
    .route().routeId("root")
.endRest();
rest("/misbehave").get().produces("text/plain")
    .route().routeId("misbehave")
    .process(exchange -> {
      this.misbehave = true;
rest("/behave").get().produces("text/plain")
    .route().routeId("behave")
    .process(exchange -> {
      this.misbehave = false;

代码示例来源:origin: RedHatWorkshops/dayinthelife-integration

rest("/threescale").description("Location information")
  .produces("application/json")
  .post("/automate/{apiToken}/{userid}/{openshiftappurl}").description("Automatically setup your 3scale APIs")
    .responseMessage().code(200).message("Your API is secured!").endResponseMessage()
    .to("direct:threescalesetup")

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {
    // configure rest to use netty4-http component as the HTTP server component
    // enable json binding mode so we can leverage camel-jackson to bind json to/from pojos
    restConfiguration().component("netty4-http").bindingMode(RestBindingMode.json)
        // expose the service as localhost:8080/service
        .host("localhost").port(8080).contextPath("service");

    // include a token id header, which we insert before the consumer completes
    // (and therefore before the consumer writes the response to the caller)
    onCompletion().modeBeforeConsumer()
        .setHeader("Token").method("tokenService");

    // use rest-dsl to define the rest service to lookup orders
    rest()
      .get("/order/{id}")
        .to("bean:orderService?method=getOrder");

  }
}

代码示例来源:origin: redhat-developer-demos/istio-tutorial

@Override
public void configure() throws Exception {
  restConfiguration()
      .component("servlet")
      .enableCORS(true)
      .contextPath("/")
      .bindingMode(RestBindingMode.auto);
  rest("/").get().consumes(MediaType.TEXT_PLAIN_VALUE)
      .route().routeId("root")
      .pipeline()
        .bean("CustomerCamelRoute", "addTracer")
        .to("http4:preference:8080/?httpClient.connectTimeout=1000&bridgeEndpoint=true&copyHeaders=true&connectionClose=true")
      .end()
      .convertBodyTo(String.class)
      .onException(HttpOperationFailedException.class)
        .handled(true)
        .process(this::handleHttpFailure)
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503))
      .end()
      .onException(Exception.class)
        .log(exceptionMessage().toString())
        .handled(true)
        .transform(simpleF(RESPONSE_STRING_FORMAT, exceptionMessage()))
        .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(503))
      .end()
      .transform(simpleF(RESPONSE_STRING_FORMAT, "${body}"))
  .endRest();
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {

    // configure rest-dsl
    restConfiguration()
      // to use spark-rest component and run on port 9090
      .component("spark-rest").port(9090)
      // enable api-docs
      .apiContextPath("api-doc")
      // enable CORS on rest services so they can be called from swagger UI
      .enableCORS(true)
      // enable CORS in the api-doc as well so the swagger UI can view it
      .apiProperty("cors", "true");

    // pong rest service
    rest("/ping").get().route().transform().constant("{ \"reply\": \"pong\" }");

  }
}

代码示例来源:origin: com.github.zed-platform/zed-camel

public void exposeAnnotatedBeans() {
  for (Map.Entry<String, Object> bean : findBeansWithRestOperations(routeBuilder.getContext().getRegistry()).entrySet()) {
    for (Method method : findRestOperations(bean.getValue().getClass())) {
      String uri = "/" + bean.getKey() + "/" + method.getName();
      boolean isGet = true;
      int parametersCount = method.getParameterCount();
      if (parametersCount > 0) {
        Class<?> lastParameterType = method.getParameterTypes()[parametersCount - 1];
        if (lastParameterType != String.class &&
            lastParameterType != Character.class && lastParameterType != char.class &&
            lastParameterType != Integer.class && lastParameterType != int.class &&
            lastParameterType != Long.class && lastParameterType != long.class &&
            lastParameterType != Float.class && lastParameterType != float.class &&
            lastParameterType != Double.class && lastParameterType != double.class) {
          isGet = false;
          parametersCount--;
        }
      }
      for (int i = 0; i < parametersCount; i++) {
        uri += "/{p" + i + "}";
      }
      routeBuilder.rest(uri).verb(isGet ? "GET" : "POST").route().process(restParametersBindingProcessor()).
          to("bean:" + bean.getKey() + "?method=" + method.getName() + "&multiParameterArray=true").
          choice().when(routeBuilder.header("CAMEL_REST_VOID_OPERATION").isNotNull()).setBody().constant("").endChoice();
    }
  }
}

代码示例来源:origin: org.openksavi.sponge/sponge-rest-api-server

protected void createRestDefinition() {
    RestDefinition restDefinition = rest(getSettings().getPath()).description("Sponge REST API");

    createOperation(restDefinition, RestApiConstants.OPERATION_VERSION, "Get the Sponge version", GetVersionRequest.class,
        "Get Sponge version request", GetVersionResponse.class, "The Sponge version response",
        (request, exchange) -> apiService.getVersion(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_LOGIN, "Login", LoginRequest.class, "Login request", LoginResponse.class,
        "The login response", (request, exchange) -> apiService.login(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_LOGOUT, "Logout", LogoutRequest.class, "Logout request",
        LogoutResponse.class, "The logout response", (request, exchange) -> apiService.logout(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_KNOWLEDGE_BASES, "Get knowledge bases", GetKnowledgeBasesRequest.class,
        "Get knowledge bases request", GetKnowledgeBasesResponse.class, "The get knowledge bases response",
        (request, exchange) -> apiService.getKnowledgeBases(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_ACTIONS, "Get actions", GetActionsRequest.class, "Get actions request",
        GetActionsResponse.class, "The get actions response", (request, exchange) -> apiService.getActions(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_CALL, "Call an action", ActionCallRequest.class, "Call action request",
        ActionCallResponse.class, "The action call response", (request, exchange) -> apiService.call(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_SEND, "Send a new event", SendEventRequest.class, "Send event request",
        SendEventResponse.class, "The send event response", (request, exchange) -> apiService.send(request, exchange));
    createOperation(restDefinition, RestApiConstants.OPERATION_ACTION_ARGS, "Provide action arguments",
        ProvideActionArgsRequest.class, "The provide action arguments request", ProvideActionArgsResponse.class,
        "The provide action arguments response", (request, exchange) -> apiService.provideActionArgs(request, exchange));

    if (getSettings().isPublishReload()) {
      createOperation(restDefinition, RestApiConstants.OPERATION_RELOAD, "Reload knowledge bases", ReloadRequest.class,
          "Reload knowledge bases request", ReloadResponse.class, "The reload response",
          (request, exchange) -> apiService.reload(request, exchange));
    }
  }
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {

    // configure rest-dsl
    restConfiguration()
      // to use spark-rest component and run on port 8080
      .component("spark-rest").port(8080)
      // and enable json binding mode
      .bindingMode(RestBindingMode.json)
      // lets enable pretty printing json responses
      .dataFormatProperty("prettyPrint", "true");

    // rest services under the orders context-path
    rest("/orders")
      // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .get("{id}").outType(Order.class)
        .to("bean:orderService?method=getOrder(${header.id})")
        // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .post().type(Order.class)
        .to("bean:orderService?method=createOrder")
        // need to specify the POJO types the binding is using (otherwise json binding defaults to Map based)
      .put().type(Order.class)
        .to("bean:orderService?method=updateOrder")
      .delete("{id}")
        .to("bean:orderService?method=cancelOrder(${header.id})");
  }
}

代码示例来源:origin: camelinaction/camelinaction2

@Override
  public void configure() throws Exception {
    // configure rest-dsl
    restConfiguration()
      // to use jetty component and run on port 8080
      .component("jetty").port(8080)
      // use a smaller thread pool in jetty as we do not have so high demand yet
      .componentProperty("minThreads", "1")
      .componentProperty("maxThreads", "16")
      // to setup jetty to use the security handler
      .endpointProperty("handlers", "#securityHandler");

    // rest services under the orders context-path
    rest("/orders")
      .get("{id}")
        .to("bean:orderService?method=getOrder(${header.id})")
      .post()
        .to("bean:orderService?method=createOrder")
      .put()
        .to("bean:orderService?method=updateOrder")
      .delete("{id}")
        .to("bean:orderService?method=cancelOrder(${header.id})");
  }
}

代码示例来源:origin: RedHatWorkshops/dayinthelife-integration

rest("/locations").description("Location information")
  .produces("application/json")
  .get("/").description("Retrieve all locations data")
    .responseMessage().code(200).message("Data successfully returned").endResponseMessage()
    .to("direct:getalllocations")
  .get("/{id}")
    .responseMessage().code(200).message("Data successfully returned").endResponseMessage()
    .to("direct:getlocation")

相关文章