Search in sources :

Example 36 with RestDefinition

use of org.apache.camel.model.rest.RestDefinition in project camel by apache.

the class RouteBuilder method rest.

/**
     * Creates a new REST service
     *
     * @return the builder
     */
public RestDefinition rest() {
    getRestCollection().setCamelContext(getContext());
    RestDefinition answer = getRestCollection().rest();
    configureRest(answer);
    return answer;
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition)

Example 37 with RestDefinition

use of org.apache.camel.model.rest.RestDefinition in project camel by apache.

the class AbstractCamelContextFactoryBean method initRestRefs.

protected void initRestRefs() throws Exception {
    // add rest refs to existing rests
    if (getRestRefs() != null) {
        for (RestContextRefDefinition ref : getRestRefs()) {
            List<RestDefinition> defs = ref.lookupRests(getContext());
            for (RestDefinition def : defs) {
                LOG.debug("Adding rest from {} -> {}", ref, def);
                // add in top as they are most likely to be common/shared
                // which you may want to start first
                getRests().add(0, def);
            }
        }
    }
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) RestContextRefDefinition(org.apache.camel.model.RestContextRefDefinition)

Example 38 with RestDefinition

use of org.apache.camel.model.rest.RestDefinition in project camel by apache.

the class AbstractCamelContextFactoryBean method setupRoutes.

/**
     * Setup all the routes which must be done prior starting {@link CamelContext}.
     */
protected void setupRoutes() throws Exception {
    if (routesSetupDone.compareAndSet(false, true)) {
        LOG.debug("Setting up routes");
        // mark that we are setting up routes
        getContext().setupRoutes(false);
        // must init route refs before we prepare the routes below
        initRouteRefs();
        // must init rest refs before we add the rests
        initRestRefs();
        // and add the rests
        getContext().addRestDefinitions(getRests());
        // convert rests into routes so we reuse routes for runtime
        for (RestDefinition rest : getRests()) {
            List<RouteDefinition> routes = rest.asRouteDefinition(getContext());
            for (RouteDefinition route : routes) {
                getRoutes().add(route);
            }
        }
        // convert rests api-doc into routes so they are routes for runtime
        for (RestConfiguration config : getContext().getRestConfigurations()) {
            if (config.getApiContextPath() != null) {
                // avoid adding rest-api multiple times, in case multiple RouteBuilder classes is added
                // to the CamelContext, as we only want to setup rest-api once
                // so we check all existing routes if they have rest-api route already added
                boolean hasRestApi = false;
                for (RouteDefinition route : getContext().getRouteDefinitions()) {
                    FromDefinition from = route.getInputs().get(0);
                    if (from.getUri() != null && from.getUri().startsWith("rest-api:")) {
                        hasRestApi = true;
                    }
                }
                if (!hasRestApi) {
                    RouteDefinition route = RestDefinition.asRouteApiDefinition(getContext(), config);
                    LOG.debug("Adding routeId: {} as rest-api route", route.getId());
                    getRoutes().add(route);
                }
            }
        }
        // do special preparation for some concepts such as interceptors and policies
        // this is needed as JAXB does not build exactly the same model definition as Spring DSL would do
        // using route builders. So we have here a little custom code to fix the JAXB gaps
        prepareRoutes();
        // and add the routes
        getContext().addRouteDefinitions(getRoutes());
        LOG.debug("Found JAXB created routes: {}", getRoutes());
        findRouteBuilders();
        installRoutes();
        // and we are now finished setting up the routes
        getContext().setupRoutes(true);
    }
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) FromDefinition(org.apache.camel.model.FromDefinition) InterceptFromDefinition(org.apache.camel.model.InterceptFromDefinition) RouteDefinition(org.apache.camel.model.RouteDefinition) RestConfiguration(org.apache.camel.spi.RestConfiguration)

Aggregations

RestDefinition (org.apache.camel.model.rest.RestDefinition)38 ToDefinition (org.apache.camel.model.ToDefinition)10 Test (org.junit.Test)10 RestsDefinition (org.apache.camel.model.rest.RestsDefinition)5 RouteDefinition (org.apache.camel.model.RouteDefinition)4 Swagger (io.swagger.models.Swagger)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 FromDefinition (org.apache.camel.model.FromDefinition)2 InterceptFromDefinition (org.apache.camel.model.InterceptFromDefinition)2 GetVerbDefinition (org.apache.camel.model.rest.GetVerbDefinition)2 RestContainer (org.apache.camel.model.rest.RestContainer)2 VerbDefinition (org.apache.camel.model.rest.VerbDefinition)2 RestConfiguration (org.apache.camel.spi.RestConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1