org.apache.camel.spi.RestConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of camel-core Show documentation
Show all versions of camel-core Show documentation
The Core Camel Java DSL based router
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.spi;
import java.util.Map;
/**
* Configuration use by {@link org.apache.camel.spi.RestConsumerFactory} and {@link org.apache.camel.spi.RestApiConsumerFactory}
* for Camel components to support the Camel {@link org.apache.camel.model.rest.RestDefinition rest} DSL.
*/
public class RestConfiguration {
public static final String CORS_ACCESS_CONTROL_ALLOW_ORIGIN = "*";
public static final String CORS_ACCESS_CONTROL_ALLOW_METHODS = "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH";
public static final String CORS_ACCESS_CONTROL_MAX_AGE = "3600";
public static final String CORS_ACCESS_CONTROL_ALLOW_HEADERS = "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers";
public enum RestBindingMode {
auto, off, json, xml, json_xml
}
public enum RestHostNameResolver {
localIp, localHostName
}
private String component;
private String apiComponent;
private String scheme;
private String host;
private int port;
private String contextPath;
private String apiContextPath;
private String apiContextRouteId;
private String apiContextIdPattern;
private boolean apiContextListing;
private RestHostNameResolver restHostNameResolver = RestHostNameResolver.localHostName;
private RestBindingMode bindingMode = RestBindingMode.off;
private boolean skipBindingOnErrorCode = true;
private boolean enableCORS;
private String jsonDataFormat;
private String xmlDataFormat;
private Map componentProperties;
private Map endpointProperties;
private Map consumerProperties;
private Map dataFormatProperties;
private Map apiProperties;
private Map corsHeaders;
/**
* Gets the name of the Camel component to use as the REST consumer
*
* @return the component name, or null to let Camel search the {@link Registry} to find suitable implementation
*/
public String getComponent() {
return component;
}
/**
* Sets the name of the Camel component to use as the REST consumer
*
* @param componentName the name of the component (such as restlet, spark-rest, etc.)
*/
public void setComponent(String componentName) {
this.component = componentName;
}
/**
* Gets the name of the Camel component to use as the REST API (such as swagger)
*
* @return the component name, or null to let Camel use the default name swagger
*/
public String getApiComponent() {
return apiComponent;
}
/**
* Sets the name of the Camel component to use as the REST API (such as swagger)
*
* @param apiComponent the name of the component (such as swagger)
*/
public void setApiComponent(String apiComponent) {
this.apiComponent = apiComponent;
}
/**
* Gets the hostname to use by the REST consumer
*
* @return the hostname, or null to use default hostname
*/
public String getHost() {
return host;
}
/**
* Sets the hostname to use by the REST consumer
*
* @param host the hostname
*/
public void setHost(String host) {
this.host = host;
}
/**
* Gets the scheme to use by the REST consumer
*
* @return the scheme, or null to use default scheme
*/
public String getScheme() {
return scheme;
}
/**
* Sets the scheme to use by the REST consumer
*
* @param scheme the scheme
*/
public void setScheme(String scheme) {
this.scheme = scheme;
}
/**
* Gets the port to use by the REST consumer
*
* @return the port, or 0 or -1 to use default port
*/
public int getPort() {
return port;
}
/**
* Sets the port to use by the REST consumer
*
* @param port the port number
*/
public void setPort(int port) {
this.port = port;
}
/**
* Gets the configured context-path
*
* @return the context path, or null if none configured.
*/
public String getContextPath() {
return contextPath;
}
/**
* Sets a leading context-path the REST services will be using.
*
* This can be used when using components such as camel-servlet where the deployed web application
* is deployed using a context-path. Or for components such as camel-jetty or camel-netty4-http
* that includes a HTTP server.
*
* @param contextPath the context path
*/
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public String getApiContextPath() {
return apiContextPath;
}
/**
* Sets a leading API context-path the REST API services will be using.
*
* This can be used when using components such as camel-servlet where the deployed web application
* is deployed using a context-path.
*
* @param contextPath the API context path
*/
public void setApiContextPath(String contextPath) {
this.apiContextPath = contextPath;
}
public String getApiContextRouteId() {
return apiContextRouteId;
}
/**
* Sets the route id to use for the route that services the REST API.
*
* The route will by default use an auto assigned route id.
*
* @param apiContextRouteId the route id
*/
public void setApiContextRouteId(String apiContextRouteId) {
this.apiContextRouteId = apiContextRouteId;
}
public String getApiContextIdPattern() {
return apiContextIdPattern;
}
/**
* Optional CamelContext id pattern to only allow Rest APIs from rest services within CamelContext's which name matches the pattern.
*
* The pattern #name# refers to the CamelContext name, to match on the current CamelContext only.
* For any other value, the pattern uses the rules from {@link org.apache.camel.util.EndpointHelper#matchPattern(String, String)}
*
* @param apiContextIdPattern the pattern
*/
public void setApiContextIdPattern(String apiContextIdPattern) {
this.apiContextIdPattern = apiContextIdPattern;
}
public boolean isApiContextListing() {
return apiContextListing;
}
/**
* Sets whether listing of all available CamelContext's with REST services in the JVM is enabled. If enabled it allows to discover
* these contexts, if false then only the current CamelContext is in use.
*/
public void setApiContextListing(boolean apiContextListing) {
this.apiContextListing = apiContextListing;
}
/**
* Gets the resolver to use for resolving hostname
*
* @return the resolver
*/
public RestHostNameResolver getRestHostNameResolver() {
return restHostNameResolver;
}
/**
* Sets the resolver to use for resolving hostname
*
* @param restHostNameResolver the resolver
*/
public void setRestHostNameResolver(RestHostNameResolver restHostNameResolver) {
this.restHostNameResolver = restHostNameResolver;
}
/**
* Sets the resolver to use for resolving hostname
*
* @param restHostNameResolver the resolver
*/
public void setRestHostNameResolver(String restHostNameResolver) {
this.restHostNameResolver = RestHostNameResolver.valueOf(restHostNameResolver);
}
/**
* Gets the binding mode used by the REST consumer
*
* @return the binding mode
*/
public RestBindingMode getBindingMode() {
return bindingMode;
}
/**
* Sets the binding mode to be used by the REST consumer
*
* @param bindingMode the binding mode
*/
public void setBindingMode(RestBindingMode bindingMode) {
this.bindingMode = bindingMode;
}
/**
* Sets the binding mode to be used by the REST consumer
*
* @param bindingMode the binding mode
*/
public void setBindingMode(String bindingMode) {
this.bindingMode = RestBindingMode.valueOf(bindingMode);
}
/**
* Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.
*
* This option is default true.
*
* @return whether to skip binding on error code
*/
public boolean isSkipBindingOnErrorCode() {
return skipBindingOnErrorCode;
}
/**
* Whether to skip binding output if there is a custom HTTP error code, and instead use the response body as-is.
*
* This option is default true.
*
* @param skipBindingOnErrorCode whether to skip binding on error code
*/
public void setSkipBindingOnErrorCode(boolean skipBindingOnErrorCode) {
this.skipBindingOnErrorCode = skipBindingOnErrorCode;
}
/**
* To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.
*
* This option is default false
*
* @return whether CORS is enabled or not
*/
public boolean isEnableCORS() {
return enableCORS;
}
/**
* To specify whether to enable CORS which means Camel will automatic include CORS in the HTTP headers in the response.
*
* This option is default false
*
* @param enableCORS true to enable CORS
*/
public void setEnableCORS(boolean enableCORS) {
this.enableCORS = enableCORS;
}
/**
* Gets the name of the json data format.
*
* Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.
*
* @return the name, or null to use default
*/
public String getJsonDataFormat() {
return jsonDataFormat;
}
/**
* Sets a custom json data format to be used
*
* Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.
*
* @param name name of the data format
*/
public void setJsonDataFormat(String name) {
this.jsonDataFormat = name;
}
/**
* Gets the name of the xml data format.
*
* Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.
*
* @return the name, or null to use default
*/
public String getXmlDataFormat() {
return xmlDataFormat;
}
/**
* Sets a custom xml data format to be used.
*
* Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance.
*
* @param name name of the data format
*/
public void setXmlDataFormat(String name) {
this.xmlDataFormat = name;
}
/**
* Gets additional options on component level
*
* @return additional options
*/
public Map getComponentProperties() {
return componentProperties;
}
/**
* Sets additional options on component level
*
* @param componentProperties the options
*/
public void setComponentProperties(Map componentProperties) {
this.componentProperties = componentProperties;
}
/**
* Gets additional options on endpoint level
*
* @return additional options
*/
public Map getEndpointProperties() {
return endpointProperties;
}
/**
* Sets additional options on endpoint level
*
* @param endpointProperties the options
*/
public void setEndpointProperties(Map endpointProperties) {
this.endpointProperties = endpointProperties;
}
/**
* Gets additional options on consumer level
*
* @return additional options
*/
public Map getConsumerProperties() {
return consumerProperties;
}
/**
* Sets additional options on consumer level
*
* @param consumerProperties the options
*/
public void setConsumerProperties(Map consumerProperties) {
this.consumerProperties = consumerProperties;
}
/**
* Gets additional options on data format level
*
* @return additional options
*/
public Map getDataFormatProperties() {
return dataFormatProperties;
}
/**
* Sets additional options on data format level
*
* @param dataFormatProperties the options
*/
public void setDataFormatProperties(Map dataFormatProperties) {
this.dataFormatProperties = dataFormatProperties;
}
public Map getApiProperties() {
return apiProperties;
}
/**
* Sets additional options on api level
*
* @param apiProperties the options
*/
public void setApiProperties(Map apiProperties) {
this.apiProperties = apiProperties;
}
/**
* Gets the CORS headers to use if CORS has been enabled.
*
* @return the CORS headers
*/
public Map getCorsHeaders() {
return corsHeaders;
}
/**
* Sets the CORS headers to use if CORS has been enabled.
*
* @param corsHeaders the CORS headers
*/
public void setCorsHeaders(Map corsHeaders) {
this.corsHeaders = corsHeaders;
}
}